Activity Forums Salesforce® Discussions How to check if any error has been added to a Salesforce record?

  • Mohit

    Member
    September 8, 2016 at 5:52 am

    Hi Tanu,

    The addError methods in a Visualforce context will also add to the Apex Page messages collection, which you can access via the ApexPages.getMessages method.

    Use the apexMessages on the visualforce page and apex controller :-

    sObject testRecord = new sObject();
    testRecord.addError('Some error');
    testRecord.A_Number__c.addError('Field error');
    for(ApexPages.Message message : ApexPages.getMessages())
    System.debug(message.getComponentLabel() + ' : ' + message.getSummary());

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos