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
prasanth kumarprasanth kumar 

custom setting trigger firing for all users.

i want to run this code only for system admin. But it is firing for all users. 


 
trigger acc_customSetting on Account (before insert) {

    adminonly__c a1=adminonly__c.getInstance(userinfo.getuserid());
    if(a1.valid__c)
    {
    for(account a2:trigger.new)
    {
        a2.description=a2.name+' this is custom setting data';
    }
    }
}

 
Carlos Campillo GallegoCarlos Campillo Gallego
Hi Prasanth,

Assuming you have already created the custom settings records and that this custom setting is of hierarchy type, it should be something like this:
trigger acc_customSetting on Account (before insert) {

	adminonly__c a1 = adminonly__c.getInstance(SysAdminID);
	Boolean sysAdm = a1.valid__c;
	if(sysAdm){
		for(account a2:trigger.new){
			a2.description=a2.name+' this is custom setting data';
		}
	}
}

As you can see it is almost as you had it. Give it a try and let me know if it worked, but check before what I told before, hierarchy custom setting type and custom setting records existing for that profile.

Regards