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
revanth adminrevanth admin 

AfterUpdate Trigger Has to UpDate the RecoredField With another object RecordField Value


(MY trigger Has to UpDate the RecoredField - Batch_Email__C  ''Data Type is--Email For this Field''}   the update date must come from the Batch Record .

Note;   ((Hear ==="Student =parenet" and "Payment=child" and Batch is 'Parent' to Child="Student")) .

now the Batch_Email__c Field on paymetn Has to Update With the Email in The Batch Record...?


trigger PaymentToBatch on Payment__c (after update)
{
Payment__c paynew=trigger.new[0];

payment__c pay=[select id,Batch_Email__c,student__r.Batch__r.Group_Mail_ID__c From Payment__c
                                             where id=:paynew.id];

              system.debug('---pay----'+pay);
            system.debug('---payToBatch----'+pay.student__r.Batch__r.Group_Mail_ID__c);
            system.debug('---pay.Batch Name----'+pay.Batch_Email__c);

                                                   
      pay.Batch_Email__c=pay.student__r.Batch__r.Group_Mail_ID__c;
   
      system.debug('---payTOBatch.After----'+pay.Batch_Email__c);             

}

Result:

In My Developer Console the out put  is Shown But my ''Batch_Email__c' 'Field on Payment Is Not Showing the OutPut value.

Best Answer chosen by revanth admin
Shashikant SharmaShashikant Sharma
YOu need to make 2 changes :

1. Change the trigger event to before update instead of after update
2. Change this statement to use paynew.Batch_Email__c

pay.Batch_Email__c=pay.student__r.Batch__r.Group_Mail_ID__c

to 

paynew.Batch_Email__c=pay.student__r.Batch__r.Group_Mail_ID__c

Above two change should work for you.

Your trigger is not supported for bulk handling, you need to bulkify it.


All Answers

Shashikant SharmaShashikant Sharma
YOu need to make 2 changes :

1. Change the trigger event to before update instead of after update
2. Change this statement to use paynew.Batch_Email__c

pay.Batch_Email__c=pay.student__r.Batch__r.Group_Mail_ID__c

to 

paynew.Batch_Email__c=pay.student__r.Batch__r.Group_Mail_ID__c

Above two change should work for you.

Your trigger is not supported for bulk handling, you need to bulkify it.


This was selected as the best answer
revanth adminrevanth admin
  Hi    Shashikant Sharma


Thanks For ur Answers its working .....


But  I need to Do the same logic in  " After Update".