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

How to restrict view and edit permissiom for a record through trigger

Hi EveryBody,


I  am converting the qualified lead to oppertunity  through trigger.So i need to restrict  user to view and edit  the qualified lead

If it possible through trigger please help me.






You'll need a static variable to track if the conversion is happening through a trigger:


public class systemflags {
  public static boolean convertleadokay;

  static {
    convertleadokay = false;

Next, set your trigger to block the event if it's not from your custom code:


trigger leadconvert on lead ( after update ) {
  for( lead l : ) {
    if( l.isconverted && !systemflags.convertleadokay ) {
      l.adderror('You cannot manually convert leads.');
  lead[] converts = new lead[0];
  for( lead l : ) {
    if( leads.shouldconvert( l ) ) {
      converts.add( l );
      systemflags.convertleadokay = true;
  // Convert the leads here.