You need to sign in to do that
Don't have an account?
Shaun 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!!
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
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
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.
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