Deprecated: trim(): Passing null to parameter #1 ($string) of type string is deprecated in /home1/oijoiv2f/public_html/wp-content/themes/entaro/template-posts/single/inner.php on line 23

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

Sumit Datta

Sumit Datta

I am a 5x Certified Salesforce developer with overall 7 years of IT experience and 5 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.

2 Comments

  1. […] Next : Working with Data […]

  2. […] Working with Data in Apex | SalesforceNextGen. 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. […]

Leave a Comment

Your email address will not be published.