Start a conversation

ImportBatch Apex Job Aborting During Product Definition JSON Import

Problem

When importing Product Definition JSON data through the CloudSense import utility, the import process appears to hang or get stuck for an extended period. Upon checking Apex Jobs in Salesforce, the ImportBatch job shows a status of "Aborted".

Despite the job aborting, a new Product Definition record may still be created in Salesforce. However, this can lead to unexpected issues:
- The newly created Product Definition becomes active
- The previous Product Definition also remains active
- Neither Product Definition is linked to the other through versioning
- Both Product Definitions exist independently without proper version control

Root Cause

The ImportBatch Apex job can fail and abort when there are too many Product Definitions being compiled simultaneously. This typically occurs when:

  1. Bulk Import Operations: Importing multiple Product Definitions at once
  2. Large Product Definitions: Importing PDs with complex schemas, many attributes, or large JSON payloads
  3. Governor Limit Pressure: The compilation process approaches Salesforce governor limits (CPU time, heap size, SOQL queries)

Why the Job Aborts

The Product Definition import process consists of two phases:
1. Import Phase: The JSON data is parsed and the Product Definition record is created/updated in Salesforce
2. Compilation Phase: The Product Definition is compiled to generate metadata, validate the schema, and establish relationships

When the compilation phase encounters governor limit pressure, the ImportBatch job aborts to prevent exceeding Salesforce limits. However, the import phase may have already completed, resulting in a Product Definition record that exists but is not fully compiled.

Why Versioning Fails

When the compilation phase aborts:
- The versioning logic (which links old and new PD versions) does not execute
- The new PD is created as a standalone record
- The old PD remains active without being archived or replaced
- This creates data inconsistency and potential configuration conflicts

Diagnosis Steps

Step 1: Check Apex Jobs

  1. In Salesforce, navigate to Setup > Environments > Jobs > Apex Jobs
  2. Filter for jobs with:
  3. Job Type: "Batch"
  4. Apex Class: "ImportBatch" or similar import-related class
  5. Status: "Aborted"
  6. Note the job ID, start time, and any error messages

Step 2: Check Product Definition Records

  1. Query for recently created or modified Product Definitions:
    sql SELECT Id, Name, cscfga__Is_Active__c, cscfga__Version__c, cscfga__Previous_Version__c, cscfga__Is_Compiled__c, CreatedDate, LastModifiedDate FROM cscfga__Product_Definition__c WHERE LastModifiedDate = TODAY ORDER BY LastModifiedDate DESC

  2. Check if multiple PDs with the same name exist:
    sql SELECT Name, COUNT(Id) recordCount FROM cscfga__Product_Definition__c WHERE cscfga__Is_Active__c = true GROUP BY Name HAVING COUNT(Id) > 1

  3. For duplicate active PDs, check if they are properly versioned:
    sql SELECT Id, Name, cscfga__Version__c, cscfga__Previous_Version__c, cscfga__Is_Active__c, CreatedDate FROM cscfga__Product_Definition__c WHERE Name = '[Product_Definition_Name]' ORDER BY CreatedDate DESC

Step 3: Check Compilation Status

  1. For the newly created Product Definition, check the cscfga__Is_Compiled__c field
  2. If this field is false or null, the compilation did not complete
  3. Check for any compilation error messages in the Product Definition record

Step 4: Review Import Options Used

  1. Ask the customer which import option they used:
  2. "Import as New" - Creates a new PD without versioning
  3. "Override Existing" - Updates the existing PD in place
  4. "Import as New Version" - Creates a new version and archives the old one

  5. If "Import as New Version" was used but versioning failed, this confirms the compilation abort caused the issue

Resolution

Step 1: Manually Compile the Product Definition

Option A: Compile via UI

  1. Navigate to the newly created Product Definition record
  2. Click the "Compile" button (if available in your org's UI)
  3. Wait for the compilation to complete
  4. Verify the cscfga__Is_Compiled__c field is now true

Option B: Compile via Apex

If the UI button is not available, use the Developer Console to compile the PD:

  1. Open Developer Console in Salesforce
  2. Go to Debug > Open Execute Anonymous Window
  3. Execute the following Apex code:
    apex Id pdId = 'a0t7T000008fzh5QAA'; // Replace with your PD ID cscfga.API_1.compileProductDefinition(pdId);

  4. Check the execution log for any errors

  5. Verify the compilation completed successfully

Step 2: Fix Versioning (If Applicable)

If the import created duplicate active Product Definitions without proper versioning:

  1. Identify the correct version relationship:
  2. Determine which PD is the "old" version (should be archived)
  3. Determine which PD is the "new" version (should remain active)

  4. Update versioning fields:
    ```apex
    // In Developer Console Execute Anonymous
    Id oldPdId = 'a0t7T000008fzh5OLD'; // Old PD ID
    Id newPdId = 'a0t7T000008fzh5NEW'; // New PD ID

cscfga__Product_Definition__c oldPd = new cscfga__Product_Definition__c(
Id = oldPdId,
cscfga__Is_Active__c = false,
cscfga__Replaced_By__c = newPdId
);

cscfga__Product_Definition__c newPd = new cscfga__Product_Definition__c(
Id = newPdId,
cscfga__Previous_Version__c = oldPdId,
cscfga__Version__c = 2 // Increment version number
);

update new List{ oldPd, newPd };
```

  1. Verify the versioning is now correct:
  2. Old PD: cscfga__Is_Active__c = false, cscfga__Replaced_By__c points to new PD
  3. New PD: cscfga__Previous_Version__c points to old PD, cscfga__Version__c incremented

Step 3: Test the Product Definition

  1. Create a new basket
  2. Add a product that uses the newly imported Product Definition
  3. Configure the product and calculate totals
  4. Verify no errors occur during basket operations
  5. Test the full order submission workflow if applicable

Prevention

For Product Definition Imports

  • Import One at a Time: When importing Product Definitions, import them one at a time rather than in bulk to avoid compilation governor limit issues
  • Use Smaller Batches: If bulk import is necessary, break the import into smaller batches (e.g., 5-10 PDs per batch)
  • Monitor Apex Jobs: After initiating an import, immediately check Apex Jobs to verify the ImportBatch job is running and not aborted
  • Verify Compilation: After each import, verify the cscfga__Is_Compiled__c field is true before proceeding to the next import

For Large Product Definitions

  • Simplify Before Import: If importing very large or complex Product Definitions, consider:
  • Splitting the PD into smaller components
  • Removing unnecessary attributes or validation rules before import
  • Importing the base PD first, then adding complexity in subsequent updates

For Import Option Selection

  • Choose the Right Option: Select the appropriate import option based on your goal:
  • Use "Import as New Version" only when you want to preserve the old version and establish version control
  • Use "Override Existing" when updating an existing PD without creating a new version
  • Use "Import as New" when creating a completely new PD

  • Verify Option Behavior: Consult the CloudSense Export-Import User Guide to understand the behavior of each import option

For Compilation Failures

  • Retry Compilation: If an import completes but compilation fails, simply retry the compilation manually (via UI button or Apex API) rather than re-importing the entire PD
  • Check Governor Limits: If compilation consistently fails, check Apex debug logs for governor limit warnings and consider optimizing the PD schema
  • Affected Apex Job: ImportBatch
  • Affected Object: cscfga__Product_Definition__c
  • Related Fields: cscfga__Is_Compiled__c, cscfga__Version__c, cscfga__Previous_Version__c, cscfga__Replaced_By__c
  • Compilation API: cscfga.API_1.compileProductDefinition(Id pdId)
  • Common Scenarios: Bulk PD import, large PD JSON, governor limit pressure
  • Related Documentation: CloudSense Export-Import User Guide
Choose files or drag and drop files
Was this article helpful?
Yes
No
  1. Priyanka Bhotika

  2. Posted

Comments