Skip to content

Latest commit

 

History

History
46 lines (31 loc) · 1.82 KB

README.md

File metadata and controls

46 lines (31 loc) · 1.82 KB

Salesforce Tools

Tools for programmatically managing Salesforce metadata (currently only Profiles and PermissionSets).

Loading Profiles:

By Path

Profile p = new Profile("...my-project\\force-app\\main\\default\\profiles\\Admin.profile-meta.xml");

By Folder

    Profiles.fromDirectory("...my-project\\force-app\\main\\default\\profiles")

Modifying 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();
    });

Removing XML nodes by predicate

Profiles.fromDirectory(profileDirectory)
    .forEach(p -> {
        p.remove((MetadataNode node) -> node.getMetadataName().contains("trailheadapp__"));
        p.saveFile();
    });

Merging Profiles

Merge will take all permissions from one profile and apply it onto another without creating duplicates.

Retain only those permissions that are available on another Profile

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();