Skip to main content
 static testMethod void testsetLeadSourceforPartnerGeneratedLeads(){

    

        Id RecordTypeIdLeadDirect = Schema.SObjectType.Lead.getRecordTypeInfosByName().get('Direct').getRecordTypeId();

        List<Lead> leadCreateList = new List<Lead>();

        List<LeadShare> leadShareList = new List<LeadShare>();

        Test.startTest();

        Lead testLead = CreateLead('John' + System.now().Format('hms'), 'Doe' + System.now().Format('hms'), '', 'Comity1 Designs', 'United States');

        leadCreateList.add(testLead);

        

        Lead testLead2 = CreateLead('John' + System.now().Format('hms'), 'Doe' + System.now().Format('hms'), '', 'Comity1 Designs', 'United States');

        testLead2.email = 'testemailduplicate@partner.com';

        testLead2.RecordTypeId = RecordTypeIdLeadDirect;

        testLead2.Status = '1-New'; 

        leadCreateList.add(testLead2);

        

        Lead testLead3 = CreateLead('John' + System.now().Format('hms'), 'Doe' + System.now().Format('hms'), '', 'Comity1 Designs');

        testLead3.Country = 'United States';

        testLead3.State = 'GA'; 

        leadCreateList.add(testLead3);

        

        insert leadCreateList;

        

        User partnerUser = [Select id from User where email = 'puser000@testlead.com'];

        

        LeadShare ldShare = new LeadShare(LeadId = testLead.Id, LeadAccessLevel = 'Edit', UserOrGroupId = partnerUser.Id);

        leadShareList.add(ldShare);

        

        LeadShare ldShare2 = new LeadShare(LeadId = testLead3.Id, LeadAccessLevel = 'Edit', UserOrGroupId = partnerUser.Id);

        leadShareList.add(ldShare2);

        

        insert leadShareList;

        

        System.runAs(partnerUser){

            Lead newLeadRec = CreateLead('John' + System.now().Format('hms'), 'Doe' + System.now().Format('hms'), '', 'Comity1 Designs');

            newLeadRec.Country = 'United States';

            newLeadRec.State = 'GA';

            newLeadRec.LeadSource = 'Partner';

            newLeadRec.Lead_Source_Most_Recent_Picklist__c = 'Test Value';

            insert newLeadRec;

            

            Lead updateLead2 = [Select id, email from Lead where id =: testLead3.Id];

            updateLead2.email = 'testemailduplicate@partner.com';

            updateLead2.Lead_Source_Most_Recent_Picklist__c = 'Test Value';

            try{

                LeadTriggerControl.executeBeforeUpdate = true;

                update updateLead2;

            }

            catch(Exception excep){

                Boolean expectedExceptionThrown =  excep.getMessage().contains('Please submit your Leads to DocuSign as') ? true : false;

                //System.AssertEquals(expectedExceptionThrown, true, excep);

            }

        }

        Test.stopTest();

    }

    
1 respuesta
  1. 30 ene 2023, 19:20

    To resolve the issue, update the Lead record with the correct value for the "Status" field before attempting to insert it. For example:

     

    Lead newLeadRec = CreateLead('John' + System.now().Format('hms'), 'Doe' + System.now().Format('hms'), '', 'Comity1 Designs');

    newLeadRec.Country = 'United States';

    newLeadRec.State = 'GA';

    newLeadRec.LeadSource = 'Partner';

    newLeadRec.Lead_Source_Most_Recent_Picklist__c = 'Test Value';

    newLeadRec.Status = '1-New';

    insert newLeadRec;

     
0/9000