Tools for programmatically managing Salesforce metadata (currently only Profiles and PermissionSets).
Profile p = new Profile("...my-project\\force-app\\main\\default\\profiles\\Admin.profile-meta.xml");
Profiles.fromDirectory("...my-project\\force-app\\main\\default\\profiles")
Profiles.fromDirectory(profileDirectory)
.forEach(p -> {
p.add(new ApplicationVisibility("Application", true, true));
p.add(new FieldPermission("Account.Custom_Field_1__c", true, false));
p.add(new FieldPermission("Account.Custom_Field_2__c", true, true));
p.add(new ObjectPermission("Custom_Object__c", true, false, true, true, false, false));
p.add(new TabVisibility("Application_Log__c", TabVisibility.DefaultOn));
p.saveFile();
});
Profiles.fromDirectory(profileDirectory)
.forEach(p -> {
p.remove((MetadataNode node) -> node.getMetadataName().contains("trailheadapp__"));
p.saveFile();
});
Merge will take all permissions from one profile and apply it onto another without creating duplicates.
retainSamePermissions()
accepts another Profile which will serve as a base and strips all permissions that are not listed on base profile.
The goal is to streamline target profile to have the same set of permissions as base profile.
Profile p = new Profile("...my-project\\force-app\\main\\default\\profiles\\Dealer Agent.profile-meta.xml");
p.retainSamePermissions(new Profile("...my-project\\force-app\\main\\default\\profiles\\Dealer Supervisor.profile-meta.xml"));
p.saveFile();