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
ArrgHunterArrgHunter 

on insert wants to copy values from previous record

Hi guys,

I need opinion on how I can achieve the required functionality.

I have a custom object A that stores user progress details every month. When a new record is added next month I want to copy user’s previous month’s scorer to newly added record. I nut shall I want to have users previous month’s score into the current month record in custom field.

 

Am I right to think that I need before insert trigger to achieve it. But don’t know how I can save previous month’s score in the trigger temporarily and then added to new record. Any help?

 

Thanks,

ArrgHunterArrgHunter

thanks ManoharSF, have checked the link and it does make sense to me.

 

it may be i did not explained enough.

 

on a master-detail relationship i add one child record every month. when a new record is created (in the child object for a master)  i want to copy progress score from previous record that i added last month (on child object ) and add it to the new record. my child object have current score and previous score two custom fields.

 

now i can't figure out how to achieve it with after insert trigger.

 

hope it's clear this time and thanks for helping.

 

Regards,

 

Sgt_KillerSgt_Killer

You can probably try querying on the child object records in your before insert trigger and fetch the recently added record for the same master(Orderby createddate). And copy its value to the new record in its corresponding field.

ArrgHunterArrgHunter

thanks Sgt_killer, thats what i am thinking but  i can not get my head around weher to start.

 

if some can post few lines of code (template) that help me to kick start.

 

 

thanks,

ArrgHunterArrgHunter

Hi,

 

i am able to store static value on new record insert with the trigger. but i am struglling to get value from the last saved report before inserting new record. i need to insert health progress score from last month (last record order by created date)

 

trigger aprUpdate on Annual_Progress_Report__c (after insert) {


Integer SC = 0;


Annual_Progress_Report__c APR=trigger.new[0];
Annual_Progress_Report__c updRP=[select id from Annual_Progress_Report__c where id = :APR.id];
updRP.Health_assessment_progress_score2__c='32';

update updRP;
}

 

any help?

ArrgHunterArrgHunter

Hi guys,

 

sorted! can't believe it was that simple.

 

thanks everyone

 

Sarada RVS 2Sarada RVS 2
Hi , How is it sorted.Please share solution