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
jpbenjpben 

Update Child Records

 

Hi All,

 

I have the following trigger that adds Revenue Schedule records on the Opportunity when the Opportunity is created.  I would like to update those records when the Opportunity Stage is changed to Closed Won.  I would like the Projected_Accrual_Date__c field on the Revenue Schedule records to be updated in case the Closed Date on the Opportunity is changed.  How can i accomplish this?  

 

Thanks in advance. 

 

 

 

 

trigger RevenueScheduleForecast on Opportunity (after insert) {


//When Onmark Oppty is created, a list of Revenue Schedule Records will be
//inserted into the Opportunity record.

List <Revenue_Schedule__c> RSToInsert = new List <Revenue_Schedule__c> ();

for (Opportunity oppty : Trigger.new) {

if(
(oppty.RecordTypeId == '012A0000000eLsf' ) ||
(oppty.RecordTypeId == '012A0000000eLsk' )
)

{


//Revenue Schedule 1//
Revenue_Schedule__c RS1 = new Revenue_Schedule__c ();
RS1.RecordTypeId = '012K0000000Cz7o';
RS1.Name = 'Month 1';
RS1.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS1.Projected_Accrual_Date__c = oppty.CloseDate;
RS1.Opportunity__c = oppty.Id;

//Revenue Schedule 2//
Revenue_Schedule__c RS2 = new Revenue_Schedule__c ();
RS2.RecordTypeId = '012K0000000Cz7o';
RS2.Name = 'Month 2';
RS2.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS2.Projected_Accrual_Date__c = oppty.CloseDate.adddays(30);
RS2.Opportunity__c = oppty.Id;

//Revenue Schedule 3//
Revenue_Schedule__c RS3 = new Revenue_Schedule__c ();
RS3.RecordTypeId = '012K0000000Cz7o';
RS3.Name = 'Month 3';
RS3.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS3.Projected_Accrual_Date__c = oppty.CloseDate.adddays(60);
RS3.Opportunity__c = oppty.Id;

//Revenue Schedule 4//
Revenue_Schedule__c RS4 = new Revenue_Schedule__c ();
RS4.RecordTypeId = '012K0000000Cz7o';
RS4.Name = 'Month 4';
RS4.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS4.Projected_Accrual_Date__c = oppty.CloseDate.adddays(90);
RS4.Opportunity__c = oppty.Id;

//Revenue Schedule 5//
Revenue_Schedule__c RS5 = new Revenue_Schedule__c ();
RS5.RecordTypeId = '012K0000000Cz7o';
RS5.Name = 'Month 5';
RS5.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS5.Projected_Accrual_Date__c = oppty.CloseDate.adddays(120);
RS5.Opportunity__c = oppty.Id;

//Revenue Schedule 6//
Revenue_Schedule__c RS6 = new Revenue_Schedule__c ();
RS6.RecordTypeId = '012K0000000Cz7o';
RS6.Name = 'Month 6';
RS6.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS6.Projected_Accrual_Date__c = oppty.CloseDate.adddays(150);
RS6.Opportunity__c = oppty.Id;

//Revenue Schedule 7//
Revenue_Schedule__c RS7 = new Revenue_Schedule__c ();
RS7.RecordTypeId = '012K0000000Cz7o';
RS7.Name = 'Month 7';
RS7.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS7.Projected_Accrual_Date__c = oppty.CloseDate.adddays(180);
RS7.Opportunity__c = oppty.Id;

//Revenue Schedule 8//
Revenue_Schedule__c RS8 = new Revenue_Schedule__c ();
RS8.RecordTypeId = '012K0000000Cz7o';
RS8.Name = 'Month 8';
RS8.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS8.Projected_Accrual_Date__c = oppty.CloseDate.adddays(210);
RS8.Opportunity__c = oppty.Id;

//Revenue Schedule 9//
Revenue_Schedule__c RS9 = new Revenue_Schedule__c ();
RS9.RecordTypeId = '012K0000000Cz7o';
RS9.Name = 'Month 9';
RS9.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS9.Projected_Accrual_Date__c = oppty.CloseDate.adddays(240);
RS9.Opportunity__c = oppty.Id;

//Revenue Schedule 10//
Revenue_Schedule__c RS10 = new Revenue_Schedule__c ();
RS10.RecordTypeId = '012K0000000Cz7o';
RS10.Name = 'Month 10';
RS10.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS10.Projected_Accrual_Date__c = oppty.CloseDate.adddays(270);
RS10.Opportunity__c = oppty.Id;

//Revenue Schedule 11//
Revenue_Schedule__c RS11 = new Revenue_Schedule__c ();
RS11.RecordTypeId = '012K0000000Cz7o';
RS11.Name = 'Month 11';
RS11.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS11.Projected_Accrual_Date__c = oppty.CloseDate.adddays(300);
RS11.Opportunity__c = oppty.Id;

//Revenue Schedule 12//
Revenue_Schedule__c RS12 = new Revenue_Schedule__c ();
RS12.RecordTypeId = '012K0000000Cz7o';
RS12.Name = 'Month 12';
RS12.Amount__c = oppty.Monthly_Revenue_Schedule_Amount__c;
RS12.Projected_Accrual_Date__c = oppty.CloseDate.adddays(330);
RS12.Opportunity__c = oppty.Id;

RSToInsert.add(RS1);
RSToInsert.add(RS2);
RSToInsert.add(RS3);
RSToInsert.add(RS4);
RSToInsert.add(RS5);
RSToInsert.add(RS6);
RSToInsert.add(RS7);
RSToInsert.add(RS8);
RSToInsert.add(RS9);
RSToInsert.add(RS10);
RSToInsert.add(RS11);
RSToInsert.add(RS12);

} //end if

}//end for

try {
insert RSToInsert;
} catch (system.Dmlexception e) {
system.debug (e);
}


}

bujjibujji
If i am not wrong your saying Update, but if seems you are inserting.Please check in the try block.

Thanks,
Bujji