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
Geetha ReddyGeetha Reddy 

very urgent issue.....

Hi,
I want to add error for save functionallity
so can any one help on this..  
public void saveRecord(){
    for(sObject obje : ssc.getRecords())
    {
    if(obje.get('WSR_Product__c')!=NULL)
    {
     try{
     upsert obje;
    system.debug('!!!!!!!!!!!!!!!!!!!' +obje);
   }
   
   catch(Exception e)
    {
     ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'Object API name is invalid')) ;  
    }
      }
       }
        //Make ssc variable null and execute get method
        ssc = null;
        getRecords();
        
    }
    
Navatar_DbSupNavatar_DbSup

Hi,

Try the below code snippet as reference:

 

public void saveRecord()

{

    for(sObject obje : ssc.getRecords())

    {

    if(obje.get('WSR_Product__c')!=NULL)

    {

     try{

  //or you can add error for the record

  //obje.adderror('record name can't be null');

     upsert obje;

    system.debug('!!!!!!!!!!!!!!!!!!!' +obje);

   }

  

   catch(Exception e)

    {

ApexPages.Message ErrMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Object API name is invalid');

 ApexPages.addMessage(ErrMsg ); 

    }

      }

       }

        //Make ssc variable null and execute get method

        ssc = null;

        getRecords();

       

    }

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

 

 

 

Geetha ReddyGeetha Reddy

now also no giving any error message.

Shashikant SharmaShashikant Sharma

Hi Geetha,

 

TO get the custom error message your code has to reach in catch block. In case fif it does reach and you are still not able to see the error message than check whether you have a apex:pagamessages component iin you page. Add if you do not have it.

 

Let me know f you still face isssue.