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
Naresh ChandaNaresh Chanda 

How to add validation to prevent users from adding/editing/removing lines from quotes

How can we add logic to prevent users from adding, editing, or removing lines on Quotes in Salesforce. We are integrated with third party application for quoting needs and all the changes should occur from third party application and will be pushed from there to the SF Quote via an integration user. What is a non-invasive way to accomplish this. Thanks.
Lucas Duque 9Lucas Duque 9
Hello Naresh.

You can create a trigger in object QuoteLineItem to prevent this actions.

Like this:
trigger TriggerQuoteLineItem on QuoteLineItem (before insert, before update, before delete) {
       if(Trigger.isInsert || Trigger.isUpdate){
             for(QuoteLineItem  qli :{
                 qli.addError('You cannot add or update a record for this object.');
       }else if (Trigger.isDelete){
            for(QuoteLineItem qli : Trigger.old){
                qli.addError('You cannot delete this record.');
That's it.

I personally recommend that you have an apex class to handle the trigger context and logic, because it's consider a bad practice to write the code on the trigger.

I hope this help you.

Have a nice day.
Naresh ChandaNaresh Chanda
Thank you Lucas. But won't the trigger gets invoked when the integration user pushes the line items from the backend? I think it will and block the integration user too. A way to fix is check the running user and then allow it for the integration user and show the error for all the other users. Thought there will be a point and click way to accomplish this!