Activity Forums Salesforce® Discussions How Will the Default value be applied to a new record created by apex in Salesforce?

  • Nikita

    Member
    September 20, 2019 at 12:38 pm

    Hi Prachi,

    If the Default value of the field is not getting populated by Apex then we have to use “Dynamic Apex”.  Create instance of object from sObjectType like shown below:

    Training__c tr= (Training__c) Training__c.sObjectType.newSObject(null, true);
    
    //Check if Value in field "Trainer__c" is default value
    System.assertEquals('Jitendra', tr.Trainer__c);

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos