You need to sign in to do that
Don't have an account?
i have an Sobject List now how do i compare one of the field values to a string?
I have a list in my trigger
List <Trial__c> Tr = [Select id, Quote__c, Trial_Sub_Status__c from Trial__c where Quote__c in (Select QuoteId from QuoteLineItem )];
I want to run some code if the string 'Approved' exists in any of the records returned in my List definition
if(Tr[0].Trial_Sub_Status__c =='Approved') works for a single value but how can i iterate through each of the values for this specific field? I only anticipate 1-3 records at the most.
been searching for a while now and can't seem to figure out the right words to search with.
Thanks
you can iterate the list with a for loop:
List <Trial__c> Tr = [Select id, Quote__c, Trial_Sub_Status__c from Trial__c where Quote__c in (Select QuoteId from QuoteLineItem )];
for(Trial__c T : tr){
if(T.Trial_Sub_Status__c =='Approved'){
// Do what u want..
}
}
All Answers
you can iterate the list with a for loop:
List <Trial__c> Tr = [Select id, Quote__c, Trial_Sub_Status__c from Trial__c where Quote__c in (Select QuoteId from QuoteLineItem )];
for(Trial__c T : tr){
if(T.Trial_Sub_Status__c =='Approved'){
// Do what u want..
}
}
Thanks Anil,
This is exactly what i needed. I wasn't able to crack if by myself so i ended up revisiting my requirements and realized that i only need to identify at least one Trial__c record with an Approved status so i updated my SOQL query with that additional filter effectively reducing my List Tr and removing the need to iterate through it on my if condition.