Achieve your business goals faster by unlocking our Salesforce Cloud Services.
Unlike any other programming language like Java or C#, Apex is tightly integrated with the database.
Hence we do not have to create any database connection to access the records or insert new records.
Instead, in Apex, we have sObjects which represent a record in Salesforce.
For example:
An account record named as Burlington Textiles in apex will be referred using an sObject, like this:
Account acc = new Account(Name=’Disney’);
The API object name becomes the data type of the sObject variable in Apex.
Here,
Account = sObject datatype
acc = sObject variable
new = Keyword to create new sObject Instance
Account() = Constructor which creates an sObject instance
Name =‘Disney’ = Initializes the value of Name field in account sObject
Similarly if we want to create a contact record using Apex then we first need to create a sObject for it in Apex, like this:
Contact con = new Contact();
Now there are 2 ways to assign field values to the contact sObject:
Contact con = new Contact(firstName = ‘Shrey’,lastName = ‘Sharma’);
con.firstName = ‘Shrey’;
con.lastName = ‘Sharma’;
Similarly for Custom Objects:
Student__c st = new Student__c(Name = ‘Arnold’);
If we want to assign the field values for custom fields then also we have to write down their field API name, like:
Account acc = new Account(Name = ‘Disney’, NumberOfLocations__c = 56);
Student__c st = new Student__c(Name = ‘Arnold’, Email__c = ‘arnold @gmail.com’);
< < Previous
Next > >
The batch is going to start shortly. Fill the form given below to Register yourself now.
Fill the form below to get a Result
Fill the form below to get a demo of this course.
Online Salesforce Development Course is soon going to be launched. Please fill the form and we will notify you about the course.