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
Davi D11801Davi D11801 

How do I retrieve profileID within apex code?

Deshraj KumawatDeshraj Kumawat
You can UserInfo apex class's static method getProfileId.

Userinfo.getProfileId();

Thanks 
Deshraj Kumawat
James LoghryJames Loghry
In addition to Deshraj's statement, you can also grab a specific profile id with the following SOQL: 
Id profileId = [Select Id From Profile Where Name='Profile name goes here'];

 
Pritam ShekhawatPritam Shekhawat
hello davi,
             You can retrive ProfileId using Userinfo.getProfileId(); in apex code.
Here i show you one example
List<Profile> PROFILE = [SELECT Id, Name FROM Profile WHERE Id=:userinfo.getProfileId()];
Thanx
Pritam Shekhawat
 
Ankit Maini.Ankit Maini.
Hi,

getProfileId()Returns the context user's profile ID.Signature

public static String getProfileId()

Usage:
Id profile_id=userinfo.getProfileId();
system.debug('~~'+profile_id);
String profile_name = [select Name from Profile where id = :profile_id].Name;
System.debug('~~'+profile_name);

Thanks
Ankit Maini
(Helios Tech Services)
 
Davi D11801Davi D11801
Thank you, Ankit. This also works for me.
Ankit Maini.Ankit Maini.
@Davi

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.