Skip to main content
2 of 2
Code formatting; added Apex & Code Coverage tags

How can I cover this contact owner assignment in test class after lead convert?

I have written a trigger helper method that converts to contact and associates the contact with an existing account. The contact owner becomes the owner of the account as shown in this snippet

Now I dont know how to cover this assignment: c.OwnerId = c.Account.OwnerId;

I am getting the error :

Error occured while converting the Lead to a Contact in convertLeadToContact methodSObject row was retrieved via SOQL without querying the requested field: Contact.Account

Any ideas?

Thanks

// contains the list of created contacts after conversion
contList =  [select Id, OwnerId from Contact where Id IN :cidList]; 
            
//update contact owner with related account owner
if(cidList.size() > 0){
    for(Contact c : contList){
          c.OwnerId = c.Account.OwnerId;
    }
    update contList;
}
Pauline
  • 395
  • 5
  • 16