Quantcast
Monday , January 21 2019
Home / Apex / Apex Programming for beginners / Working with Data in Apex

Working with Data in Apex

Working with Data in Apex

As discussed now it’s the time for some real action, in this series you will learn how to interact with data in your Salesforce org.  Before we begin to make sure have created a Salesforce developer org, it is available for free and it is the environment where we will try to implement the Apex we learn here.

 

  • Working with sObjects
  • Data Manipulation Language
  • SOQL and SOSL Queries
  • SOQL For Loops
  • sObject Collections
  • Dynamic Apex
  • Apex Security and Sharing
  • Custom Settings

 

Working with sObjects

sObject is the representation of a row of data in the database and can be a standard (created by Salesforce) or custom (created by user). They are similar to SOAP API, therefore generic sObject abstract type can be used to represent any object. DML works on both generic sObjects and regular sObjects.

Ex:

 

Account acc = new Account();

Object__c custObj = new Object__c ();

 

Casting of sObjects :

sObject s = new Account();

Account a = (Account)s;  —–  Allowed

Contact c = (Contact)s;  —– Not Allowed

 

*Id of a sObject is read-only and can never be modified.

 

Accessing sObjects Fields

 

Fields of sObject are accessible or updateable via the dot notation similar to Java.

 

Fields which is generated by Salesforce system cannot be modified by the user directly.

 

Also, the fields which are generated using a formula are also not modifiable.

 

Ex:

Account a = new Account();

 

a.Name = ‘Nameoftheaccount’;

 

Validating sObjects and Fields

Before execution of the code, the values captured are first parsed against the sObject and if there is any mismatch a run time parse error is encountered.

 

Salesforce also prevents us from making changes which may result in making some apex code invalid, as mentioned below scenario.

  1. Changing the API name of a field or object
  2. Changing the data type of a field
  3. Deletion of an object or one of its field
  4. Making OWD(organization wide changes)

 

Next: Data Manipulation Language DML

About Sumit Datta

Sumit Datta
I am a 3x Certified Salesforce developer with overall 5 years of IT experience and 3 years of Implementation experience in Salesforce. I am here to share my knowledge and help Beginners in Salesforce to understand the concepts of Apex, Visualforce, Salesforce Lightning and Salesforce Configuration.

Check Also

MODAL Box

How to create a Modal box in Lightning Component?

How to create a Modal box in Lightning Component? In this post we are going …

Salesforce Lightning Training

How to send parameters in AuraEnabled methods in Salesforce Lightning Components?

How to send parameters in AuraEnabled methods in Salesforce Lightning Components? Passing value to and …

Salesforce Lightning Tutorials

How to use lightning accordion

How to use lightning accordion and how to dynamically add accordion section in lightning. In …

Salesforce Lightning Tutorial

How to fetch and display list of records in Lightning Component

How to fetch and display list of records in Lightning Component? In this post we …

Leave a Reply

Your email address will not be published. Required fields are marked *