Utility Class:-
public class Utility{ private static Map<String, Id> profileIdByName = new Map<String, Id>(); public static Id getProfileIdByName(String profileName) { if (!String.isBlank(profileName)) { if (profileIdByName.containsKey(profileName)) { return profileIdByName.get(profileName); } else{ for(Profile pfInstance:[SELECT Name,Id FROM profile
WHERE Name='System Admin'
OR Name='Read Only'
OR Name='Marketing User']){ profileIdByName.put(pfInstance.Name,pfInstance.Id); } return profileIdByName.get(profileName); } } return Null; } }
Fetching Profile Id Using Profile Name by Map :-
if(ProfileId == Utility.getProfileIdByName('Marketing User')){ //Your Logic }
No comments:
Post a Comment