---
schema_version: "1"
id: 98a60a2e31065ef34c46469f6948c1e8003f94a3630326904dc445b74f04bf29
title: Additional Automation Using Custom Apex Code
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/sfdo/264-0-0/npsp_automation_apex_code.md
canonical_url: https://help.salesforce.com/s/articleView?id=sfdo.npsp_automation_apex_code.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: 741a7b724d7dce828cdbf84428c24e849a89e8f0ee2d49c8d68572884b4c37a7
description: Find out more about additional automation.
products:
  - Nonprofit
release: "264"
---
# Additional Automation Using Custom Apex Code

Find out more about additional automation.

![Important](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-sfdo-nonprofit_success_pack-264-0-0-production-enus/bd2879e2-2bdc-4012-aa32-dc0c697c4538/images/icon_important.png)

Important This feature requires Apex coding and should only be used by a developer.

- **[Post Processing](https://help.salesforce.com/s/articleView?id=sfdo.npsp_automation_apex_code.htm&release=264.0.0&type=5)**  
    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](https://help.salesforce.com/s/articleView?id=sfdo.npsp_automation_apex_code.htm&release=264.0.0&type=5)**  
    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](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-sfdo-nonprofit_success_pack-264-0-0-production-enus/bd2879e2-2bdc-4012-aa32-dc0c697c4538/nonprofit_success_pack/images/extensibility_section.png)

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.

```java
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);
        }

    }
  }
}
```