DEV Community

bhanukarkra
bhanukarkra

Posted on

Apex (SObject)

Playing with SObjects:
Account acct = new Account();
acct.Name = 'Acme';
Or
Account acct = new Account(Name='Acme'); //direct initialization

Generic SObject:Gives flexibility in use on any salesforce object.
However specific sObject data type can reference only the Salesforce records of the same type.

sObject sobj1 = new Account(Name='Trailhead');
sObject sobj2 = new Book__c(Name='Workbook 1');
however
Account acct = new Account();

How to cast Generic sobject to specific sobject (benifit to use .notation)
// Cast a generic sObject to an Account
Account acct = (Account)myGenericSObject;
// Now, you can use the dot notation to access fields on Account
String name = acct.Name;
String phone = acct.Phone;

https://trailhead.salesforce.com/content/learn/modules/apex_database/apex_database_sobjects?trailmix_creator_id=shibua&trailmix_slug=ust-sfdc-dev-apex-vf-basics

Apex Hammer:Before each major service upgrade, Salesforce runs all Apex tests on your behalf through a process called Apex Hammer

Top comments (0)