You need to sign in to do that
Don't have an account?
Ramanjot Sidhu
Locking Stage Field on Opportunity
On my opportunity page, I have a child object called Sponsorship Offer. When a Sponsorship offer is related to an opportunity, I want to prevent the Stage field from being change on the Opportunity page, but be controlled via a custom stage field on the custom object. Is this even possible through a trigger?
Vivek, on this developer forum, assissted me and wrote this trigger:
trigger UpdateStage on Opportunity (before update) {
List<Line_item__c> opportunitywithsponsorshipoffer = [SELECT Opportunity__r.id, Opportunity__r.StageName
from Line_item__c where Line_item__c.Opportunity__c IN :Trigger.NewMap.keyset()];
if( opportunitywithsponsorshipoffer !=null && !opportunitywithsponsorshipoffer.isEmpty())
{
for(Line_item__c liRecord : opportunitywithsponsorshipoffer)
{
if(Trigger.newMap.get(liRecord.Opportunity__r.id)!=null && Trigger.newMap.get(liRecord.Opportunity__r.id).StageName != liRecord.Opportunity__r.StageName )
{
Trigger.newMap.get(liRecord.Opportunity__r.id).adderror('Cannot track Stage on Opportunity page, please refer to the related Sponsorship Offer page');
}
}
}
}
which works perfectly fine, but I still want to be able to edit the opportunity stage field, from the related sponsorship offer field. I cannot due this, as this trigger locks the field completed once a sponsorship offer is added.