+ Start a Discussion
Sunny_SlpSunny_Slp 

Inner SOQL query and governor limits

Hi Everyone,

 

I'm trying to retrieve  Partial_Control_Group__c records connected via junction object CSAP_CGLP_Junction__c to CRD__c

 

here is my query:

 

pcgList=[SELECT Id,Name,CSAP_Control_ID__c,CSAP_Plan_ID__c FROM Partial_Control_Group__c WHERE Id IN (SELECT Partial_Control_Group__c FROM CSAP_CGLP_Junction__c WHERE CRD__c=:sourceCrdId) ORDER BY Name]; 

/*build string*/ 

for(Partial_Control_Group__c pcg:pcgList){
      s=s+pcg.get('CSAP_Control_ID__c')+pcg.get('CSAP_Plan_ID__c')+',';
    } 

 

 is it safe (in terms of governor limits) to use inner query in this case?  there are 2000-3000 records for each CRD__c  and I'm worried about hitting any governor limits...would you call this safe way to do it or is there another even better way ?

 

Thank you,

SunnySlp

Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

The docs state that each sub-query counts as an additional query for the purpose of governor limits.  Its a perfectly reasonable way to pull back parents and their children as long as you don't return 50,000 rows and breach that governor limit.

All Answers

bob_buzzardbob_buzzard

The docs state that each sub-query counts as an additional query for the purpose of governor limits.  Its a perfectly reasonable way to pull back parents and their children as long as you don't return 50,000 rows and breach that governor limit.

This was selected as the best answer
Sunny_SlpSunny_Slp

Thank you :)