You need to sign in to do that
Don't have an account?
System.Exception: Too many SOQL queries: 101
Looking for some general help with this issue.
Also, in my efforts to limit my SOQL queries, I am trying to combine redundant ones using relationship queries. Such as
Select (Select Fire_Alarm_Inspection__c, Fire_Protection__c, Fire_Extinguisher__c, Fire_Suppression__c From Inspections__r), (Select Name__c From Floors1__r where exits_to_ground__c = true) From Account_c__c a Where ID = 'a0A70000006jSDV'
My problem lies in how exactly to access the dat returned in this query. I tried this:
Account_c__c account =[Select (Select Fire_Alarm_Inspection__c, Fire_Protection__c, Fire_Extinguisher__c, Fire_Suppression__c From Inspections__r), (Select Name__c From Floors1__r where exits_to_ground__c = true) From Account_c__c a Where ID = :buildingid];ground = account.Floors1__r.name__c;
but I am being told "Invalid foreign key relationship: Account_c__c.Floors1__r ", I ran the above query in the schema browser in Eclipse and got the results I wanted, but it won't work in my apex, or if it is working, I don't know how to access the data.
Thanks in advance for the help.
There's definitely limits to what you can build on the platform due to all `govern limits, but still you can create pretty advanced stuff.
To avoid hitting limits, 'bulkify' your code. A good article about it can be found here:http://wiki.developerforce.com/index.php/Apex_Code_Best_Practices
All Answers
Looking at your queries, I would expect account.Floors1__r to contains a List of Floors1__c records (all related Floors1__c records to the Account you queried). So basically you will need a loop to access them:
for(Floors1__c floor : Floors1__r) {
ground = floor.Name__c;
}
Not 100% sure if i got object names and relations right (you sure chose some weird names for the objects and fields), but this is what the posted query suggests.
I sure do! In retrospect Account_c__c was a horrible choice. LOL
Anyway, I see what you mean with the results being a List, but would I have to cycle through like you said even if the query only returns one result?
ground = Floors1__r[0].Name__c;
would suffice then.
OK, so here is a SOQL limit question, if I write an Apex Class that uses, say 50 SOQL queries and then I write a Controller that calls that Class three times, will I run against the 101 SOQL Query limit?
Probably, huh?
If so, how does one write complicated, scaleable Apex code while staying within the 101 allowable SOQL queries?
There's definitely limits to what you can build on the platform due to all `govern limits, but still you can create pretty advanced stuff.
To avoid hitting limits, 'bulkify' your code. A good article about it can be found here:http://wiki.developerforce.com/index.php/Apex_Code_Best_Practices