• montez
  • NEWBIE
  • 25 Points
  • Member since 2008
  • Sales Operations Manager
  • Urban Airship


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 1
    Likes Given
  • 3
    Questions
  • 3
    Replies
I have this class I am using to assign leads via process builder. When the class tries to run in bulk, I get the following error:
Error Occurred: An Apex error occurred: System.QueryException: List has more than 1 row for assignment to SObject​

Any thoughts on how to resolve this error?
Here is the class I an using to assign leads:
public class AssignLeadsUsingAssignmentRules
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
            Database.DMLOptions dmo = new Database.DMLOptions();
            dmo.assignmentRuleHeader.useDefaultRule= true;          
            Lead Leads=[select id from lead where lead.id in :LeadIds];
            Leads.setOptions(dmo);
            update Leads;
   }
}

 
  • April 04, 2016
  • Like
  • 0
I need a trigger that pulls all the unique values from Email Domain (custom field) and populates the field Domain Mapping (managed package custom field) separated by a single space and only unique values.

Example:
Account XYZ has three contacts.
Contact 1 has a Email Domain of XYZ.com
Contact 2 has an Email Domain of ABC.com
Contact 3 has an Email Domain of XYZ.com
Accounts Domain Mapping field should be “XYZ.com ABC.com”

Object - Field - API Name
Account - Domain Mapping - Zendesk__Domain_Mapping__c
Contact - Email Domain - Email_Domain__c

Can you help?
  • December 07, 2015
  • Like
  • 0
When a lead is updated and the owner is X and the Matched Status is Enriched, run the default lead assignment rule. My code is below, but when it runs I get the error below. It looks like it is looping the updating over and over.

Can you tell me where I am going wrong?

Code:

trigger AssignLeadAfterClean on Lead(after update) {
    Database.DMLOptions dmo = new Database.DMLOptions();
    dmo.assignmentRuleHeader.useDefaultRule= true;
    
    // Get the related leads in this trigger.        
    List<Lead> relatedLeads = [SELECT ID,OwnerID,ivm__MatchedStatus__c FROM Lead
                               WHERE Id IN :Trigger.New];
    
    List<Lead> leadsToUpdate = new List<Lead>();
    
    // Iterate over the related leads
    for(Lead lead_n1 :relatedLeads) {      
        // Run the Lead Assignement Rule when the owner is 005C0000006pm5r and clean process has completed
        if ((lead_n1.OwnerID == '005C0000006pm5r') && (lead_n1.ivm__MatchedStatus__c == 'Enriched')) {
            lead_n1.setOptions(dmo);
            leadsToUpdate.add(lead_n1);
        }
    }
    
    // Perform DML on a collection
    update leadsToUpdate;
}


Error:

Error:Apex trigger AssignLeadAfterClean caused an unexpected exception, contact your administrator: AssignLeadAfterClean: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 00QM0000006fq8JMAQ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AssignLeadAfterClean: maximum trigger depth exceeded Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J]: []: Trigger.AssignLeadAfterClean: line 21, column 1
I have this class I am using to assign leads via process builder. When the class tries to run in bulk, I get the following error:
Error Occurred: An Apex error occurred: System.QueryException: List has more than 1 row for assignment to SObject​

Any thoughts on how to resolve this error?
Here is the class I an using to assign leads:
public class AssignLeadsUsingAssignmentRules
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
            Database.DMLOptions dmo = new Database.DMLOptions();
            dmo.assignmentRuleHeader.useDefaultRule= true;          
            Lead Leads=[select id from lead where lead.id in :LeadIds];
            Leads.setOptions(dmo);
            update Leads;
   }
}

 
  • April 04, 2016
  • Like
  • 0
I need a trigger that pulls all the unique values from Email Domain (custom field) and populates the field Domain Mapping (managed package custom field) separated by a single space and only unique values.

Example:
Account XYZ has three contacts.
Contact 1 has a Email Domain of XYZ.com
Contact 2 has an Email Domain of ABC.com
Contact 3 has an Email Domain of XYZ.com
Accounts Domain Mapping field should be “XYZ.com ABC.com”

Object - Field - API Name
Account - Domain Mapping - Zendesk__Domain_Mapping__c
Contact - Email Domain - Email_Domain__c

Can you help?
  • December 07, 2015
  • Like
  • 0
When a lead is updated and the owner is X and the Matched Status is Enriched, run the default lead assignment rule. My code is below, but when it runs I get the error below. It looks like it is looping the updating over and over.

Can you tell me where I am going wrong?

Code:

trigger AssignLeadAfterClean on Lead(after update) {
    Database.DMLOptions dmo = new Database.DMLOptions();
    dmo.assignmentRuleHeader.useDefaultRule= true;
    
    // Get the related leads in this trigger.        
    List<Lead> relatedLeads = [SELECT ID,OwnerID,ivm__MatchedStatus__c FROM Lead
                               WHERE Id IN :Trigger.New];
    
    List<Lead> leadsToUpdate = new List<Lead>();
    
    // Iterate over the related leads
    for(Lead lead_n1 :relatedLeads) {      
        // Run the Lead Assignement Rule when the owner is 005C0000006pm5r and clean process has completed
        if ((lead_n1.OwnerID == '005C0000006pm5r') && (lead_n1.ivm__MatchedStatus__c == 'Enriched')) {
            lead_n1.setOptions(dmo);
            leadsToUpdate.add(lead_n1);
        }
    }
    
    // Perform DML on a collection
    update leadsToUpdate;
}


Error:

Error:Apex trigger AssignLeadAfterClean caused an unexpected exception, contact your administrator: AssignLeadAfterClean: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 00QM0000006fq8JMAQ; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, AssignLeadAfterClean: maximum trigger depth exceeded Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J] Lead trigger event AfterUpdate for [00QM0000006fq8J]: []: Trigger.AssignLeadAfterClean: line 21, column 1

Any pointers on how to make it required to have at least one value in the competitor related list on close lost/close won of an Opportunity?  This is not available in the standard validation on the Opp since I can't get to the Competitor fields.  Any thoughts or code you have written for something similar?

  • October 16, 2012
  • Like
  • 1