• StevekBlueSnap
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 17
    Replies

I am receiving the following:

Error Number: 1566295115-16221 (-1072421861) related to a workflow not able to perform a pending action. Does anyone know what this references?

I have a trigger code deployed that upon a set parameter, it will automatically convert a Lead to an Account with an Opportunity. What type of additional line of code would I need to add to enable these converted records be attached to existing Accounts rather than simply creating a net new record?

I have tried simplistically to swap Lead everywhere I see Opportunity or opp. This method does not work. What would I have to edit to establish the activity counter on Leads?

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
trigger TaskUpdateOpportunity on Task (after delete, after insert, after undelete, after update) {

    Set<ID> oppIds = new Set<ID>();
    //We only care about tasks linked to opportunities.
    String prefix =  OpportunityActivityCount.oppPrefix;

    //Add any opportunity ids coming from the new data
    if (Trigger.new != null) {
        for (Task t : Trigger.new) {
            if (t.WhatId != null && String.valueOf(t.whatId).startsWith(prefix) ) {
                oppIds.add(t.whatId);
            }
        }
    }

    //Also add any opportunity ids coming from the old data (deletes, moving an activity from one opportunity to another)
    if (Trigger.old != null) {
        for (Task t : Trigger.old) {
            if (t.WhatId != null && String.valueOf(t.whatId).startsWith(prefix) ) {
                oppIds.add(t.whatId);
            }
        }
    }

    if (oppIds.size() > 0)
        OpportunityActivityCount.updateOpportunityCounts(oppIds);

}

 

public with sharing class OpportunityActivityCount {

    public static Boolean didRun = false;
    public static String oppPrefix =  Opportunity.sObjectType.getDescribe().getKeyPrefix();

    /*
    * Takes a set of opportunity IDs, queries those opportunities, and updates the activity count if appropriate
    */
    public static void updateOpportunityCounts(Set<ID> oppIds) {

        if (didRun == false) { //We only want this operation to run once per transaction.
            didRun = true;

            //Query all the opportunites, including the tasks child relationships
            List<Opportunity> opps = [SELECT ID, activity_count__c, (SELECT ID FROM Tasks), (SELECT ID FROM Events) FROM Opportunity WHERE ID IN :oppIds];
            List<Opportunity> updateOpps = new List<Opportunity>();

            for (Opportunity o : opps) {
                Integer count = o.tasks.size() + o.events.size();

                if (o.activity_count__c != count) {
                    o.activity_count__c = count;
                    updateOpps.add(o); //we're only doing updates to opps that have changed...no need to modify the others
                }
            }

            //Update the appropriate opportunities
            try {
                update updateOpps;
            } catch (Exception e) {
                //This is controversial. Anything could happen when updating the opportunity..validation rule, security, etc. The key is we don't
                //want the event update to fail...so we put a try catch around the opp update to make sure we don't stop that from happening.
            }
        }
    }

    /*
    * Test method for this class and TaskUpdateOpportunity and EventUpdateOpportunity
    */
    public static testMethod void testCountTask() {
        //Setup
        Account a = new Account(name='Test');
        insert a;

        Opportunity opp = new Opportunity(accountId = a.id, name='Test Opp', StageName='New', CloseDate=System.today());
        insert opp;

        //Insert our first task
        Task t = new Task(subject='Test Activity', whatId = opp.id);
        insert t;

        //Verify count
        opp = [SELECT ID, activity_count__c FROM Opportunity WHERE ID = :opp.id];
        System.assertEquals(1,opp.activity_count__c);

        //Disconnect task from the opportunity
        didRun = false; //Reset
        t.whatId = null;
        update t;
        //Verify count = 0
        opp = [SELECT ID, activity_count__c FROM Opportunity WHERE ID = :opp.id];
        System.assertEquals(0,opp.activity_count__c);

        didRun = false; //Reset
        //Add an event
        Event e = new Event(subject='Test Event', whatId = opp.id, startDateTime = System.Now(), endDateTime = System.now());
        insert e;

        //Verify count = 1
        opp = [SELECT ID, activity_count__c FROM Opportunity WHERE ID = :opp.id];
        System.assertEquals(1,opp.activity_count__c);

        //Relink the task to the opportunity
        didRun = false; //Reset
        t.whatId = opp.id;
        update t;

        //Verify count = 2
        opp = [SELECT ID, activity_count__c FROM Opportunity WHERE ID = :opp.id];
        System.assertEquals(2,opp.activity_count__c);

        //Disconnect the event from the opportunity
        didRun = false; //Reset
        e.whatId = null;
        update e;

        //Verify count is back down to 1
        opp = [SELECT ID, activity_count__c FROM Opportunity WHERE ID = :opp.id];
        System.assertEquals(1,opp.activity_count__c);

        //Delete the task
        didRun = false; //reset
        delete t;
        //Verify count is back down to 0
        opp = [SELECT ID, activity_count__c FROM Opportunity WHERE ID = :opp.id];
        System.assertEquals(0,opp.activity_count__c);

    }

I have the following trigger deployed with the reference test class:

 

 

trigger LeadConvert on Lead (after insert,after update) {
//Bulkified
List<String> LeadNames = new List<String>{};
for(Lead myLead: Trigger.new){
 if((myLead.isconverted==false) && (myLead.Status == 'Confirmed')) {
Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(myLead.Id);
        lc.convertedStatus = 'Confirmed';
        //Database.ConvertLead(lc,true);
        lc.setDoNotCreateOpportunity(false);
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        }
        }
}

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

// Test Class for LeadConvert trigger

public class testLeadConvert {

    static testMethod void leadConvertTest() {
        // Create test data
        List<Lead> leadList = new List<Lead>();
        
        // Insert Leads
        for(integer i=0; i<10; i++){
            Lead l1 = new Lead(Company = 'Test Account#' +i , LastName= 'Test Lead LastName' +i, Status ='Confirmed');
            leadList.add(l1);
        }
        
        Profile p1 = [select Id from profile where name = 'Standard User'];
        User u = new User( Alias = 'standasf', 
                           Email='standarduser@testorg.com',
                           EmailEncodingKey='UTF-8',
                           LastName='Testing',
                           LanguageLocaleKey='en_US',
                           LocaleSidKey='en_US',
                           ProfileId = p1.Id,
                           TimeZoneSidKey='America/Los_Angeles',
                           UserName='stadfasdfsdfndarduser@testorg.com'
        );
        
        System.runAs(u){
            Test.startTest();
            Database.Insert(leadList);
            Test.stopTest();
        }
        //Assertion Testing
        leadList = [select Id, IsConverted, ConvertedAccountId, ConvertedContactId from Lead where Id IN :leadList];
        
        for(integer i=0;i<leadList.size();i++){
            System.assertEquals(leadList[i].IsConverted, true , 'Values not equal');
            System.assert(leadList[i].ConvertedAccountId <> null );
            System.assert(leadList[i].ConvertedContactId <> null );
        }
    }
}

 

 

 

Unfortunately I tried to Upsert from the Data Loader (over 9000 records) and got this error:

 

 Developer script exception from BlueSnap : LeadConvert : LeadConvert: execution of AfterUpdate  caused by: System.DmlException: ConvertLead failed. First exception on row 0; first error: LIMIT_EXCEEDED, System.LimitException: SFSSDupeCatcher:Too many S...

 

Apex script unhandled trigger exception by user/organization: 00570000001K82v/00D700000008Rkb

 

LeadConvert: execution of AfterUpdate

 

caused by: System.DmlException: ConvertLead failed. First exception on row 0; first error: LIMIT_EXCEEDED, System.LimitException: SFSSDupeCatcher:Too many SOQL queries: 101: []

 

Trigger.LeadConvert: line 11, column 1

 

What am I missing or do I need to change "after insert" or "after update"

 

The populated fields from the upsert have nothing to do with the Lead Status and therefore I'm not sure what is causing the error

I have a trigger code deployed that upon a set parameter, it will automatically convert a Lead to an Account with an Opportunity. What type of additional line of code would I need to add to enable these converted records be attached to existing Accounts rather than simply creating a net new record?

I have tried simplistically to swap Lead everywhere I see Opportunity or opp. This method does not work. What would I have to edit to establish the activity counter on Leads?

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
trigger TaskUpdateOpportunity on Task (after delete, after insert, after undelete, after update) {

    Set<ID> oppIds = new Set<ID>();
    //We only care about tasks linked to opportunities.
    String prefix =  OpportunityActivityCount.oppPrefix;

    //Add any opportunity ids coming from the new data
    if (Trigger.new != null) {
        for (Task t : Trigger.new) {
            if (t.WhatId != null && String.valueOf(t.whatId).startsWith(prefix) ) {
                oppIds.add(t.whatId);
            }
        }
    }

    //Also add any opportunity ids coming from the old data (deletes, moving an activity from one opportunity to another)
    if (Trigger.old != null) {
        for (Task t : Trigger.old) {
            if (t.WhatId != null && String.valueOf(t.whatId).startsWith(prefix) ) {
                oppIds.add(t.whatId);
            }
        }
    }

    if (oppIds.size() > 0)
        OpportunityActivityCount.updateOpportunityCounts(oppIds);

}

 

public with sharing class OpportunityActivityCount {

    public static Boolean didRun = false;
    public static String oppPrefix =  Opportunity.sObjectType.getDescribe().getKeyPrefix();

    /*
    * Takes a set of opportunity IDs, queries those opportunities, and updates the activity count if appropriate
    */
    public static void updateOpportunityCounts(Set<ID> oppIds) {

        if (didRun == false) { //We only want this operation to run once per transaction.
            didRun = true;

            //Query all the opportunites, including the tasks child relationships
            List<Opportunity> opps = [SELECT ID, activity_count__c, (SELECT ID FROM Tasks), (SELECT ID FROM Events) FROM Opportunity WHERE ID IN :oppIds];
            List<Opportunity> updateOpps = new List<Opportunity>();

            for (Opportunity o : opps) {
                Integer count = o.tasks.size() + o.events.size();

                if (o.activity_count__c != count) {
                    o.activity_count__c = count;
                    updateOpps.add(o); //we're only doing updates to opps that have changed...no need to modify the others
                }
            }

            //Update the appropriate opportunities
            try {
                update updateOpps;
            } catch (Exception e) {
                //This is controversial. Anything could happen when updating the opportunity..validation rule, security, etc. The key is we don't
                //want the event update to fail...so we put a try catch around the opp update to make sure we don't stop that from happening.
            }
        }
    }

    /*
    * Test method for this class and TaskUpdateOpportunity and EventUpdateOpportunity
    */
    public static testMethod void testCountTask() {
        //Setup
        Account a = new Account(name='Test');
        insert a;

        Opportunity opp = new Opportunity(accountId = a.id, name='Test Opp', StageName='New', CloseDate=System.today());
        insert opp;

        //Insert our first task
        Task t = new Task(subject='Test Activity', whatId = opp.id);
        insert t;

        //Verify count
        opp = [SELECT ID, activity_count__c FROM Opportunity WHERE ID = :opp.id];
        System.assertEquals(1,opp.activity_count__c);

        //Disconnect task from the opportunity
        didRun = false; //Reset
        t.whatId = null;
        update t;
        //Verify count = 0
        opp = [SELECT ID, activity_count__c FROM Opportunity WHERE ID = :opp.id];
        System.assertEquals(0,opp.activity_count__c);

        didRun = false; //Reset
        //Add an event
        Event e = new Event(subject='Test Event', whatId = opp.id, startDateTime = System.Now(), endDateTime = System.now());
        insert e;

        //Verify count = 1
        opp = [SELECT ID, activity_count__c FROM Opportunity WHERE ID = :opp.id];
        System.assertEquals(1,opp.activity_count__c);

        //Relink the task to the opportunity
        didRun = false; //Reset
        t.whatId = opp.id;
        update t;

        //Verify count = 2
        opp = [SELECT ID, activity_count__c FROM Opportunity WHERE ID = :opp.id];
        System.assertEquals(2,opp.activity_count__c);

        //Disconnect the event from the opportunity
        didRun = false; //Reset
        e.whatId = null;
        update e;

        //Verify count is back down to 1
        opp = [SELECT ID, activity_count__c FROM Opportunity WHERE ID = :opp.id];
        System.assertEquals(1,opp.activity_count__c);

        //Delete the task
        didRun = false; //reset
        delete t;
        //Verify count is back down to 0
        opp = [SELECT ID, activity_count__c FROM Opportunity WHERE ID = :opp.id];
        System.assertEquals(0,opp.activity_count__c);

    }

I have the following trigger deployed with the reference test class:

 

 

trigger LeadConvert on Lead (after insert,after update) {
//Bulkified
List<String> LeadNames = new List<String>{};
for(Lead myLead: Trigger.new){
 if((myLead.isconverted==false) && (myLead.Status == 'Confirmed')) {
Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(myLead.Id);
        lc.convertedStatus = 'Confirmed';
        //Database.ConvertLead(lc,true);
        lc.setDoNotCreateOpportunity(false);
        Database.LeadConvertResult lcr = Database.convertLead(lc);
        }
        }
}

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

// Test Class for LeadConvert trigger

public class testLeadConvert {

    static testMethod void leadConvertTest() {
        // Create test data
        List<Lead> leadList = new List<Lead>();
        
        // Insert Leads
        for(integer i=0; i<10; i++){
            Lead l1 = new Lead(Company = 'Test Account#' +i , LastName= 'Test Lead LastName' +i, Status ='Confirmed');
            leadList.add(l1);
        }
        
        Profile p1 = [select Id from profile where name = 'Standard User'];
        User u = new User( Alias = 'standasf', 
                           Email='standarduser@testorg.com',
                           EmailEncodingKey='UTF-8',
                           LastName='Testing',
                           LanguageLocaleKey='en_US',
                           LocaleSidKey='en_US',
                           ProfileId = p1.Id,
                           TimeZoneSidKey='America/Los_Angeles',
                           UserName='stadfasdfsdfndarduser@testorg.com'
        );
        
        System.runAs(u){
            Test.startTest();
            Database.Insert(leadList);
            Test.stopTest();
        }
        //Assertion Testing
        leadList = [select Id, IsConverted, ConvertedAccountId, ConvertedContactId from Lead where Id IN :leadList];
        
        for(integer i=0;i<leadList.size();i++){
            System.assertEquals(leadList[i].IsConverted, true , 'Values not equal');
            System.assert(leadList[i].ConvertedAccountId <> null );
            System.assert(leadList[i].ConvertedContactId <> null );
        }
    }
}

 

 

 

Unfortunately I tried to Upsert from the Data Loader (over 9000 records) and got this error:

 

 Developer script exception from BlueSnap : LeadConvert : LeadConvert: execution of AfterUpdate  caused by: System.DmlException: ConvertLead failed. First exception on row 0; first error: LIMIT_EXCEEDED, System.LimitException: SFSSDupeCatcher:Too many S...

 

Apex script unhandled trigger exception by user/organization: 00570000001K82v/00D700000008Rkb

 

LeadConvert: execution of AfterUpdate

 

caused by: System.DmlException: ConvertLead failed. First exception on row 0; first error: LIMIT_EXCEEDED, System.LimitException: SFSSDupeCatcher:Too many SOQL queries: 101: []

 

Trigger.LeadConvert: line 11, column 1

 

What am I missing or do I need to change "after insert" or "after update"

 

The populated fields from the upsert have nothing to do with the Lead Status and therefore I'm not sure what is causing the error