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
Anu Singh 40Anu Singh 40 

How to copy one custom object field in another custom object field dynamically

Hi All

I need to know How to copy one custom object field in another custom object field dynamically in lighntning?
Like we do whenever we match the field  by Map to lead button in lead object if we want to map custom field. If we want opportunity Account and Contact data is saved in  back to lead then how can we do this dynamically?
If a custom field is created on Account  so we have to create a cutom field on lead. then how can we match the field by code.

 
CharuDuttCharuDutt
Hii Anu Singh

There Must Be Relationship Between Two Objects Like Master Detail Relationship Or Lookup Relationship
Example:
Showing Account's PhoneIn Contact 
Account = ParentObject 
Contact = ChildObject

Make Formula Field On Contact Object Data Type (Text)

Formula:   Account.Phone 

Or 

Trigger
trigger Sample on Account(before update) {
     String Phone;
     list<Contact> lstUpdateCon = new list<Contact>();
     set<Id> lstId = new set<id>();
    if(trigger.IsBefore &&.IsUpdate){
        for(Account acc:trigger.new){
           Phone=acc.Phone;
        }
    }
    list<Contact> lstCon = [select Id,Name,Account,Phone From Contact Where AccountId IN :lstId];
    for(Contact Con2:lstCon){
     Con2.Phone = Phone;
     lstUpdateCon.Add(Con2);
     }
      update lstUpdateCon ;
      

}
Please Mark It As Best Answer If It Helps
Thank You!



 
Dinesh ParvathalaDinesh Parvathala
Thank you for your info