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
Phuc Nguyen 18Phuc Nguyen 18 

Get record from a List based on current record being updated

Hello,
I was wondering.  What is the best way to get the record from a list based on the currecnt record.
For example I have this list where I am grabbing all the records where the ProjectT Name is 'Closed Templates'
cprojects = [SELECT Id, ProjectT__r.Name, Cand_Project__c,Cand__c 
                FROM Project__c WHERE  ProjectT__r.Name =: 'Closed Templates'];
In a nother method how can I grab the the record/field from the list based on the current record.  What I am trying to go is query all of the records that meet the criteria so that I only have to query it once in the class but need to be able to get a record from list based on the current record being updated.
Thanks,
P
GauravGargGauravGarg
@Nguyen,

Your query is correct, just make use of FOR loop in-case no result returned it will not hit an error. 
List<Project__c> cprojects = new List<Project__c>();
for(Project__c p : [SELECT Id, ProjectT__r.Name, Cand_Project__c,Cand__c 
                FROM Project__c WHERE  ProjectT__r.Name =: 'Closed Templates']){
cprojects.add(p);
}


Thanks,

Gaurav
Skype: gaurav62990

Phuc Nguyen 18Phuc Nguyen 18
Thanks for the reply Gaurav,
So how do I grab a record from the list based on the current record being update?  
The list right now is grabbing all of the records in teh org that meet that criteria.  In a nother method I would like to go through the list and grab field(s) from teh lsit based on the current record being updated.
Thanks you,
Becky BarnettBecky Barnett
Your content helped me a lot to take my doubts, thank you very much.  
https://www.walgreenslistens.mobi/
mich kelmich kel
The online world helps us a lot to make our works easy. Per your health is an online Medical Payment Portal. It helps patients to pay medical bill online. It collects payments from the patients according to the billing. Check https://peryourhealth.vip here.