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
AsshAssh 

Assigning contact name

Hi All,

 

I have a custom object of text type.This custom object has a lookup relationship with "contact" standard object.  I want to assign contact name to the custom object name in the Apex class.

When I save the custom object[customer object] after I enter other required fields, then the record is saving with random name like "a0650000007xpaD". How can I assign contact name to the customer object name? Could anyone please help me with this? Your help is greatly appreciated.

I have written following statement in the code:

 

 

 

 customer.name = customer.Contact__c;
     controller.save();
Best Answer chosen by Admin (Salesforce Developers) 
bob_buzzardbob_buzzard

Assuming Contact__c is a lookup relationship, this is expected as you are copying the ID of the contact into the customer.name field.

 

To copy the contact name you would need:

 

 

customer.name = customer.Contact__r.Name;

 

 

All Answers

bob_buzzardbob_buzzard

Assuming Contact__c is a lookup relationship, this is expected as you are copying the ID of the contact into the customer.name field.

 

To copy the contact name you would need:

 

 

customer.name = customer.Contact__r.Name;

 

 

This was selected as the best answer
AsshAssh

Hi,

 

Thak you for your suggestion, and I implemented as you mentioned. It is working fine.