You need to sign in to do that
Don't have an account?
rani
Trigger on Opportunity
Hi All,
I want to create a trigger on Opportunity which would update a field on Opportunity depending on values from Events associated with that Opportunity. Event has a date field and the maximum of that field should be updated to one of the Opportunities field when the Opportunity is updated and meets the criteria.
Regards,
Rani
Hi Rani,
Although that might change in the new release of Salesforce (scheduled for Feb) there is currently no way to use aggregate functions in SOQL to my knowledge (such as SELECT MAX(Date) FROM...) .
A workaround I have used in the past is do a select ordering desc on the specific field and using the "LIMIT 1" clause. This way you will easily get the MAX value.
Hope it helps. Regards,
J
Hey J,
Thanks for the prompt response and solution, but in the trigger i would loop the opportunity object so again including SOQL in the for loop to retrieve the Event record as you mentioned would throw an error due to limitation of SOQL in loops. Do you have any other alternatives?
Appreciate your help.
Regards,
Rani
Hi Rani,
Why are you looping through opportunities do you need to evaluate other Opps as well?
Maybe you can post part of the code?
J
J, to handle bulk updates we need to loop thru the opportunites. For example the code of trigger would look as follows:
trigger OpportunityTrigger on Opportunity (before update)
{
for (Opportunity O: trigger.new)
{
....
......
}
}
I need some clear description,possile post full code