In my trigger I would need to make a condition according to the user profile as well as a custom permission set , and here is my code which does not deploy due to "Unexpected token" error .

trigger BeforeInsertCu on Strick__c (before insert) {

    Id currentUser = UserInfo.getUserId();
    Id currentUserProfileId = userinfo.getProfileId();
    String profileName = [SELECT Id, Name FROM Profile WHERE Id = :currentUserProfileId].Name ;

    String permission =[SELECT DeveloperName   FROM CustomPermission  ]
        for( Strick__c ap : trigger.new) 
            if (
                profileName =='Egypt' ||
                permission == 'PermissionEgypt'


            if(ap.Status__c == 'End' ) 
                ap.Status__c.addError('The status can t be end in the creation');

  • @Ghingis Even If I tried what you say and I add the ; and also change the type I get this error : ` Illegal assignment from String to Profile (7:13)` Commented Apr 5, 2022 at 15:20

2 Answers 2


The issue is, that you are missing a ; at the end of the line starting with String permission. But there are more issues with your code like, that line won't return a String, but a CustomPermission, same with the previous line..


You'd want to use FeatureManagement to detect your custom permission:

String profileName = [SELECT Name FROM Profile WHERE Id = :UserInfo.getProfileId()].Name;
Boolean hasEgyptPermission = FeatureManagement.checkPermission('PermissionEgypt');
for(Strick__c record: Trigger.new) {
  if( profileName == 'Egypt' && hasEgyptPermission && record.Status__c == 'End') {
    record.Status__c.addError('Cannot be "End" during record creation.');

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .