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:
- Bulk Import Operations: Importing multiple Product Definitions at once
- Large Product Definitions: Importing PDs with complex schemas, many attributes, or large JSON payloads
- 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
- In Salesforce, navigate to Setup > Environments > Jobs > Apex Jobs
- Filter for jobs with:
- Job Type: "Batch"
- Apex Class: "ImportBatch" or similar import-related class
- Status: "Aborted"
- Note the job ID, start time, and any error messages
Step 2: Check Product Definition Records
-
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 -
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 -
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
- For the newly created Product Definition, check the
cscfga__Is_Compiled__cfield - If this field is
falseor null, the compilation did not complete - Check for any compilation error messages in the Product Definition record
Step 4: Review Import Options Used
- Ask the customer which import option they used:
- "Import as New" - Creates a new PD without versioning
- "Override Existing" - Updates the existing PD in place
-
"Import as New Version" - Creates a new version and archives the old one
-
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
- Navigate to the newly created Product Definition record
- Click the "Compile" button (if available in your org's UI)
- Wait for the compilation to complete
- Verify the
cscfga__Is_Compiled__cfield is nowtrue
Option B: Compile via Apex
If the UI button is not available, use the Developer Console to compile the PD:
- Open Developer Console in Salesforce
- Go to Debug > Open Execute Anonymous Window
-
Execute the following Apex code:
apex Id pdId = 'a0t7T000008fzh5QAA'; // Replace with your PD ID cscfga.API_1.compileProductDefinition(pdId); -
Check the execution log for any errors
- Verify the compilation completed successfully
Step 2: Fix Versioning (If Applicable)
If the import created duplicate active Product Definitions without proper versioning:
- Identify the correct version relationship:
- Determine which PD is the "old" version (should be archived)
-
Determine which PD is the "new" version (should remain active)
-
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 };
```
- Verify the versioning is now correct:
- Old PD:
cscfga__Is_Active__c = false,cscfga__Replaced_By__cpoints to new PD - New PD:
cscfga__Previous_Version__cpoints to old PD,cscfga__Version__cincremented
Step 3: Test the Product Definition
- Create a new basket
- Add a product that uses the newly imported Product Definition
- Configure the product and calculate totals
- Verify no errors occur during basket operations
- 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__cfield istruebefore 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
Related Information
- 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
Priyanka Bhotika
Comments