You need to sign in to do that
Don't have an account?
Ian Vianna 2
I'm getting this error message when trying to update a Metadata. Can you help me?
I'm trying to modify the visibility of a field using Apex, but I'm getting the following error when trying to update Metadata:
Below is the code for the method that is causing the problem. I have no idea what could be wrong:
I am using this API:
https://github.com/financialforcedev/apex-mdapi
MetadataServiceExamples.MetadataServiceExamplesException: Error occured processing component ***.***@***.***.com. In field: fullName - no Profile named ***.***@***.***.com found (INVALID_CROSS_REFERENCE_KEY).
Below is the code for the method that is causing the problem. I have no idea what could be wrong:
public static void updateFLS(String fieldName, Boolean securityLevel) { MetadataService.MetadataPort portService = MetadataServiceExamples.createService(); MetadataService.Profile profileName = new MetadataService.Profile(); system.debug(profileName.fullName); profileName.fullName = UserInfo.getUserName(); system.debug(profileName.fullName); profileName.custom = securityLevel; MetadataService.ProfileFieldLevelSecurity fieldSecurity = new MetadataService.ProfileFieldLevelSecurity(); fieldSecurity.field = fieldName; fieldSecurity.editable = true; profileName.fieldPermissions = new MetadataService.ProfileFieldLevelSecurity[] {fieldSecurity}; List <MetadataService.SaveResult> results = portService.updateMetadata( new MetadataService.Metadata[] {profileName} ); MetadataServiceExamples.handleSaveResults(results[0]); }
I am using this API:
https://github.com/financialforcedev/apex-mdapi
I see issue with the below line.UserInfo.GetUserName() only get the user name but not the profile name.
Can you assign the profile name and check the code.
If this solution helps, Please mark it as best answer.
Thanks,
You can't directly access the profile full name. It's only available in tooling api.
For System Administrator the fullname is Admin. Similarly other profiles also having their own full names.
So i have created below apex class to get the profile fullname using tooling api in apex:
Update your code like below:
One more easy way is there, create custom setting or custom metadata to store the profile name and their respective fullname... But you have to maintain whenever new profiles are coming... Then you can acces easily access inside the apex for refer the profile fullname by just calling metadata or CS match... Sample is in below screenshot...
Thanks,
Maharajan.C