-1

I need to restrict Non admin Profiles or Users from deleting the opportunityline items (lookupfield -- product) on added to the opportunity. I need to allow them to edit the opportunity for any changes unless closed Won. Since opportunitylineitems is child object it doesn't have any standard function or edit, read, create or delete function on profile level.

1
  • if you want to prevent edit, use a validation rule, if you want to prevent deletion, use a validation error in trigger. Commented Apr 2 at 9:53

2 Answers 2

2

You might need to write a validation in the trigger on BeforeDelete event , which throws an error when non Admin users try to delete. Customise the if block based on your requirements

 trigger OpportunityLineItemTrigger on OpportunityLineItem(before delete) { for (OpportunityLineItem record : Trigger.old) { if (UserInfo.getProfileName() != 'System Administrator') { Trigger.new[0].addError('You are not allowed to delete this record.'); } } } `` 
2
  1. Add a rollup summary field to Opportunity that is LineItemCount__c (define as COUNT of Opportunity Product)
  2. Then add a Validation Rule on Opportunity that (if IsWon = true) sees if current value of LineItemCount__c is < priorvalue of LineItemCount__c as this would indicate a deletion.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.