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.QueryException: List has no rows for assignment to SObject Class.LeadTriggerUtilityTest.testsetLeadSourceforPartnerGeneratedLeads: line 1639, column 1

 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);
        
        List<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();
    }
    
Santiago CurettiSantiago Curetti

Hi Parise,

You have 2 SOQL query with no limit and if the query do not find any object to the related query it will failed. Also if the query return more than one object it will throw list has more than 1 row for assignment to SObject.

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

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

I suggest that change the query to:

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

And if the updateLead2 <> null loop trough the records to modidy what you want/