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
Valerie GValerie G 

Locking Opportunity Products

Hi there!

 

I am trying to find out if it is possible to restrict modifications / accidental deletions of Opportunity Products after a specific custom field is updated to "True".  Basically, I want to ensure that the Sales & Account Management teams can no longer modifiy a product once a specific field is updated in an Opportunity Product.  All updates need to be limited to the specific roles/Profiles (such as Accounting team, System Administrators).

 

Is this possible? 

Pradeep_NavatarPradeep_Navatar

In my opinion, it is workable. You need to create a trigger on opportunity product and that will restrict the users to accidently delete or modify the record when certain criteria is met.

 

Hope this helps.

Valerie GValerie G

I tried the triggers, but could not create a new trigger or find a trigger to modify.  I found the following in the Help & Training section:

 

Sometimes, a customer might ask why they can not see the NEW button in Apex Code trigger section in Live Production.

To create an Apex class in live Production instance is not supported.

Only Developer Edition, Sandbox, and Trial organizations have the ability to create, edit, and delete Apex classes and triggers directly in the Salesforce CRM user interface.

Unlimited Edition and Enterprise Edition production organizations can execute Apex and can view Apex in the user interface, but modifying Apex in the user interface is not allowed.


The Apex classes and triggers should first be written in a Developer Edition, Sandbox, or Trial organization along with the appropriate test methods with at least 75% of test coverage.

 

To activate the Trigger Function in live production environment, you will need to use either the Salesforce ANT Tool or Apex Toolkit for Eclipse to deploy.

 

The New button also does not appear in Apex Class, not just triggers.

 

We are working in the Enterprise Edition.

gpedronigpedroni

any luck on this, I'm just looking to remove the delete link (already removed the delete button), but your idea sounds interesting also.

Valerie GValerie G

Oh yes!  Sorry about that.  I did figure this out and have a solution.  Thanks for the follow up.

IzelIzel

What solution did you come up with? I would love to know this, as im trying to block, deleting of products.

Valerie GValerie G
I found the solution in the Help & Training section under “How do I lock the Opportunity Products using Validation Rules once the Opportunity State is Closed? I added 2 Roll-Up Summary Fields to the Opportunity Details page: 1. Number of Products 2. Number of Invoice Schedules Then I set up Validation Rules: 1. To prevent create & edit to Opportunity Line Items on Closed Opportunities Create a Validation Rule on Opportunity Product Formula: OR(ISPICKVAL(Opportunity.StageName, "Closed Won"), ISPICKVAL(Opportunity.StageName, "Closed Lost")) 2. To prevent deletes to Opportunity Line Items on Closed Opportunities Create a Validation Rule on Opportunity Formula: AND(OR(ISPICKVAL(StageName, "Closed Won"), ISPICKVAL(StageName, "Closed Lost")), Number_of_Line_Items__c < PRIORVALUE(Number_of_Line_Items__c) ) Assumes that you have a custom Roll-Up Summary Field on Opportunity object called Number of Line Items, that Counts the number of Opportunity Product records associated to an Opportunity. Finally, I changed User Profiles so non-administrators cannot “Delete” Opportunities. I hope this helps.