- September 20, 2019 at 11:33 am #63109Prachi #6
How Will the Default value be applied to a new record created by apex in Salesforce?
There is a custom Object named “Training__c” which has field “Trainer__c”. I have set some default value in that field. I want to know if that default value will be applied to new record created by apex code , if yes than please explain me how?September 20, 2019 at 12:38 pm #63120Nikita #1
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:1234Training__c tr= (Training__c) Training__c.sObjectType.newSObject(null, true);//Check if Value in field "Trainer__c" is default valueSystem.assertEquals('Jitendra', tr.Trainer__c);
Please Register to reply to this topic. /