For the complete documentation index, see llms.txt. This page is also available as Markdown.

Fixing Template Errors After Template Migration

thinking face Problem

You or a client just used the standard migration method under S-Docs Setup to migrate templates from one org to another. Afterwards, most or all of those templates trigger an error upon use until you go to that template and manually re-save it.

seedling Solution

1

Step: Verify templates have errors

Start by verifying the field SDOC__Has_Error__c is set to true for those templates. Spot checking only a couple should be fine. To get a full list, run the following query in Salesforce Inspector:

SELECT Id FROM SDOC__SDTemplate__c WHERE SDOC__Has_Error__c = true
2

Step: Add Apex class to toggle the field

Add the following Apex class to auto-toggle that field from TRUE to FALSE:

public class HasErrorToggler {
    public static void toggleBooleanField(List<SObject> records, String fieldName) {
        if (records == null || records.isEmpty()) return;

        for (SObject rec : records) {
            Boolean currentValue = (Boolean) rec.get(fieldName);
            rec.put(fieldName, currentValue == null ? true : !currentValue);
        }
        update records;
    }
}
3

Step: Run the Apex class

Then, run a simple command in the Developer Console to run the Apex class:

List<SDOC__SDTemplate__c> temps = [
    SELECT Id, SDOC__Has_Error__c
    FROM SDOC__SDTemplate__c
    WHERE SDOC__Has_Error__c = true
];

HasErrorToggler.toggleBooleanField(temps, 'SDOC__Has_Error__c');

By adding a LIMIT 1 to the query, you can verify if this is working. You’ll see the record count in Salesforce Inspector drop by 1.

4

Step: Test generation

Finally, try to generate a document with a couple of the templates that previously errored. They should generate.

Keep in mind, some templates may still trigger that same error. This means there is something else keeping it from toggling, such as an invalid ID in the preview ID field, or it references a component that no longer exists, etc.

Last updated

Was this helpful?