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
K_devK_dev 

Trigger on custom object as an error when createdBY!=Userinfo.getuserID

HI

 

Iam looking to add an error when customerNote__c object records is edited only when createdBy= UserInfo.getuserId

 

 

 

 
K_devK_dev

CAn you correct it

 

trigger updateInvalid on CustomerNote__c (before update) {

for (CustomerNote__c opp: trigger.new){
System.debug('User:::::'+ UserInfo.getUserId());
if (Opp.CreatedById != UserInfo.getUserId()) {

opp.adderror('Insufficient Access to edit this Note');
}
}
}

john4sfdcjohn4sfdc

Try the below code

 

 

trigger updateInvalid on CustomerNote__c (before update) {

for (CustomerNote__c opp: trigger.new){
System.debug('User:::::'+ UserInfo.getUserId());
if (Opp.CreatedById != UserInfo.getUserId()) {

trigger.new[0].adderror('Insufficient Access to edit this Note');
}
}
}

Vinit_KumarVinit_Kumar

What is the error you are getting,I see your code is fine and it works fine for me ..

 

K_devK_dev

Does it works for Bulk updates?

Vinit_KumarVinit_Kumar

Yes,

 

It will work for bulk updates too.