function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Shaun AShaun A 

Basic SOQL understanding

public Object__c incSearch = new Object__c ();

 

Result  = filed__c from Object__c where Status__c =: incSearch.Status__c OR Incident__c like :incSearch.Incident_No_for_Search__c+'%' OR Applies_To__c=:incSearch.Applies_To__c OR Responsible__c = :incSearch.Responsible__c];

 

Please explain the above code and what is use of '%' here ??

 

Thanksin advance!!

Best Answer chosen by Admin (Salesforce Developers) 
nickwick76nickwick76

In the below example 'Status__c' is a field on the object you are querying. What you are doing here is adding a condition to narrow the amount of records to return from the query.

IncSearch is an instance of an object that you either instantiated in your class or got as a response from another SOQL-query. The IncSearch instance contains a lot of fields which have values that you in this case want to compare with.

 

The colon (:) is used in SOQL-queries to bind the values of parameters outside of the SOQL-query.

 

So that is basically what's going on here. You are checking if the value of Status__c of any record in the org of a specific type is equal to the value of the field Status__c in the incSearch instance. 

 

Status__c=:incSearch.Status__c

 


HTH / Niklas

All Answers

nickwick76nickwick76

Hi,

It looks a bit strange with only a right bracket and no select?

But anyways % (percent sign) is used in combination with the keyword 'like'.

 

In your example below:

Incident__c like :incSearch.Incident_No_for_Search__c+'%'

means that the field 'Incident__c' should be equal to the value of variable incSearch.Incident_No_for_Search__c and whatever comes after this value.

 

A simple example is:

select Id,name from Opportunity where name like 'Test%'

This means, select all opportunities with a name that starts with 'Test'

 

HTH / Niklas

Shaun AShaun A

Hi Nick,

 

ok thanks for providing your valuable inputs.

one more thing here

Status__c=:incSearch.Status__c, Incident__c=:incSearch.Incident_No_for_Search__c,  Applies_To__c=:iincSearch.Applies_To__c 

what's the purpose incSearch.______ of in condition?? 

 

Thanks.

nickwick76nickwick76

In the below example 'Status__c' is a field on the object you are querying. What you are doing here is adding a condition to narrow the amount of records to return from the query.

IncSearch is an instance of an object that you either instantiated in your class or got as a response from another SOQL-query. The IncSearch instance contains a lot of fields which have values that you in this case want to compare with.

 

The colon (:) is used in SOQL-queries to bind the values of parameters outside of the SOQL-query.

 

So that is basically what's going on here. You are checking if the value of Status__c of any record in the org of a specific type is equal to the value of the field Status__c in the incSearch instance. 

 

Status__c=:incSearch.Status__c

 


HTH / Niklas

This was selected as the best answer