+ Start a Discussion
Lavanya Ponniah 3Lavanya Ponniah 3 

How to copy custom fields from one object to another object?

I am using professional edition.So,I want to know whenever i choose account name in lookup field in contact object the related custom fields in accounts have to copied to the contact custom fields using custom button.
Devendra Hirulkar 3Devendra Hirulkar 3
for this u need trigger  that copy your  object filed  from one to another
the trigger like that


trigger CopyRolltoStudent1 on class__c (before insert,before update) //You want it on update too, right?
{
  Map<ID, Student__c> parentroll = new Map<ID, Student__c>(); //Making it a map instead of list for easier lookup
  List<Id> listIds = new List<Id>();

  for (class__c childObj : Trigger.new)
  {
    listIds.add(childObj.student__c);
  }

  //Populate the map. Also make sure you select the field you want to update, Rollno
  //The child relationship is more likely called Classes__r (not Class__r) but check
  //You only need to select the child classes a if you are going to do something for example checking whether the Classes in the trigger is the latest
  parentroll = new Map<Id, Student__c>([SELECT id, Roll_No__c,(SELECT ID, Roll_No__c FROM Class__r) FROM Student__c WHERE ID IN :listIds]);

  for (class__c cl : Trigger.new)
  {
     Student__c myParentroll = parentroll.get(cl.student__c);
     myParentroll.Roll_No__c = Decimal.valueOf(cl.Roll_No__c);
  }
    
  update parentroll.values();
}
Lavanya Ponniah 3Lavanya Ponniah 3
For professional edition we can not use trigger.