+ Start a Discussion
SamuSamu 

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.

 

 

Thanks

Samu

sfdcfoxsfdcfox

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 : trigger.new ) {
    if( l.isconverted && !systemflags.convertleadokay ) {
      l.adderror('You cannot manually convert leads.');
    }
  }
  lead[] converts = new lead[0];
  for( lead l : trigger.new ) {
    if( leads.shouldconvert( l ) ) {
      converts.add( l );
      systemflags.convertleadokay = true;
    }
  }
  // Convert the leads here.
}