You need to sign in to do that
Don't have an account?
Shirin
Need help for triger on updating
H, I have written a code to insert records in a custom object from opportunitylineitemschedule. Can anybody help me write the update trigger for the same. My code is as seen below:
trigger RevenueForecastInsert on OpportunityLineItem (After Insert) {
For (OpportunityLineItem OppLi : Trigger.New)
{
list <OpportunityLineItemSchedule> schedule = [select Id, ScheduleDate,Revenue from
OpportunityLineItemSchedule where
OpportunityLineItemId = :OppLi.Id ];
For( Integer i=0; i< (schedule.size()) ;i++)
{
Forecast__c F = New Forecast__c (Amount__c = schedule[i].Revenue,
Record_Id_BE__c = schedule[i].Id,
Date__c = schedule[i].ScheduleDate,
Status__c = 'Pipeline',
Forecast_Owner__c = OppLi.Opportunity_Owner_Id__c,
Business_Unit_Head__c = OppLi.Business_Unit_Head_Id__c,
Business_Unit__c = OppLi.Resource_Business_Unit__c,
Opportunity_Type__c = 'T&M',
Related_Opportunity__c = OppLi.Opportunity_IdNumber__c);
Insert F;
}
}
}
Add after update event to trigger and use the below code.
The code for insert as well as update is not bulkified and will not address if many records fire at a time.
Hi,
Try this code.
If a reply to a post answers your question or resolves your problem, please mark it as the solution to the post so that others may benefit.
Thanks I will try this and respond back. If the insert & update is not a bulkified code how do we managein case many records are updated/ inserted at a time
Chamil: I am getting the following error, can you help?
"Apex trigger ForecastInsertTest caused an unexpected exception, contact your administrator: ForecastInsertTest: execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.ForecastInsertTest: line 7, column 18".
Its always best practice to use a List while querying the object.
The query issued has returned no records to assign to Forecast object.
Try this
Forecast[] f = [query];
//then check
if(f.size() > 0)
{
// do the process here
}
Hi Imran, I am getting this error message. can you help me on this?
Error: Compile Error: Initial term of field expression must be a concrete SObject: MAP<Id,OpportunityLineItemSchedule> at line 33 column 16
I am writing the code as follows for updating the record in the custom object Forecast.
I am getting an error as: "Apex trigger ForecastInsertTest caused an unexpected exception, contact your administrator: ForecastInsertTest: execution of AfterUpdate caused by: System.QueryException: List has no rows for assignment to SObject: Trigger.ForecastInsertTest: line 7, column 18".
I am unable to understand how to resolve this please help
Thanks Imran this actually helped me write the code and it works fine now.
thanks for the help