• Ian Vianna 2
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
I'm trying to modify the visibility of a field using Apex, but I'm getting the following error when trying to update Metadata:
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'm trying to modify the visibility of a field using Apex, but I'm getting the following error when trying to update Metadata:
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