You need to sign in to do that
Don't have an account?
Exclude some profiles from method in Apex Class
Hello everyone, I have a question connected with exclusion of some profiles from method in Apex Class.
I have a method in CaseManagment class, which prevent closure of Case when case have email drafts. But, for some purposes this function have to work for all profiles except "Sales Manager" , "Sales Backoffice" profiles. How can i exclude this profiles from function?
Id StandardRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByDeveloperName().get('Case_Standard').getRecordTypeId();
Map<String,Boolean> emailMessageMap = new Map<String,Boolean>();
List<Case> closedCasesList = new List<Case>();
for(Case c : newMap.values()){
if(c.RecordTypeId == StandardRecordTypeId){
if (c.Status != oldMap.get(c.Id).Status && c.Status == 'Closed'){
closedCasesList.add(c);
}
}
}
List<EmailMessage> emailMessageList = [SELECT ID,Status,RelatedToId FROM EmailMessage WHERE RelatedToId IN:closedCasesList AND Status='5'];
System.debug(emailMessageList.size());
for(EmailMessage em : emailMessageList){
emailMessageMap.put(em.RelatedToId,true);
}
for(Case c : closedCasesList){
if (emailMessageMap.get(c.Id)!=null){
c.addError('Email Draft exist');
}
}
}
I have a method that identify current user profile, but how it use in this case?
Id currentProfile=userinfo.getProfileId();
Profile profileName=[Select Name from Profile where Id=:currentProfile];
System.debug(profileName.Name);
Thanks in advance!
Basically, get the Ids for those profiles that are not allowed to edit the record.
Then do a list.contains()
you could probably do something similar with SELECTing a Map and then do a map.containsKey();
regards
Andrew