Scripts
These scripts are intended for use only when Auto Config does not work in your Salesforce org. They are not required for most customers.
Creating the GRAX_Integration_User Permission Set manually
Open the Salesforce Developer Console
Open the
DebugmenuSelect
Open Execute Anonymous Window(or pressCTRL + E)Copy the script below into the
Enter Apex CodedialogSelect the
Open LogcheckboxClick
ExecuteAssign the new 'GRAX_Integration_User' permission set to the GRAX Integration User.
PermissionSet piu = new PermissionSet(
Name = 'GRAX_Integration_User',
Label = 'GRAX Integration User Permission',
Description='Grants users permission to read and update records, fields and files for GRAX backup, archive and restore',
PermissionsApiEnabled=true,
PermissionsViewAllData=true,
PermissionsModifyAllData=true,
PermissionsQueryAllFiles=true
);
DescribeSobjectResult permissionSetDescribe = Schema.PermissionSet.SObjectType.getDescribe();
Map<String, SObjectField> fieldMap = permissionSetDescribe.fields.getMap();
List<String> availablePermissions = new List<String>();
for (String fieldName : fieldMap.keySet()) {
if (!fieldName.startsWithIgnoreCase('Permissions')) {
continue;
}
if (fieldName == 'PermissionsCreateAuditFields') {
System.debug('Setting PermissionsCreateAuditFields=true');
piu.put(fieldName, true);
}
if (fieldName == 'PermissionsViewAllData' ||
fieldName == 'PermissionsModifyAllData' ||
fieldName == 'PermissionsQueryAllFiles') {
continue;
}
DescribeFieldResult fd = fieldMap.get(fieldName).getDescribe();
if (fd.isCreateable() && fd.isUpdateable()) {
availablePermissions.add(fieldName);
}
}
Integer count = 1;
while (count < 11) {
try {
insert piu;
count = 100;
} catch(DmlException e) {
count++;
List<String> splitError = e.getMessage().split(' ');
for (String str : splitError){
string check = str.removeEnd(',');
check = check.removeEnd(':');
for (String fieldName : availablePermissions){
if (fieldName == 'Permissions' + check){
piu.put(fieldName, true);
}
}
}
}
}Fixing Field Level Security manually
Option 1: Apex FLS Script
The GRAX-provided Apex script below is an effective solution for updating field-level permissions on a large number of objects. However, there are a few cases in which the script may not be ideal:
Very large number of objects
Very large number of fields
The script makes a best effort to handle Apex row/batch limits. This means that you need to run the script multiple times if a large number of objects are processed. The script outputs Apex batch limits reached. Please run again for next batch. if another run is required.
If you encounter Apex limit errors, errors related to specific objects, or validation errors while running this script, fallback to the web-tools option below for updating the objects that remain.
NOTE: this section assumes you've used the script above to provision a GRAX_Integration_User Permission Set. If you don't have a permission set with this name in your org, the script fails.
ALSO NOTE: this script grants access to fields we're able to find in the Salesforce metadata. This may not be a comprehensive list. GRAX Admins should review the GRAX_Integration_User Permission Set's Field Permissions for each object to ensure access is granted to all fields.
Running the FLS Script
Open the Salesforce Developer Console
Open the
DebugmenuSelect
Open Execute Anonymous Window(or pressCTRL + E)Copy the script below into the
Enter Apex CodedialogSelect the
Open LogcheckboxClick
ExecuteIn the
Execution Logwindow, select theDebug OnlycheckboxIf the last log entry prompts a re-run, return to the
Execute Anonymous Windowand repeat the subsequent steps until the last entry no longer prompts a re-run.
Option 2: Web-tools Script Builder
GRAX Web-tools can generate an FLS script that is scoped to a single-object at a time. This prevents many issues with Apex limits that may result from the larger script above while still making life easy for SFDC admins.
Generating and Running a Script
Navigate to
/web/toolson your GRAX Application, or use the link at the top right of theSettingspageSelect the
Missing Field PermissionsoptionSelect the
Show Apex Scriptoption for the intended objectCopy the generated script to your clipboard
Open the Salesforce Developer Console
Open the
DebugmenuSelect
Open Execute Anonymous Window(or pressCTRL + E)Copy the script below into the
Enter Apex CodedialogSelect the
Open LogcheckboxClick
ExecuteIn the
Execution Logwindow, select theDebug OnlycheckboxThe script outputs the number of corrected fields in the last log line.
Repeat the steps above for each necessary object.
Last updated
Was this helpful?

