function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PARISE RAVIKIRANPARISE RAVIKIRAN 

system.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Please submit your Leads to DocuSign as "1-New": [Status] Class.LeadTriggerUtilityTest_Clone.testsetLeadSource

 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();
    }
    
Shri RajShri Raj


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;