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
Robert Wambold 10Robert Wambold 10 

Trigger to update a Closed Opportunity with Validation Rule

Hello All,

Hope everyone is safe and healthy.

I have a field on the Opportunity object called NetworkPath__c which composed of Account and Opportunity fields.

When the Opportunity is created or updated or the Account is updated NetworkPath__c may need to be updated. All is good except when the Opportunity Stage is "Closed" where a Validation Rule (VR) presents the User with an error message "You cannot update a Closed Opportunity". This by design.

I need a way to allow the user to update Opportunity NetworkPath__c when certain Opportunity or Account fields are changed. I don't want allow the User update to complete Opportunity, only the fields that compose NetworkPath__c.

I am thinking a pagelayout limited to the fields that compose NetworkPath__c, but how do I get past the VR that presents the User with the error message.

How about this idea...add a field to the User Profile that grants certain individuals the ability to update the fields that compose NetworkPath__c, then modify the VR to check User Profile for new field.

Doe's this make any sense? Or is there a better way to do this? I am open to all ideas.

Thanks for reading my caffine driven rant.

Cheers!

Robert

MoonpieMoonpie
Hi Robert,

I'm new to a lot of this, but I just spent literally a few days digging into the best way to bypass triggers on Object B when a specific trigger on Object A had code that updated Object B.  I know that is not your use case here, but in my "interwebs" searches I came across and sifted through a lot of similar use cases.

All that to say - especially since no one has yet to reply to your post - that what you have proposed seems logical and plausible to my newbie self.  I would say that if you can try what you proposed in a scratch org or or sandbox, to go for it and see.

At least until someone more experienced than I chimes in.

Please let us know whether it is successful!
SUCHARITA MONDALSUCHARITA MONDAL
Hi Robert,

You can bypass this validation rule for Certain Users. You can create Custom Permission and add that Custom Permission to Users for which you want to bypass the validation rule. 

Check the links below:
https://www.j2interactive.com/blog/bypassing-salesforce-validation-rule/
https://unhandledsunshine.com/2018/12/06/use-custom-permissions-to-bypass-validation-rules-and-pass-unit-tests/

Thanks,
Sucharita