Thursday, July 24, 2014

How to use sObject in Apex salesforce

Hi so today I was searching around the net to get some example to use sObjects of salesforce but I was not able to find some, so I decided to make one here with very easy approach.


  • Declaring a sObject - sOject objAcc = new sObject (); // without type
                                     sOject objAcc = new Account (); // with type
  • Getting field values - sOject objAcc = new Account ();
                                    Id oId = objAcc.Id;
                                    String nameAcc = objAcc.get('Name'); // "Name" is field's API name
  • Setting field values - sOject objAcc = new Account ();
                                    objAcc.put('Name','TestName');
Hope this helps someone.

No comments:

Post a Comment