+ Start a Discussion
KMK91KMK91 

Formula field from Parent to child

Hi All,

How to Pull fields from a "Parent" object into a "Child" object.


Thanks
KMK
KMK91KMK91
How to Pull fields from a "Parent" object into a "Child" object.
Based on condition i need to execute 
AnkaiahAnkaiah (Salesforce Developers) 
Hi,

Can you explain about your requirement.?
Refer the below screenshot, i am referring Account object fields from contact.

User-added image

Custom object formula reference:
Customobject__r.Name


Standard object formula reference:
 
Account.Name

If this helps, Please mark it as best answer.

Thanks!!
 
KMK91KMK91
Hi Ankaiah,

I need create a formla field from Parent object to Child object.

how to write formula field in child object ?

Thanks
KMK
AnkaiahAnkaiah (Salesforce Developers) 
If you want to update parent field value in child object then refer the below formula.
Parent__r.FiendName__C

If my understanding is wrong, then explain about your extact requirement.

Thanks!!
 
KMK91KMK91
Hi  Ankaiah ,

Apologies, My question is wrong,

 I need to create a formla field from Child object to Parent object.

how to write formula field in Parent object ? if Yes, i created formula in Child object. I want same field value in parent object.

Thanks
KMK
 
AnkaiahAnkaiah (Salesforce Developers) 
Hi,

Its not possible through formula field. you need to write a trigger.

try with below trigger. Modify the fields & object API names as per your org.
Trigger FieldupdateOnParent on Child__c(after insert,after update){


Map<id,string> chidvaluesmap  = new map<id,string>();

for(Child__c ch:trigger.new){

Child__c oldch = trigger.oldmap.get(ch.id);

if(ch.formulafield__c !=Null && (ch.formulafield__c != oldch.formulafield__c) && ch.parent__c!=Null ){

chidvaluesmap.put(ch.parent__c,ch.formulafield__c);

}
}

List<Parent__c> parentupdate = new List<parent__c>();

for(Parent__c p: [select id,Field__c from pder where id=:chidvaluesmap.Keyset()]){
if(chidvaluesmap.containkey(p.id)){
p.Field__c = chidvaluesmap.get(p.id);
parentupdate.add(p);
}

}

Update parentupdate;


}

If this helps, Please mark it as best answer.

Thanks!!

 
KMK91KMK91
Thank you Ankaiah .