function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sukhdeep SinghSukhdeep Singh 

Unable to show error in VF page

I useing below code for controller & VF. But error does`t display on VF.

Controller:-

public PageReference Saveod(){  
        for(Opportunity_Development__c od:odList)   {
             if(od.Account_Plan__c == null)
            od.Account_Plan__c=ap.id;
        }
        try
        {
            pagereference p = apexpages.Currentpage();
            upsert odList;
        }
        catch (Exception e)
        {
            System.debug('AccountPlanningExtensionSaveod() Exception ===> '+e);
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please use Save button at the top of the page to save header information.'));
//          ApexPages.Message msg = new ApexPages.Message(ApexPages.Severity.ERROR, 'Please use Save button at the top of the page to save header information.');
//            ApexPages.addMessage(msg);
//            return p;
        }




VF:-


<apex:page standardController="Account_Plan__c" extensions="AccountPlanningExtension" standardStylesheets="true">
<apex:pageMessages />
 
Best Answer chosen by Sukhdeep Singh
AshlekhAshlekh
Hi,

You have to rerder the parent section of Page message so it will show you the message.
 
<apex:page standardController="Account_Plan__c" extensions="AccountPlanningExtension" standardStylesheets="true">
<apex:outPutPanel id="outerpanel">
   <apex:pageMessages />
</apex:outPutPanel>


 
public PageReference Saveod(){  
        pagereference p = apexpages.Currentpage();
        for(Opportunity_Development__c od:odList)   {
             if(od.Account_Plan__c == null)
            od.Account_Plan__c=ap.id;
        }
        try
        {
            upsert odList;
        }
        catch (Exception e)
        {
            System.debug('AccountPlanningExtensionSaveod() Exception ===> '+e);
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please use Save button at the top of the page to save header information.'));
        }
	return null;
}

 

All Answers

BalajiRanganathanBalajiRanganathan
try to return null if exception occurs.
AshlekhAshlekh
Hi,

You have to rerder the parent section of Page message so it will show you the message.
 
<apex:page standardController="Account_Plan__c" extensions="AccountPlanningExtension" standardStylesheets="true">
<apex:outPutPanel id="outerpanel">
   <apex:pageMessages />
</apex:outPutPanel>


 
public PageReference Saveod(){  
        pagereference p = apexpages.Currentpage();
        for(Opportunity_Development__c od:odList)   {
             if(od.Account_Plan__c == null)
            od.Account_Plan__c=ap.id;
        }
        try
        {
            upsert odList;
        }
        catch (Exception e)
        {
            System.debug('AccountPlanningExtensionSaveod() Exception ===> '+e);
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Please use Save button at the top of the page to save header information.'));
        }
	return null;
}

 
This was selected as the best answer
Sukhdeep SinghSukhdeep Singh
I tried return null. But It does`t work.