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
fredkafredka 

Getting Name of Parent From Child before update trigger

I have a parent child relationship... on the before update of the child record, I wasn to write the name of the child to include the parent name... here is what I have but the parent name portion is shown as null

 

for (Health_Enrollment_Product_Detail__c HEPD: Trigger.new){
     //Set the name of the health_enrollment_product_detail object
     HEPD.name = HEPD.Health_Enrollment_Summary__r.name + ' ' + HEPD.Product__c + ' ' + HEPD.Funding_Type__c;
          }

 Thanks!!

AishAish

trigger parentName on Child__c (before insert, before update)
{
    for (Child__c child: Trigger.new)
    {
        if(Trigger.isInsert)
        {
                Account a = Database.query('select name from Account where id=\''+ child.parent__c + '\'');
                child.parent_s_name__c = a.name;
        }
    }
}

AishAish

I created a master-detail (parent child) between "Account" standard and "Child" custom object fo rthe above example to work.

fredkafredka

Thanks for responding Aish!!!