Loading
Nonprofit Success Pack (NPSP) Managed Package
Additional Automation Using Custom Apex Code

Additional Automation Using Custom Apex Code

Find out more about additional automation.

Important
Important This feature requires Apex coding and should only be used by a developer.
  • Post Processing
    When you're importing data records, you may have some post processing that would be easier to do with code because you can process higher volumes and perform more complex procedures.
  • Sample Code
    This sample code shows a simple post-processing scenario where a "Spouse" relationship is automatically created between Contact1 and Contact2 (assuming the contacts are newly-created).

Post Processing

When you're importing data records, you may have some post processing that would be easier to do with code because you can process higher volumes and perform more complex procedures.

NPSP includes an interface that you can customize to perform post-processing functionality on your data import records. The interface, BDI_IPostProcess, includes one method called process. To take advantage of this functionality, you'll need to write an Apex class that implements the interface and its method. You then specify the Apex class in the Post Process Implementing Class field in either the NPSP Data Import configuration options or in the NPSP Data Import Batch configuration options.

Extensibility section in the Configuration Options

After NPSP processes the number of records you specify as the batch size (in configuration options), NPSP will call your class and perform any post processing specified in the class.

Sample Code

This sample code shows a simple post-processing scenario where a "Spouse" relationship is automatically created between Contact1 and Contact2 (assuming the contacts are newly-created).

This is a working example, just to give you an idea of what is possible. We encourage you to write a post processing class that performs more complex tasks.

global with sharing class MyPostProcess implements npsp.BDI_IPostProcess {

global void process(npsp.BDI_DataImportService bdi) {

    List<npe4__Relationship__c> listRel = new List<npe4__Relationship__c>();

    for (npsp__DataImport__c di : bdi.listDI) {
        // create a relationship if both c1 and c2 are specified
        // and they are newly created contacts
        if (di.npsp__Contact1Imported__c != null && di.npsp__Contact2Imported__c != null &&
            di.npsp__Contact1ImportStatus__c == label.npsp__bdiCreated && di.npsp__Contact2ImportStatus__c == label.npsp__bdiCreated) {
            listRel.add(new npe4__Relationship__c(
                npe4__Contact__c = di.npsp__Contact1Imported__c,
                npe4__RelatedContact__c = di.npsp__Contact2Imported__c,
                npe4__Type__c = 'Spouse',
                npe4__Status__c = 'Current'));
           }
        }

        if (listRel.size() > 0) {
            database.insert(listRel);
        }

    }
  }
}
 
Cargando
Salesforce Help | Article