• WHO WE ARE
  • WHAT WE DO
    • Implementations
      • Salesforce
        • Sales Cloud
        • Service Cloud
        • CPQ
        • Field Service for SMEs
        • Field Service Lightning
      • Salesforce Partner Apps
        • Panda Doc
        • Conga
    • Developments
      • Salesforce Customization
      • Custom Application Development
      • AppExchange Product Development
    • Migrations
      • Classic to Lightning Migration
      • Other Systems to Salesforce Migration
    • Integrations
  • HOW WE DO
    • Delivery Model
    • Our Works
  • BLOG
    • WHO WE ARE
    • WHAT WE DO
      • Implementations
        • Salesforce
          • Sales Cloud
          • Service Cloud
          • CPQ
          • Field Service for SMEs
          • Field Service Lightning
        • Salesforce Partner Apps
          • Panda Doc
          • Conga
      • Developments
        • Salesforce Customization
        • Custom Application Development
        • AppExchange Product Development
      • Migrations
        • Classic to Lightning Migration
        • Other Systems to Salesforce Migration
      • Integrations
    • HOW WE DO
      • Delivery Model
      • Our Works
    • BLOG
Salesforce Blog | Salesforce Simple Tutorial
Salesforce Blog | Salesforce Simple Tutorial
  • WHO WE ARE
  • WHAT WE DO
    • Implementations
      • Salesforce
        • Sales Cloud
        • Service Cloud
        • CPQ
        • Field Service for SMEs
        • Field Service Lightning
      • Salesforce Partner Apps
        • Panda Doc
        • Conga
    • Developments
      • Salesforce Customization
      • Custom Application Development
      • AppExchange Product Development
    • Migrations
      • Classic to Lightning Migration
      • Other Systems to Salesforce Migration
    • Integrations
  • HOW WE DO
    • Delivery Model
    • Our Works
  • BLOG

Part IV. 3. SOQL Basics in Salesforce

Salesforce Blog | Salesforce Simple Tutorial > SFDC Training > SFDC Training Part IV > Part IV. 3. SOQL Basics in Salesforce
  • November 2, 2017
  • Merfantz Editor
  • SFDC Training, SFDC Training Part IV
  • 0

To read a record from Salesforce, you need to write a query. Salesforce provides the Salesforce Object Query Language, or SOQL in short, that you can use to read saved records. SOQL is similar to the standard SQL language but is customized for the Lightning Platform.

Because Apex has direct access to Salesforce records that are stored in the database, you can embed SOQL queries in your Apex code and get results in a straightforward fashion. When SOQL is embedded in Apex, it is referred to as inline SOQL.

To include SOQL queries within your Apex code, wrap the SOQL statement within square brackets and assign the return value to an array of sObjects. For example, the following retrieves all account records with two fields, Name and Phone, and returns an array of Account sObjects.

Account[] accts = [SELECT Name,Phone FROM Account];

Prerequisites

Some queries in this unit expect the org to have accounts and contacts. Before you run the queries, create some sample data.

  1. In the Developer Console, open the Execute Anonymous window from the Debug menu.
  2. Insert the below snippet in the window and click Execute.

// Add account and related contact
Account acct = new Account(
Name=’SFDC Computing’,
Phone='(415)555-1212′,
NumberOfEmployees=50,
BillingCity=’San Francisco’);
insert acct;
// Once the account is inserted, the sObject will be
// populated with an ID.
// Get this ID.
ID acctID = acct.ID;
// Add a contact to this account.
Contact con = new Contact(
FirstName=’Carol’,
LastName=’Ruiz’,
Phone='(415)555-1212′,
Department=’Wingo’,
AccountId=acctID);
insert con;
// Add account with no contact
Account acct2 = new Account(
Name=’The SFDC Query Man’,
Phone='(310)555-1213′,
NumberOfEmployees=50,
BillingCity=’Los Angeles’,
Description=’Expert in wing technologies.’);
insert acct2;

Using the Query Editor

The Developer Console provides the Query Editor console, which enables you to run your SOQL queries and view results. The Query Editor provides a quick way to inspect the database. It is a good way to test your SOQL queries before adding them to your Apex code. When you use the Query Editor, you need to supply only the SOQL statement without the Apex code that surrounds it.

Let’s try running the following SOQL example:

  1. In the Developer Console, click the Query Editor tab.
  2. Copy and paste the following into the first box under Query Editor, and then click Execute.

SELECT Name,Phone FROM Account

All account records in your org appear in the Query Results section as rows with fields.This training is very useful to learn about the basics of SOQL in salesforce.

We are the ISV Partners and Please reach us for custom development => www.merfantz.com


  • Previous Part IV. 2. Apex Class Creation in Salesforce
  • Next Part IV. 4. Trigger Creation in Salesforce
We denounce with righteous indignation in and dislike men who are so beguiled and to demo realized by the charms of pleasure moment, so blinded by desire, that they cannot foresee the pain and trouble that are bound.

Discover More

Contact Info

  • 374 William S Canning Blvd, Fall River MA 2721, USA
  • (+880)155-69569
  • [email protected]
  • 10:00 - 17:00

Latest Posts

Salesforce Marketing Cloud Will Fuel Your B2B Marketing Engine. January 30, 2023
Overview of DML operations in Apex January 24, 2023
Benefits of Integrating Salesforce and Marketing Automation for Business Growth January 20, 2023

2023 All Rights Reserved