+ Start a Discussion
Saru VadlamudiSaru Vadlamudi 

Soql 101 error on deployment-urgent

We are facing the issue with soql 101 error while deploying trigger.We have tried to capture the issue in all the ways.please let me know where could be the causing an isssue in below code.its an urgent request.

trigger contactdetails on Contact (before update) {
Map<id,id> cntctOwnerMap = new Map<id,id>();
Map<id,id> accountOwnerMap = new Map<id,id>();
Map<id,id> accountTeamMap = new Map<id,id>();
Map<id,id> accountidMap = new Map<id,id>();
Map<id,id> accountTeamMember = new Map<id,id>();


List<contact> ct1 = new List<Contact>();
set <string> profileids = new set<string>{'00e700000013gAKAAY','00e700000013gPeAAI','00e700000013YgPAAU','00e70000000x3egAAA','00e70000000x8q3AAA','00e70000000xE3lAAE','00e70000000xE7xAAE','00e70000000sR8UAAU','00e70000000xBqJAAU','00e70000000x3XVAAY','00e700000013YIGAA2','00e70000000x3oSAAQ'};
set <id> userIds = new set<id> {'00570000001u6pxAAA','00570000002VUUlAAO','00570000001R8tOAAS'};
List <id> accountids = new List<id>();
String currentprofileid = Userinfo.getprofileid();
map<id,set<id>> a = new map<id,set<id>>();
List<accountteammember> acc = new List<accountteammember>();

ct1 = [select id , ownerid , account.ownerid , accountid from contact where id in : trigger.newMap.keySet()];
for(Integer i = 0 ; i<ct1.size() ; i++)
{
cntctOwnerMap.put(ct1[i].id,ct1[i].ownerid);
}

for(Integer i = 0 ; i<ct1.size() ; i++)
{
accountOwnerMap.put(ct1[i].id,ct1[i].account.ownerid);
}

for(Contact ct: ct1)
{
accountidMap.put(ct.id,ct.accountid);
accountids.add(ct.accountid);
}
acc = [select id , accountid , userid from accountteammember where accountid in : accountids];
for(Id ab : accountids)
{
set <id> aa = new set < id > ();
for(accountteammember at: acc)
{
if(at.accountid==ab)
{
aa.add(at.userid);
}
}
a.put(ab,aa);
}

for(contact c : trigger.new){

if(userinfo.getuserid()==cntctOwnerMap.get(c.id) || userinfo.getuserid()==accountownermap.get(c.id) || a.get(accountidMap.get(c.id)).contains(userinfo.getuserid()) || profileids.contains(userinfo.getprofileid()) || userIds.contains(userinfo.getuserid()))
{}else{
c.adderror('You are not authorized to make any change on the Contact.');
}
}
}



srlawr uksrlawr uk
I have been through your code line by line 10 times, and I can't see any weakness that could cause a SOQL limit reception in this particular trigger! Is it definitely coming from this class, or is it just being thrown as you try to deploy this class? Could you post the actual message you are getting? Honestly, this code looks legit.

By the way, please use the "code" format box (the <> in the formatting bar) when posting code, and the forum will format and colourise it - which makes reading it a lot easier! Also, on a personal note, having tried to read that code - more descriptive variable names are invaluable, and basically free!
Temoc MunozTemoc Munoz
It's hard to follow your code.

- Make sure your trigger is not being fired more than once in the same context.
- Make sure no other process or trigger is being fired after your trigger
- Trace your debug logs
- Use Limits class and trace your code https://developer.salesforce.com/page/Apex_Code_Best_Practices
jyothsna reddy 5jyothsna reddy 5
Hi Saru,

please refer below link
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000MKubIAG

Regards ,
Jyothsna D