There are two Objects with master-detail relationship (Contact and Certification__c)
I need to copy a textfield(Name) value from the child object(Certification__c) and paste it on it's Parent's(Contact) textfield(Certification_Token), for every contact which has a certification instance. Please note that this is for existing record values.
code:
List<Certification__c> CertificationObjects = new List<Certification__c>();
CertificationObjects = [SELECT Name, Contact__r.Id, Contact__r.Certification_Token__c FROM Certification__c];
for(Certification__c c : CertificationObjects){
if(c.Contact__r.Certification_Token__c == NULL){
c.Contact__r.Certification_Token__c = c.Name;
}
}
update CertificationObjects;
When I run this on the Execute Anonymous Window, it shows no error, but it is not updating it's parent. Should i map the fields using the Id and update it or can we fix this code? I do not require a workflow, as I need to update the existing values in the system, and not the future ones.
@UPDATE not every contact instance will have a certification instance. A contact can have multiple certification instances, but all the certification instances of a particular contact can have only one .Name