+ Start a Discussion
pabramspabrams 

how to list profiles to disable/enable triggers for profiles like in a custom configuration page

how to list profiles to disable/enable triggers for profiles like in a custom configuration page
Best Answer chosen by pabrams
chanchal_:)chanchal_:)
Hello, Try this one - 
 
Id profileId = UserInfo.getProfileId();
        Profile profileObj = [Select Id, Name from Profile where Id =: profileId];
 if(profileObj.Name == 'Standard User') {
//your code
}

 

All Answers

Gangadhar T 15Gangadhar T 15
Hi pabrams,

          I hope that  the below link is useful to you.
                     https://help.salesforce.com/articleView?id=users_profiles_apex_access.htm&type=5 (https://help.salesforce.com/articleView?id=users_profiles_apex_access.htm&type=5).




Thank You,
   www.nubeselite.com (http:// www.nubeselite.com)
   Development | Training | Consulting

             Please mark this as solution if your problem is solved.                
         
Danish HodaDanish Hoda
Hi there,
You can create a custom field with two fields - ProfileName (type Text) and isDisabled type checkbox). 
Then create records with Profile name and isDisabled an use these custom setting in trigger like:
custom_sett__c csObj = new custom_sett__c.getValues('System administrator);
pabramspabrams
Danish ,

right now i'm having disableTrigger created under API custom setting.
and using this on lead trigger :

   boolean disableTrigger=APIConfig__c.getOrgDefaults().mkto_si__Enable_Trigger__c;
              if (!disableTrigger){
                 System.debug('Executing Trigger');
}


how do i create records for profile names?.
im looking for listing this profiles in custom setting to choose profiles where and all they need to disable.


 
chanchal_:)chanchal_:)
Hello, Try this one - 
 
Id profileId = UserInfo.getProfileId();
        Profile profileObj = [Select Id, Name from Profile where Id =: profileId];
 if(profileObj.Name == 'Standard User') {
//your code
}

 
This was selected as the best answer
pabramspabrams

i dont want to hardcode StandardUser it should be from the value user selects
chanchal_:)chanchal_:)
yeah, so you can fill those values in a list, or in custom metadata and then can match the current user's profile name. 
Danish HodaDanish Hoda
Hi there,
I am presuming mkto_si__Enable_Trigger__c is your custom settings.
You can got ot Setup --> custom settings --> custom settings --> Manage records --> New --> Add values per your profile requirements.