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
NLTNLT 

When clicking on the delete button should throw the exception message to users except for the system admin with verbiage 'Not to delete the opportunity product'.

When clicking on the standard delete button for opportunity product as shown in below screenshot should throw the exception message to users except for the system admin with verbiage 'Not to delete the opportunity product'. Please provide apex logic for it.

User-added image
AnkaiahAnkaiah (Salesforce Developers) 
Hi,

try with below trigger.
trigger StopDelete on OpportunityLineItem (before delete) 
{
    String profileName=[SELECT id,Name FROM Profile WHERE Id =:UserInfo.getProfileId()].Name ;  
    for (OpportunityLineItem a : Trigger.old)
    {      
        If(profileName!='System Administrator')
        {
            a.addError('You cannot delete this record!');
        }
    }
    
}

If this helps, Please mark it as best answer.

Thanks!!​​​​​​​