You need to sign in to do that
Don't have an account?

Your help needed - please a little urgent
Hi All,
Could you help me with the following piece of code :
----------------------------------------------------------------------------------------------------------
if(acclst.size()>0) {
for(Account acc:acclst) {
//Check if Account have contact/Opportunity associated with it
opplst = [select Id,AccountId from Opportunity where AccountId =:acc.Id];
conlst = [select Id from Contact where AccountId in:acc.Id];
if(opplst.size()==0&&conlst.size()==0) {
/*
* If Account do not have the contacts and opportunities associated to it
* then add those account Ids in the set
*/
sAccId.add(acc.Id);
}
else {
sAccId_CO.add(acc.Id);
}
}
-----------------------------------------------------------------------------------------------------
The problem : I am running this through a trigger, and since a query should not be in loops i am hitting TOO MANY SQL QUERY exception. Could you please have a look at the code and modify it to make it work for me ?
Your help will be really appreciated,
Rajat
I guess this should work. let me know if it doesnt work.
All Answers
I guess this should work. let me know if it doesnt work.
Hi
Please take out your query from for loop and use map. This will solve this error. The error is because it is hitting governor limits.
Thanks
Anu
Man Thanks!!!!!
Just a little code modification, but it worked !!