Tag: Structured Object Query Language

  • All You Need to Know About SOSL and Related Records in Apex

    All You Need to Know About SOSL and Related Records in Apex

    In this blog, we will discuss what are related records in Salesforce and what we understood by SOSL in apex

    What are Related Records in Apex?

    Inserting Related Records

    Example :

    Account acc = new Account(Name=’abc’, Phone = ‘123456’); 
    insert acc; 
    Contact con = new Contact(Account=acc.Id, FirstName = ‘abc’ , LastName = ‘xyz’, Phone = ‘12345’); 
    Insert con;

    Updating Related Records

    Contact con = [SELECT Id, Name,Account.Phone FROM Contact WHERE Name = ‘abc’ AND AccountId!=Null AND Account.Name = ‘Account1’];  
    Con.Phone=’111’; 
    Con.Account.Phone=’2222’; 
    update con; 
    update con.Account;

    dont miss out iconDon’t forget to check out: Learn All About Salesforce Apex Programming

    Now, let’s move to SOSL!

    What is SOSL in Apex?

    • SOSL stands for Salesforce Object Search language. 
    • It is used to perform a text search in records. 
    • We can use SOSL to search fields across multiple sObjects records. 
    • SOQL is used to retrieve records for a single object whereas use SOSL to search fields across multiple objects. 

    Syntax 

    Find ‘SearchQuery’ [IN SearchGroup] [RETURNING ObjectsAndFields];

    What is a SearchQuery?

    • Single Word: It should be enclosed in single quotes. 
    • Phrase: It is having multiple words and should be enclosed in double quotes. 

    What is a SearchGroup?

    SearchGroup is optional. 

    • The default is ALL FIELDS. 
    • You can choose from the following search groups: 
    • ALL FIELDS 
    • NAME FIELDS 
    • EMAIL FIELDS 
    • PHONE FIELDS 
    • SIDEBAR FIELDS 

    ObjectsAndFields 

    • ObjectsAndFields is optional. 
    • It is the information to return in the search result – a list of one or more sObjects and within each sObject, list of one or more fields, with optional values to filter against. 
    • If not specified the search result contain the IDs of all objects found. 

    dont miss out iconCheck out another amazing blog by Bhawana here: All You Need to Know About Database Class Methods to Perform DML Operations

    Execute Anonymous Window 

    List<List<sObject>> searchList = [FIND ‘Cloud’ IN ALL FIELDS RETURNING Account(Name),Contact(FirstName, Lastname, Email)];

    Query Editor 

    FIND {Cloud} IN ALL FIELDS RETURNING Account(Name), Contact(FirstName, LastName, Email)];

    For example:

    List<List<sObject>> searchList = [FIND ‘Abc’ IN ALL FIELDS RETURNING Account(Name), Contact(FirstName,LastName,Email)]; 
    List<Account> accList = new List<Account>(); 
    List<Contact> conList = new List<Contact>(); 
    accList = (List<Account>) searchList[0]; 
    conList = (List<Contact>) searchList[1]; 
    for(Account acc : accList)
    { 
        System.debug(‘Name =>' + acc.Name); 
    } 
    for(Contact con : conList)
    { 
        System.debug(con.FirstName + ‘ ‘ + con.LastName); 
    }

    So, this is all about related records in apex and SOSL. I hope this information is helpful to you. 

  • Learn All About Salesforce Apex Programming

    Learn All About Salesforce Apex Programming

    What is Apex? 

    In the CRM cloud platform, Apex is an object-oriented programming language that has syntax similar to Java, which is also an object-oriented language. APEX has built-in functions or procedures to handle operations such as inserting, updating, deleting, and handling DML errors. It creates schema objects directly from schema objects like sObject. 

    In addition to releasing and updating Apex with every Salesforce release, Apex is automatically included with the Salesforce cloud platform. 

    These are some of the important Apex applications:  

    1. Create web services and integrate them with external systems
    2. Email services
    3. Create custom transactional logic
    4. Perform complex validation over several objects at once, and also perform custom validation

    The Apex platform works with SOSL and SOQL query languages designed specifically for Salesforce. 

    dont miss out iconDon’t forget to check out: What is Constructor in Apex Programming? | Salesforce Apex Guide

    What is Apex SOSL?

    Apex SOSL refers to Salesforce Object Search Language. SOSL can search across multiple objects for a particular string. It has the following capabilities: 

    1. Many objects can be searched at a time. 
    2. It can be used in classes but not in triggers 
    3. DML operations cannot be performed on searched results.  
    4. It can only query EMAIL, text, and phone type fields. The results are not objects.  
    5. The results are the fields, not the objects themselves. 

    What is Apex SOQL?

    A Structured Object Query language (SOQL) is used for DML operations such as INSERT, UPDATE, DELETE, UPSERT, etc. It has the following capabilities: 

    1. Only one object can be searched at a time.  
    2. It can be used in classes and triggers and can query all types of fields.  
    3. DML operations can only be performed on query results.  
    4. Record-level operations only return records. 

    How can Apex classes be Executed in Salesforce?

    1. Scheduling the apex class.  
    2. Using triggers or process builder.  
    3. Using web services.  
    4. Using SOAP or REST API.  
    5. Using an anonymous block.  
    6. Invoking JavaScript in VF pages or asynchronously. 

    dont miss out iconCheck out another amazing blog by Nikhil here: Salesforce Postman Integration – A Short Guide

    What are Apex Triggers?

    A trigger is a stored procedure that executes when a given event occurs. Triggered events are those that can be executed before and after an event occurs on a record. 

    1. Insert
    2. Update
    3. Delete
    4. Upsert
    5. Undelete
    6. Learn All About Salesforce Apex Programmingmerge 
  • Learn All About Salesforce Apex Programming Language

    Learn All About Salesforce Apex Programming Language

    What is Apex?

    In the CRM cloud platform, Apex is an object-oriented programming language that has syntax similar to Java, which is also an object-oriented language. APEX has built-in functions or procedures to handle operations such as inserting, updating, deleting, and handling DML errors. It creates schema objects directly from schema objects like sObject. 

    In addition to releasing and updating Apex with every Salesforce release, Apex is automatically included with the Salesforce cloud platform. 

    These are some of the important apex applications 

    1. Create web services and integrate them with external systems.  
    2. Email services. 
    3. Create custom transactional logic.  
    4. Perform complex validation over several objects at once, and also perform custom validation. 

    The Apex platform works with SOSL and SOQL query languages designed specifically for Salesforce. 

    dont miss out iconDon’t forget to check out: Apex Design Patterns: The Singleton Pattern in Salesforce

    Apex SOSL

    Apex SOSL refers to Salesforce Object Search Language. SOSL can search across multiple objects for a particular string. It has the following capabilities: 

    1. Many objects can be searched at a time. 
    2. It can be used in classes but not in triggers.  
    3. DML operations cannot be performed on searched results.  
    4. It can only query EMAIL, text and phone type of fields. The results are not objects.  
    5. The results are the fields, not the objects themselves. 

    Apex SOQL

    A Structured Object Query language (SOQL) is used for DML operations 

    such as INSERT, UPDATE, DELETE, UPSERT, etc. It has the following capabilities: 

    1. Only one object can be searched at a time.  
    2.  It can be used in classes and triggers and can query all type of fields.  
    3. DML operations can only be performed on query results.  
    4. Record-level operations only return records. 

    Apex Classes can be Executed in So Many Ways in Salesforce:

    1. Scheduling the apex class.  
    2. Using triggers or process builder.  
    3. Using web services.  
    4. Using SOAP or REST API.  
    5. Using an anonymous block.  
    6.  Invoking JavaScript in VF pages or asynchronously. 

    dont miss out iconCheck out another amazing blog by Mohit here: Salesforce Lightning Component Framework – Learn All About it Here

    Apex Triggers

    A trigger is a stored procedure which executes when a given event occurs. Triggered events are those that can be executed before and after an event occurs on a record. 

    • Insert
    • Update
    • Delete
    • Upsert
    • Undelete
    • merge