Thursday 6 June 2013

How to fetch Standard Profiles from SOQL

Hi friends today I am going to share one small trick. 
Recently I met with a problem where I need to fetch only standard profiles in SOQL. I went to force.com developer board and some other discussion forums and finally found the work around.

As we all know that there is no such attribute on profile to determine whether it is standard or custom so we can use a concept here that "standard profile gets created along with organization by Salesforce only" so it's created Date time would be same as organization.


Datetime OrgCreatedDateTime = [Select id , createdDate from Orgaization ][0].CreatedDate ;



Now we would like to query profile with same createdDate time.

List<profile> StandardProfiles = new List<profile>();
StandardProfiles = [select id,Name from Profile where createdDate = :OrgCreatedDateTime];

So "StandardProfiles"  is list of all standard profile of our org this is just a work around because I am still worried if a new standard profile gets enabled on demand after creating Org.
Please share your views ahead.

No comments:

Post a Comment