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
affuaffu 

auto update

Hi,

 

I want to write a trigger to update a field in one object called schedules

 

scenario is:

 

i have no.of schedules related to opportunity and i have two fields in schedules named test1 and test2

lets say 

schedule record 1 - test1(field) value is 10 then the test2(field) should update as 10

schedule record 2 - test1(field) value is 20 then the test2(field) should update as 30

schedule record 3 - test1(field) value is 30 then the test2(field) should update as 60

 

So the test2 field should update as test2 from the previous record and add it to current record

 

 

thanks in advance

Saikishore Reddy AengareddySaikishore Reddy Aengareddy

In your trigger on schedules object query all the records related to that particular opportunity...sum them up and add it to current record.

 

psuedocode

 

trigger on Schedules(before insert){

 

//get the sum of the previous schedule records on test1 (check the syntaxes from docs)

AggregateResult[] aggsum = [SELECT sum(test1) s FROM schedules__c where Opportunity__c = opportunity on the current record];
sumtotal = aggsum[0].get('s');

 

current record test2 = current record test1 + sumtotal;

 

}

affuaffu

Hi sam ,

thanks for replying but i didnt get what is current record