Adding Fields to sObjects
2 ways to add fields to sObjects. The first is called constructor and the second is called dot notation.
Example 1: Constructor
Account acct = new Account(Name=‘NameValue’); Name is the field name; it doesn’t have trailing __c because it’s a standard field to Salesforce’s standard Account object. Note the single quotation marks to encapsulates the NameValue. If you want the sObject’s “Name” datafield to have a value of “Salesforce Consulting Company” then you would replace ‘NameValue’ with ‘Salesforce Consulting Company.’
Add a trailing comma in order to add new fields & field values.
Account acct = new Account(Name='Salesforce Consulting Company', Phone='(555)555-5555', ClientStatus__c=‘Active’, ContactCount__c=100);
Notice how numeric values do not need to be inside single quotation marks.
Example 2: dot notation Account acct = new Account (); acct.Name = ‘Salesforce Consulting Company’; acct.Phone = ‘(555)555-5555′; ClientStatus__c=‘Active’; ContactCount__c=100;







