SOQL And SOSL in salesforce

Developing software applications requires you to know how to insert and retrieve data from databases. In Salesforce, you can retrieve data from the databases using SOQL and SOSL. If you want to be a Salesforce developer, then you must know both of these query languages. I have provided you with a detailed explanation of these languages below:

  • SOQL stands for Salesforce Object Query Language. Using SOQL statements, you can retrieve data from the database as a list of sObjects, a single sObject or an Integer for count method. You can think of the SOQL as an equivalent of a SELECT SOQL query. I have provided an example of a SOQL query below:

List<Account> accList = [SELECT Id, Name FROM Account WHERE Name=”YourName”];

  • SOSL stands for Salesforce Object Search Language. You can use SOSL statements to retrieve a list of sObjects, where each list contains the search results for a particular sObject type. You can think of SOSL as an equivalent to a database search query. I have provided an example of a SOSL query below:

List<List<sObject>> searchList = [FIND ‘map*’ IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead];

You can use SOQL when you know which object the data resides in and use SOSL when you don’t know the name of the object where the data resides.

Classes And Methods

Like in every other object oriented programming language, you can develop classes and methods using Apex. You can think of a class as a blueprint using which individual objects are created and used. You can think of a method as a subprogram, which acts on data and returns a value. I have provided you with the syntax to write a class and method below:

I will now show you how to add a class and method in Apex:

Step 1: From setup enter Apex Classes in QuickFind Box, then select Apex Classes and click New.

Step 2: In the editor add the following class definition:

Public class HelloWorld {

}

Step 3: Add a method definition between the class opening and closing brackets:

Public static void helloWorldMethod(Country__c[] countries) {

For ( Country__c country : countries){

country.currency_value__c *= 1.5;

}

}

Step 4: Click on Save and you should have your full class as:

Public class HelloWorld {

Public static void helloWorldMethod(Country__c[] countries) {

For ( Country__c country : countries){

country.currency_value__c *= 1.5;

}

}

You can use the syntax and example shown above to develop your own classes and methods for your Salesforce application. To become a Salesforce developer you need to know more than just writing classes and methods. In the next few sections, I will discuss topics which make developing applications on the Salesforce platform simple and easy.

Tech enthusiastic, life explorer, single, motivator, blogger, writer, software engineer