0

I am deploying my code to production and i am getting the below error

Failure Message: "System.LimitException: Too many SOQL queries: 101", Failure Stack Trace:

My trigger

trigger OpportunityTrigger on Opportunity (after delete, after insert, after undelete, 
after update, before delete, before insert, before update) {

    if(Trigger.isAfter && Trigger.isInsert){
        {
        EncryptURl.insertOpp(Trigger.new,Trigger.newMap.keySet());
        }
}

and my trigger class is

public static void insertOpp(Opportunity[] o,Set<id> newMapKeySet)
{

    list<Opportunity> oppsToUpdate =[select id,Encrypted_URL__c from Opportunity where id  IN :newMapKeySet];
    for(Opportunity op:oppsToUpdate){
        if(op.id != null){
            string oppid=op.id;
            Blob dataLead = Blob.valueOf(oppid);
            String b64Data = EncodingUtil.base64Encode(dataLead);
            string oppURL =Label.PWV_FavoriteURL+'oId='+b64Data;
            op.Encrypted_URL__c =oppURL;
        }   
   }
    try{
    update oppsToUpdate;
    }catch(exception e){
            system.debug('DMl exception'+e);
     }

}

Can i know where i am going wrong ....

0

1 Answer 1

2

As an always System.LimitException: Too many SOQL queries: 101 is hard to find. Error does not return you place what is a problem but those that cause SOQL number 101. So you have to investigate ALL code around this action. Check your logs. Good luck :)

Btw I don't think you need query for oppsToUpdate as you have those in Trigger.new

Try something like this:

public static void insertOpp(Opportunity[] Opportunities){
    Opportunity[] opps = new Opportunity []{};
    // This is just in case you want only those 2 fields in  opportunities in your list
    for(Opportunity op:Opportunities){
        opps.add( new Opportunity(  Id = op.Id,
                                    Encrypted_URL__c = op.Encrypted_URL__c
                                  ));
    }

    for(Opportunity opp:opps){
        /* your actions*/
    }
    update opps;
}
8
  • i need update opportunity so on before insert it is not possible because the record is null and to do an after i have to query the record other it is giving an error read only
    – user6833
    Jun 17, 2014 at 7:04
  • isn't it recursion? Jun 17, 2014 at 7:10
  • I think it is getting recursion.
    – user6833
    Jun 17, 2014 at 7:11
  • list<Opportunity> oppsToUpdate =[select id,Encrypted_URL__c from Opportunity where id IN :newMapKeySet];// i think the error is with this line when i commented i was able deploy it fine
    – user6833
    Jun 17, 2014 at 7:11
  • how can i query without exceeding the limit
    – user6833
    Jun 17, 2014 at 7:12

Not the answer you're looking for? Browse other questions tagged .