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.
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.
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.
SELECT Name, FullName FROM Profile WHERE Name = 'System Administrator'
Commented
Jan 14, 2019 at 18:59
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.