• Colealars
  • NEWBIE
  • 50 Points
  • Member since 2009

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 8
    Replies

Can someone tell me how to fix the error below on my trigger:

 

Error:Apex trigger ContractChangeQuote caused an unexpected exception, contact your administrator: ContractChangeQuote: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 0QL700000000zWnGAI; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ContractChangeQuote: maximum trigger depth exceeded Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote

trigger ContractChangeQuote on Quote (after update) {
If(Trigger.isUpdate){
     //check the opprtunites in the trigger to see if the Contract Term changed, if so add them to a Set
     Set<Id> UpdatedOppIds = new Set<Id>();
        string term;
        for(Integer i=0;i<trigger.new.size();i++){  
            if(trigger.old[i].Contract_Term__c == null){
                term = '';
            } else {
                term = trigger.old[i].Contract_Term__c;
            }    
            //if(trigger.new[i].Contract_Term__c <> trigger.old[i].Contract_Term__c){
            if(trigger.new[i].Contract_Term__c <> term) {
                UpdatedOppIds.add(Trigger.new[i].id);
            }
        }
         
        //Process any opps that have changed
        if(UpdatedOppIds.size() > 0){
            //get all of the quote Line items tied to opportunities in this trigger
            List<Quote> qliList = [select Id, Name, Contract_Term__c, (select Id, ContractTerm__c, QuoteId from QuoteLineItems) from Quote where Id IN :UpdatedOppIds];
             
            //create list to hold quote line items that need updating.
            List<QuoteLineItem> qliUpdateList = new List<QuoteLineItem>();
             
            //loop through opportunites and update all of the quote line items. add line items to update list.
            for(Quote o : qliList){
                for(QuoteLineItem qli : o.QuoteLineItems){
                    qli.ContractTerm__c = o.Contract_Term__c;
                    qliUpdateList.add(qli);
                }
            }
             
            //update the line items
            if(!qliUpdateList.isEmpty()){
                update qliUpdateList;
            }
        }
    }
}

 

trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6]: []: Trigger.ContractChangeQuote: line 36, column 1

Can someone help me modify the query below to filter on Product2.isActive = true

 

Select description, PricebookEntry.isActive FROM OpportunityLineItem WHERE PricebookEntry.IsActive = true

I have a field End_customerId__c on Opportunity which is a lookup to Account.  I've named the relationship End_Cust_Lookup.   I'm trying to get back a list of Opportunities where the accountnumber on the related account record is null. 

 

When I try this query:

 

Select Opp_Uid__c,end_cust_lookup__r.accountnumber From opportunity  where  end_cust_lookup__r.accountnumber = NULL AND Opp_Uid__c <> NULL

 

I get an error Unable to open Schema Browser. Malformed_Query - end_cust_lookup__r.accountnumber From opportunity where end_cust_lookup__r.accountnumber.  No viable alternative at character ''.


I also tried the following but that doesn't filter out the non null records because I guess you can't filter master records from child this way/

 

Select  (Select Opp_Uid__c From End_Cust_Lookup__r where Opp_uid__c <> NULL )  From Account a where  a.accountnumber = NULL
 

 

I'm trying to filter the result set of the following query to only return records where Opp_Uid__c is not null.

 

Select  (Select Opp_Uid__c From End_Cust_Lookup__r where stage_code_num__c < '50' )  From Account a where  a.accountnumber = NULL

 

When I add the where End_Cust_Lookup__r.Opp_uid__c <> NULL at the end of the statement above I get an error that it didn't understand relationship Ennd_Cust_Lookup__r in field path.

 

When I add Opp_uid__c <> NULL to the where clause in the subquery I get the same results set as I do without this additional where.

 

Maybe I'm going about this all wrong.  I have a lookup field end_customerID__c on the opportunity object which does a lookup to account.  I want to return a list of opportunities where the account.accountnumber is null on the end customer listed on the Opp.

 

 

Can someone tell me what I'm missing here.  In the debug log it says no records found after I update an OpportunityLineItem record:

 

Trigger.oppLineItem_prod_data_trigger2: line 20, column 33: SOQL query with 0 rows finished in 3 ms

 

trigger oppLineItem_prod_data_trigger2 on OpportunityLineItem (after insert, after update) { Set<String> opportunityLineItemIDs = new Set<String>(); List<OpportunityLineItem> updtOpportunityLineItems = new List<OpportunityLineItem>(); OpportunityLineItem[] opportunityLineItems = new List<OpportunityLineItem>(); OpportunityLineItem[] oliList = [select pricebookentry.product2.bu_code__c FROM OpportunityLineItem where id in :opportunityLineItemIDs]; for(OpportunityLineItem oli : oliList) { oli.bu_code__c = oli.pricebookentry.product2.bu_name__c; } update oliList; }

 

I've gone round and round with trying to create a trigger on a custom object opportunitywwa__c that need to set the value of opportunity.has_wwa__c to true if it is currently false.

 

Opportunitywwa__c  has a field named opportunity_name__c which is a lookup to opportunity which may or not be populated. 

 

Since there can be one or more opportunitywwa__c records mapped to a single opportunity I only need to update the Opportunity.has_wwa__c field if the value is false.

 

Here is the code that I can't get to compile:

trigger updt_Opp_Has_OR3 on OpportunityWWA__c (after insert, after update) { Set<id> oppsToUpdate = new Set<id>(); //add the opportunityID from the lookup field into the set for (OpportunityWWA__c wwa : Trigger.new){ if (wwa.opportunity_name__c <> null){ oppsToUpdate.add(wwa.opportunity_name__c); } } //get list of Opportunities that need to be updated for(Opportunity opp : [SELECT Id, (select opportunity_name__c FROM OpportunityWWA__R where id IN : oppsToUpdate and opportunity_name__c <> null) from opportunity where has_ors__c = false]) { opp.has_www__c = true; } if(opp.size() > 0){ //I get error on this line that varialbel "opp" does not exists //What am I missing and will this work for bulk updates? update opp; } }

 

I’m trying to update fields on the OpportunityLineItem record from fields on Product2.  Am I supposed to be using a multidimensional map to accomplish this task?  If so,  can someone get me started?  If not, can you get me on the right path?  See code below.

trigger oppLineItem_prod_data_trigger2 on OpportunityLineItem (before insert, before update) { Set<String> opportunityLineItemIDs = new Set<String>(); //We create a list for all opportunityLineItem records we will ultimately update to //enable us to perfoirm a single bulk update List<OpportunityLineItem> updtOpportunityLineItems = new List<OpportunityLineItem>(); //We loop through the updated records to get the Id, and add it to the set for(OpportunityLineItem oli : trigger.new) { if(!opportunityLineItemIDs.contains(oli.Id)) { opportunityLineItemIDs.add(oli.Id); } //This is our holding list for opportunityLineItem and the associated Product2 attributes OpportunityLineItem[] opportunityLineItems = new List<OpportunityLineItem>(); //We can now add the product2 attributes to the opportunityLineItems list created right above opportunityLineItems = [SELECT pricebookentry.product2.sbu_abbr__c, pricebookentry.product2.bu_abbr__c FROM OpportunityLineItem ]; //Old code //[Select Id, product2.sbu_abbr__c, product2.bu_abbr__c //From PricebookEntry //where id in '01u30000000M4EcAAK']; Map<Id, OpportunityLineItem []> oliProdAttributes = new Map<Id, OpportunityLineItem[]>(); //Old code //Place the data from the query into the map // Now use the map to set the appropriate attribute on every OpportunityLineItem processed by the trigger. //for (OpportunityLineItem oli : Trigger.new){ // oli.bu_abbr__c = entries.get(oli.pricebookEntryId).product2.bu_abbr__c; // oli.sbu_abbr__c = entries.get(oli.pricebookEntryId).product2.sbu_abbr__c; } for (OpportunityLineItem o :opportunityLineItems) { oliProdAttributes.put(o.Id, o.sbu_abbr__c, o.bu_abbr__c); } //Once we have updated the opportunityLineItem based on the data in Product2, we add it to //the opportunityLineItems list we created at the beginning updtOpportunityLineItems.add(oli); } //Once the account for loop has finished, we execute once single update of OpportunityLineItem update updtOpportunityLineItems; }

 

I get the following error:

 

Error: Compile Error: Variable does not exist: oli.sbu_abbr__c at line 21 column 7 

 

When I try to save the trigger code below. 

trigger oppLineItem_prod_data_trigger on OpportunityLineItem (before insert, before update) { Set<Id> pbeIds = new Set<Id>(); for (OpportunityLineItem oli : Trigger.new) pbeIds.add(oli.pricebookentryid); Map<Id, PricebookEntry> entries = new Map<Id, PricebookEntry>( [Select product2.sbu_abbr__c, product2.bu_abbr__c From PricebookEntry where id in :pbeIds]); . for (OpportunityLineItem oli : Trigger.new) oli.bu_abbr__c = entries.get(oli.pricebookEntryId).product2.bu_abbr__c; oli.sbu_abbr__c = entries.get(oli.pricebookEntryId).product2.sbu_abbr__c; }

 

Can someone tell me what I'm doing wrong.

 

Thanks.

I've confirmed that when inserting a new opportunity that has a workflow field update my before update trigger fires.  Can anyone think of a way to prevent this trigger from firing?

 

Here is my trigger:

 

 

trigger opportunity_ae_required on Opportunity (before update) { Map<String, Opportunity> oppy_contact = new Map<String, Opportunity>(); for (Integer i = 0; i < Trigger.new.size(); i++) { if (Trigger.isUpdate && Trigger.new[i].ae_required__c == 1) { oppy_contact.put(Trigger.new[i].id,Trigger.new[i]); system.debug('Trigger.new[i]: ' + Trigger.isUpdate); } } map<Id, OpportunityContactRole> oppycontactroles = new map<Id, OpportunityContactRole>(); for (OpportunityContactRole ocr : [select OpportunityId, Role from OpportunityContactRole where (OpportunityContactRole.Role = 'Account Executive' and OpportunityContactRole.OpportunityId in :oppy_contact.keySet())]) { oppycontactroles.put(ocr.OpportunityId,ocr); } for (Opportunity oppy : system.trigger.new) { system.debug('trigger.isUpdate: ' + Trigger.isUpdate); if (Trigger.isUpdate) { if (oppycontactroles.containsKey(oppy.id) || oppy.ae_required__c == 0) { // Do nothing } else { oppy.addError('Cannot make changes to this Opportunity until an Account Executive has been Selected in the Contact Roles section.'); } } } //for }

 

When I create an Opp the before update trigger below is firing.  I have a lot of field update workflows, its that what's causing the trigger to fire on the creation of the Opp.  If so, how do I prevent this trigger from firing?

 

//This trigger display error if no Account Executive is specified on Contact Role
trigger opportunity_ae_required on Opportunity (before update) {

    Map<String, Opportunity> oppy_contact = new Map<String, Opportunity>();

        if (Trigger.isUpdate && Trigger.new[i].ae_required__c == 1)
                {
                oppy_contact.put(Trigger.new[i].id,Trigger.new[i]);
                //system.debug('This is the trigger.new.id - '+Trigger.new[i].id);
                system.debug('Trigger.new[i]: ' + Trigger.isUpdate);
        }
    }

    map<Id, OpportunityContactRole> oppycontactroles = new map<Id, OpportunityContactRole>();

    for (OpportunityContactRole ocr : [select OpportunityId, Role from OpportunityContactRole
                                       where (OpportunityContactRole.Role = 'Account Executive'
                                       and OpportunityContactRole.OpportunityId in :oppy_contact.keySet())]) {

        oppycontactroles.put(ocr.OpportunityId,ocr);
    }

    for (Opportunity oppy : system.trigger.new) {
        //system.debug('List oppy Id - '+oppy.id);
        system.debug('trigger.isUpdate: ' + Trigger.isUpdate);
        if (Trigger.isUpdate) {
            if  (oppycontactroles.containsKey(oppy.id) || oppy.ae_required__c == 0 || 1==1)
                {
                // Do nothing
                } 
            else
                {
                    //oppy.addError(Trigger.isInsert +' Cannot make changes to this Opportunity until an Account Executive has been Selected in the Contact Roles section.');          
                    oppy.addError('U:'+Trigger.isUpdate + ' I:'+Trigger.isInsert+' AE:'+oppycontactroles.containsKey(oppy.id)+' AEreq:' + oppy.ae_required__c);
                 }
         }
    } //for 
 }

I want to prevent my trigger that checks for a specific Opp contact role from firing on the creation of a new Opp because the Opp has to be created before a person is added to contact role.

 

How can this be done?

Can someone tell me how to fix the error below on my trigger:

 

Error:Apex trigger ContractChangeQuote caused an unexpected exception, contact your administrator: ContractChangeQuote: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 0QL700000000zWnGAI; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, ContractChangeQuote: maximum trigger depth exceeded Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote

trigger ContractChangeQuote on Quote (after update) {
If(Trigger.isUpdate){
     //check the opprtunites in the trigger to see if the Contract Term changed, if so add them to a Set
     Set<Id> UpdatedOppIds = new Set<Id>();
        string term;
        for(Integer i=0;i<trigger.new.size();i++){  
            if(trigger.old[i].Contract_Term__c == null){
                term = '';
            } else {
                term = trigger.old[i].Contract_Term__c;
            }    
            //if(trigger.new[i].Contract_Term__c <> trigger.old[i].Contract_Term__c){
            if(trigger.new[i].Contract_Term__c <> term) {
                UpdatedOppIds.add(Trigger.new[i].id);
            }
        }
         
        //Process any opps that have changed
        if(UpdatedOppIds.size() > 0){
            //get all of the quote Line items tied to opportunities in this trigger
            List<Quote> qliList = [select Id, Name, Contract_Term__c, (select Id, ContractTerm__c, QuoteId from QuoteLineItems) from Quote where Id IN :UpdatedOppIds];
             
            //create list to hold quote line items that need updating.
            List<QuoteLineItem> qliUpdateList = new List<QuoteLineItem>();
             
            //loop through opportunites and update all of the quote line items. add line items to update list.
            for(Quote o : qliList){
                for(QuoteLineItem qli : o.QuoteLineItems){
                    qli.ContractTerm__c = o.Contract_Term__c;
                    qliUpdateList.add(qli);
                }
            }
             
            //update the line items
            if(!qliUpdateList.isEmpty()){
                update qliUpdateList;
            }
        }
    }
}

 

trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6] Quote trigger event AfterUpdate for [0Q0700000004jf6]: []: Trigger.ContractChangeQuote: line 36, column 1

I have a field End_customerId__c on Opportunity which is a lookup to Account.  I've named the relationship End_Cust_Lookup.   I'm trying to get back a list of Opportunities where the accountnumber on the related account record is null. 

 

When I try this query:

 

Select Opp_Uid__c,end_cust_lookup__r.accountnumber From opportunity  where  end_cust_lookup__r.accountnumber = NULL AND Opp_Uid__c <> NULL

 

I get an error Unable to open Schema Browser. Malformed_Query - end_cust_lookup__r.accountnumber From opportunity where end_cust_lookup__r.accountnumber.  No viable alternative at character ''.


I also tried the following but that doesn't filter out the non null records because I guess you can't filter master records from child this way/

 

Select  (Select Opp_Uid__c From End_Cust_Lookup__r where Opp_uid__c <> NULL )  From Account a where  a.accountnumber = NULL
 

 

I'm trying to filter the result set of the following query to only return records where Opp_Uid__c is not null.

 

Select  (Select Opp_Uid__c From End_Cust_Lookup__r where stage_code_num__c < '50' )  From Account a where  a.accountnumber = NULL

 

When I add the where End_Cust_Lookup__r.Opp_uid__c <> NULL at the end of the statement above I get an error that it didn't understand relationship Ennd_Cust_Lookup__r in field path.

 

When I add Opp_uid__c <> NULL to the where clause in the subquery I get the same results set as I do without this additional where.

 

Maybe I'm going about this all wrong.  I have a lookup field end_customerID__c on the opportunity object which does a lookup to account.  I want to return a list of opportunities where the account.accountnumber is null on the end customer listed on the Opp.

 

 

Can someone tell me what I'm missing here.  In the debug log it says no records found after I update an OpportunityLineItem record:

 

Trigger.oppLineItem_prod_data_trigger2: line 20, column 33: SOQL query with 0 rows finished in 3 ms

 

trigger oppLineItem_prod_data_trigger2 on OpportunityLineItem (after insert, after update) { Set<String> opportunityLineItemIDs = new Set<String>(); List<OpportunityLineItem> updtOpportunityLineItems = new List<OpportunityLineItem>(); OpportunityLineItem[] opportunityLineItems = new List<OpportunityLineItem>(); OpportunityLineItem[] oliList = [select pricebookentry.product2.bu_code__c FROM OpportunityLineItem where id in :opportunityLineItemIDs]; for(OpportunityLineItem oli : oliList) { oli.bu_code__c = oli.pricebookentry.product2.bu_name__c; } update oliList; }

 

I've gone round and round with trying to create a trigger on a custom object opportunitywwa__c that need to set the value of opportunity.has_wwa__c to true if it is currently false.

 

Opportunitywwa__c  has a field named opportunity_name__c which is a lookup to opportunity which may or not be populated. 

 

Since there can be one or more opportunitywwa__c records mapped to a single opportunity I only need to update the Opportunity.has_wwa__c field if the value is false.

 

Here is the code that I can't get to compile:

trigger updt_Opp_Has_OR3 on OpportunityWWA__c (after insert, after update) { Set<id> oppsToUpdate = new Set<id>(); //add the opportunityID from the lookup field into the set for (OpportunityWWA__c wwa : Trigger.new){ if (wwa.opportunity_name__c <> null){ oppsToUpdate.add(wwa.opportunity_name__c); } } //get list of Opportunities that need to be updated for(Opportunity opp : [SELECT Id, (select opportunity_name__c FROM OpportunityWWA__R where id IN : oppsToUpdate and opportunity_name__c <> null) from opportunity where has_ors__c = false]) { opp.has_www__c = true; } if(opp.size() > 0){ //I get error on this line that varialbel "opp" does not exists //What am I missing and will this work for bulk updates? update opp; } }

 

When I create an Opp the before update trigger below is firing.  I have a lot of field update workflows, its that what's causing the trigger to fire on the creation of the Opp.  If so, how do I prevent this trigger from firing?

 

//This trigger display error if no Account Executive is specified on Contact Role
trigger opportunity_ae_required on Opportunity (before update) {

    Map<String, Opportunity> oppy_contact = new Map<String, Opportunity>();

        if (Trigger.isUpdate && Trigger.new[i].ae_required__c == 1)
                {
                oppy_contact.put(Trigger.new[i].id,Trigger.new[i]);
                //system.debug('This is the trigger.new.id - '+Trigger.new[i].id);
                system.debug('Trigger.new[i]: ' + Trigger.isUpdate);
        }
    }

    map<Id, OpportunityContactRole> oppycontactroles = new map<Id, OpportunityContactRole>();

    for (OpportunityContactRole ocr : [select OpportunityId, Role from OpportunityContactRole
                                       where (OpportunityContactRole.Role = 'Account Executive'
                                       and OpportunityContactRole.OpportunityId in :oppy_contact.keySet())]) {

        oppycontactroles.put(ocr.OpportunityId,ocr);
    }

    for (Opportunity oppy : system.trigger.new) {
        //system.debug('List oppy Id - '+oppy.id);
        system.debug('trigger.isUpdate: ' + Trigger.isUpdate);
        if (Trigger.isUpdate) {
            if  (oppycontactroles.containsKey(oppy.id) || oppy.ae_required__c == 0 || 1==1)
                {
                // Do nothing
                } 
            else
                {
                    //oppy.addError(Trigger.isInsert +' Cannot make changes to this Opportunity until an Account Executive has been Selected in the Contact Roles section.');          
                    oppy.addError('U:'+Trigger.isUpdate + ' I:'+Trigger.isInsert+' AE:'+oppycontactroles.containsKey(oppy.id)+' AEreq:' + oppy.ae_required__c);
                 }
         }
    } //for 
 }