2

Is there any way to map between Standard Profile Name to its matching metadata file name ?

I.e. 'System Administrator' should be mapped to Admin etc.

Thanks.

  • It's also worth noting that these names are different for different languages. If you do a SOQL query for a profile named "System Administrator", it will fail if the user's language is set to something other than English. – martin Jan 20 '17 at 12:03
4

Yes, there's at least three ways to map the names to their labels.

If you want just one value, you can use the Tooling API:

SELECT Name, FullName FROM Profile WHERE Name = 'System Administrator'

Output:

Name                  FullName
System Administrator  Admin

The tooling API requires at most one result when returning the FullName field, so you'd have to query all profiles by Name alone, then filter for each profile by name or Id to get its FullName value.


To get all names and their corresponding values, you could use listMetadata, available in the Force.com Migration Toolkit, or you can write your own program to list and parse the results. In the Migration Toolkit, that looks like:

<sf:listMetadata metadataType="Profile" username="..." password="..." serverurl="..." />

The third option is to readMetadata, and then read the appropriate values from the XML. Each *.profile file will have its label inside. You could probably write up a quick Perl, Ruby, or NodeJS script if you wanted to just spit out the information in whatever format was easy for you.

  • Hi @sfdcfox. Thanks for answering. I would like to perform the mapping for around 30+ profiles. Third option is kind of problematic because I am restricted to maximum 10 results only . First option is also problematic because I am restricted to 1 result only as I am retrieving the FullName field. For the listMetadata option, can I match between the FileProperties getId() value and the Tooling Api query Id field ? – sfdcdev Jan 20 '17 at 11:59
  • @RonDaniel Yes, the Id in listMetadata is the same as used in the Tooling API, which is the same as the normal SOAP/REST APIs. I just checked to verify. – sfdcfox Jan 20 '17 at 12:13
  • Ok thank you very much. you always help me a lot :) – sfdcdev Jan 20 '17 at 12:17
  • @sfdcfox Should Tooling API query above be SELECT Name, FullName FROM Profile WHERE Name = 'System Administrator' – Alan Morey Jan 14 '19 at 18:59
  • @AlanMorey Yes, it should have been. Thanks for letting me know, I'll edit it. – sfdcfox Jan 14 '19 at 19:01
0

The approach I took using jsForce was to make one call to Metadata API to get list of Profiles this includes their Id and FullName. Then a second query to the SOAP API to get list of Profiles, this includes their Id and Name.

Then simply merge the results where the Id's match and get both Name and FullName for each Profile.

Assuming conn is a valid jsForce Connection

const conn = ...;

const getProfilesMetadataApi = async () => {
    const profiles = await conn.metadata.list([{ type: 'Profile' }]);

    const profileById = p => [
        p.id, {
            id: p.id,
            fullName: p.fullName
        }
    ];

    return new Map(profiles.map(profileById));
};

const getProfilesSoapApi = async () => {
    const profiles = await conn.sobject('Profile')
        .select('Id, Name')
        .execute();

    const profileById = p => [
        p.Id, {
            id: p.Id,
            name: p.Name
        }
    ];

    return new Map(profiles.map(profileById));
};

const metaProfiles = await getProfilesMetadataApi();
const soapProfiles = await getProfilesSoapApi();

const profiles = new Map();

for (const [id, profile] of metaProfiles) {
    const mergedProfile = Object.assign(profile, soapProfiles.get(id));
    profiles.set(id, mergedProfile);
}

The profiles above is a Map, where the key is the Profile Id and value is a Profile data object with properties { id, name, fullName }. It should be easy filter or create other maps from here.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.