By default user have create permission on profile level??
try with below code. Replace
trigger checkpermissionset on Account (before insert) {
id userid = UserInfo.getUserid();
PermissionSetAssignment assignid =[ SELECT AssigneeId FROM PermissionSetAssignment WHERE PermissionSet.Name = 'Create_Account'];
for(account acc :trigger.new){
if(assignid.AssigneeId != userid){
acc.adderror(' Logged user is not assigned to "Create Account" on Permissionsetassignment');
}
}
}
trigger checkpermissionset on Account (before insert) {
RestrictAccountCreationHelper.RestrictUser(Trigger.New);
}
######################################################################
public class RestrictAccountCreationHelper{
public static Void RestrictUser(list<Account>newAccount){
id userid = UserInfo.getUserid();
list<PermissionSetAssignment> assignedPermissionSet =[ SELECT Id FROM PermissionSetAssignment WHERE AssigneeId = :Userinfo.getUserId() AND PermissionSet.Name = 'Create_Account'];
for(account acc :newAccount){
if(assignedPermissionSet.IsEmpty()){
acc.adderror(' Logged user is not assigned to "Create Account" on Permissionsetassignment');
}
}
}
}
Please Mark It As Best Asnwer If It Helps Thank You!
By default user have create permission on profile level??
try with below code. Replace
Thanks!
Try Below Code Please Mark It As Best Asnwer If It Helps
Thank You!