You need to sign in to do that
Don't have an account?
ashish gupta 61
Need to avoid SOQL inside for Loop
Hi All,
I have to avoid User Soql inside for loop. I have a custom object filldata__c. I need each user record for every filldata ID and want to avoid this user SOql query in for loop
List<fill_Data__c> fillDatalist = [Select id,CreatedById,Action_Type__c from fill_Data__c Where Action_Type__c='BulkParent'];
for(fill_Data__c obj:fillDatalist){
fillIDWithCreatedBYIDMap.put(obj.ID,obj.CreatedById);
}
for(ID fillID :fillIDWithCreatedBYIDMap.keyset()){
if(fillIDWithCreatedBYIDMap.containsKey(fillID)){
User user=[select ID,FirstName,LastName,email from user where Id =:fillIDWithCreatedBYIDMap.get(fillID) limit 1]; // I want to avoid this user SOql query in for loop
}
}
Please check above code and provide your solution It would be great help.
I have to avoid User Soql inside for loop. I have a custom object filldata__c. I need each user record for every filldata ID and want to avoid this user SOql query in for loop
List<fill_Data__c> fillDatalist = [Select id,CreatedById,Action_Type__c from fill_Data__c Where Action_Type__c='BulkParent'];
for(fill_Data__c obj:fillDatalist){
fillIDWithCreatedBYIDMap.put(obj.ID,obj.CreatedById);
}
for(ID fillID :fillIDWithCreatedBYIDMap.keyset()){
if(fillIDWithCreatedBYIDMap.containsKey(fillID)){
User user=[select ID,FirstName,LastName,email from user where Id =:fillIDWithCreatedBYIDMap.get(fillID) limit 1]; // I want to avoid this user SOql query in for loop
}
}
Please check above code and provide your solution It would be great help.
http://wiki.developerforce.com/page/Apex_Code_Best_Practices
It will help you.