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
KCLKCL 

Need to update Custom Parent object filed name with last modified Custom child record name

I have created 2 objects REL and DEV, REL is parent and DEV is the child with master details relationship. I create the   REL1 and DEV1,DEV2 , DEV3. these 3 DEV records are under REL1. DEV 1 one filed that is last modified record name.

Here If i made any update or new record on these DEV items , that should be displayed on REL1, 
 
Nikhil Verma 6Nikhil Verma 6
Hi Vijay,
Since REL and DEV are related via Master-detail relationship, you can use a Workflow Rule + Field Update on the child (DEV) object to update the required field on the parent (REL) object.

Hope this helps.
KCLKCL
Hi Nikhi,
can we write trigger for this one .
Nikhil Verma 6Nikhil Verma 6
Yes Vijay, you can always go for a trigger approach. Write the trigger on DEV on after update event to fetch the parent object and update its field. But why write code when you can get this done via OOB functionality.
KCLKCL
Nikil I am unable to do do that from workflow, can i get the trogger for this
Nikhil Verma 6Nikhil Verma 6
Vijay, below is the sample code to achieve this (you may make field/object name adjustments):
trigger updateParentName on DEV__c (after insert, after update){
    Set<Id> setParentIds = new Set<Id>();
    Map<Id, String> mapParentId_ChildName = new Map<Id, String>();
    List<REL__c> listParentUpdate = new List<REL__c>();
    for(DEV__c varD : trigger.new){
        setParentIds.add(varD.Parent__c);
        mapParentId_ChildName.put(varD.Parent__c, varD.Name);
    }

    for(REL__c varR : [SELECT Id, Name FROM REL__c WHERE Id IN : setParentIds]){
        if(mapParentId_ChildName.containsKey(varR.Id)){
            varR.Name = mapParentId_ChildName.get(varR.Id);
            listParentUpdate.add(varR);
        }
    }
    
    if(listParentUpdate.size() > 0)
        update listParentUpdate;
}

Hope this helps.
Nikhil Verma 6Nikhil Verma 6
Vijay, which field do you want to update? on which object? with what value? and what is the master-detail relationship field API name?
I think what you are trying to do and what I understood is different. Provide some details so I can help.