You need to sign in to do that
Don't have an account?
Jean-Luc
Use an Opportunity trigger to sync the value of the Stage with the value of a custom picklist
Hello
In the Opportunity object, I created three record types and two custom fields:
- a picklist "Opportunity Sub-type" controlling
- a picklist "Funnel Stages" with in fact exactly the same values as the picklist standard field "StageName"
The purpose is to limit in the different record types the stages to use for each Opportunity Sub-Type.
As the field StageName is mandatory on Opportunity and not possible to define field dependencies with, I created a trigger to sync the StageName value when the same one is selected in the "Funnel_Stages__c" picklist.
------------
trigger UpdateSource on Opportunity (after update)
{
List<Opportunity> opportunitiesToUpdate = new List<Opportunity>();
for(Opportunity currOpportunity : trigger.new)
{
currOpportunity.StageName= currOpportunity.Funnel_Stages__c;
leadsToUpdate.add(currOpportunity);
}
update opportunitiesToUpdate;
}
--------------------
Not error when compiled but well when activated as I had thefollowing error message on the Opportunity page:
-------------------
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger UpdateSource caused an unexpected exception, contact your administrator: UpdateSource: execution of AfterUpdate caused by: System.FinalException: Record is read-only: Trigger.UpdateSource: line 6, column 1
-----------------
Can somebody help me?
Thanks already.
Best regards
Jean-Luc
In the Opportunity object, I created three record types and two custom fields:
- a picklist "Opportunity Sub-type" controlling
- a picklist "Funnel Stages" with in fact exactly the same values as the picklist standard field "StageName"
The purpose is to limit in the different record types the stages to use for each Opportunity Sub-Type.
As the field StageName is mandatory on Opportunity and not possible to define field dependencies with, I created a trigger to sync the StageName value when the same one is selected in the "Funnel_Stages__c" picklist.
------------
trigger UpdateSource on Opportunity (after update)
{
List<Opportunity> opportunitiesToUpdate = new List<Opportunity>();
for(Opportunity currOpportunity : trigger.new)
{
currOpportunity.StageName= currOpportunity.Funnel_Stages__c;
leadsToUpdate.add(currOpportunity);
}
update opportunitiesToUpdate;
}
--------------------
Not error when compiled but well when activated as I had thefollowing error message on the Opportunity page:
-------------------
Error: Invalid Data.
Review all error messages below to correct your data.
Apex trigger UpdateSource caused an unexpected exception, contact your administrator: UpdateSource: execution of AfterUpdate caused by: System.FinalException: Record is read-only: Trigger.UpdateSource: line 6, column 1
-----------------
Can somebody help me?
Thanks already.
Best regards
Jean-Luc
Thank you very much for the solution.
Fully working.
Best regards
Jean-Luc
All Answers
If you realy want to use trigger please find below code :
trigger UpdateSource on Opportunity (before update)
{
for(Opportunity currOpportunity : trigger.new)
{
currOpportunity.StageName= currOpportunity.Funnel_Stages__c;
}
}
Thank you very much for the solution.
Fully working.
Best regards
Jean-Luc
I added (before insert,before update) but it's not working.
Thanks already