Skip to main content
Code formatting; added Apex & Code Coverage tags
Source Link

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;: 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

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

contList = [select Id, OwnerId from Contact where Id IN :cidList];// contains the list of created contacts after conversion

        //update contact owner with related account owner
   contains the list of created if(cidList.size()contacts >after 0){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;
            }

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

contList = [select Id, OwnerId from Contact where Id IN :cidList];// contains the list of created contacts after conversion

        //update contact owner with related account owner
        if(cidList.size() > 0){
                       
            for(Contact c : contList){
                  c.OwnerId = c.Account.OwnerId;
                        
             }
            
            update contList;
            }

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;
}
Source Link
Pauline
  • 395
  • 5
  • 16

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

contList = [select Id, OwnerId from Contact where Id IN :cidList];// contains the list of created contacts after conversion

        //update contact owner with related account owner
        if(cidList.size() > 0){
                       
            for(Contact c : contList){
                  c.OwnerId = c.Account.OwnerId;
                        
             }
            
            update contList;
            }