+ Start a Discussion

JDE Integration gives trigger error "CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY"

We have an JDE integration which is pushing data into salesforce, which is running for long time and now, the integration is failing(not inserting). The error log shows that, there are some trigger issues.

Class.JdeTriggerHandler.createObjsFromJDEs: line 115, column 1
Class.JdeTriggerHandler.onAfterInsert: line 14, column 1
Trigger.JDETrigger: line 11, column 1
2016-03-21 18:24:57,590 ERROR [JdeUpsert] client.PartnerClient processResult (Pa
rtnerClient.java:383) - Errors were found on item135
2016-03-21 18:24:57,590 ERROR [JdeUpsert] client.PartnerClient processResult (Pa
rtnerClient.java:385) - Error code is:CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY
2016-03-21 18:24:57,590 ERROR [JdeUpsert] client.PartnerClient processResult (Pa
rtnerClient.java:386) - Error message:JDETrigger: execution of AfterInsert

caused by: System.DmlException: Insert failed. First exception on row 0; first e
rror: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, SalesOrderCTrigger: execution of Aft

caused by: System.DmlException: Update failed. First exception on row 0 with id
0013400001JeMLsAAN; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, gii.Accou
ntAfterInsert: execution of AfterUpdate

caused by: System.NullPointerException: Attempt to de-reference a null object

Trigger.gii.AccountAfterInsert: line 61, column 1: []

Class.SalesOrderCTriggerHandler.aggregateCalc: line 49, column 1
Class.SalesOrderCTriggerHandler.onAfterInsert: line 4, column 1
Trigger.SalesOrderCTrigger: line 6, column 1: []

This integration was running from last year without any issues and now this error appears. 
No changes in the code until this implementation for the first time last year.
chandra sekhar chandranachandra sekhar chandrana
Hi visitorviv,

I think you might changed the account update trigger which causes this issue.
It seems some where in the trigger after creation of activity causing null reference .

From my view Class.SalesOrderCTriggerHandler.aggregateCalc: line 49, column 1 in this trigger is there any null reference of field having null value which might be used in validation or check causing the issue.

Mahesh DMahesh D

Please paste the below code and it will be easy to provide the solution:

SalesOrderCTrigger  -- Trigger
SalesOrderCTriggerHandler -- Apex Class

Also this integration is running for more than a year. 


trigger SalesOrderCTrigger on Sales_Order__c (after insert, after update, after delete, after undelete) {
    SalesOrderCTriggerHandler handler = new SalesOrderCTriggerHandler();
     if (trigger.isAfter) {
        if (trigger.isInsert)   { handler.onAfterInsert(trigger.new); }
        if (trigger.isUpdate)   { handler.onAfterUpdate(trigger.new, trigger.oldMap); }
        if (trigger.isDelete)   { handler.onAfterDelete(trigger.old); }
        if (trigger.isUndelete) { handler.onAfterUndelete(trigger.new); }

public without sharing class SalesOrderCTriggerHandler {
     public void onAfterInsert(List<Sales_Order__c> newLst) {  
    public void onAfterUpdate(List<Sales_Order__c> newLst, Map<Id, Sales_Order__c> oldMap) {   
    // recalc if orderdate changes  
     List<Sales_Order__c> toRecalc = new List<Sales_Order__c>();    
   for (Sales_Order__c item : newLst) {      
   if (item.OrderDate__c != oldMap.get(item.id).OrderDate__c) {     
     if (!toRecalc.isEmpty()) { aggregateCalc(toRecalc); }   
    public void onAfterDelete(List<Sales_Order__c> oldLst) {   
   public void onAfterUndelete(List<Sales_Order__c> newLst) {   
         private void aggregateCalc(List<Sales_Order__c> orders) {  
     List<Id> accIds = new List<Id>();  
     List<Id> conIds = new List<Id>();   
           for (Sales_Order__c item : orders) {  
      if (item.Account__c != null) { accIds.add(item.Account__c); }      
   if (item.Contact__c != null) { conIds.add(item.Contact__c); }    
             if (!accIds.isEmpty()) {    
     Map<Id, Account> accMap = new Map<Id, Account>([SELECT Id, Last_Sales_Order_Date__c, Number_of_Sales_Orders__c FROM Account WHERE Id IN :accIds]);                  for (AggregateResult item : [SELECT Count(Id) cnt, Max(OrderDate__c) maxDate, Account__c    
                    FROM Sales_Order__c     
                    WHERE Account__c IN :accIds    
                     GROUP BY Account__c])  
     accMap.get((id)item.get('Account__c')).Last_Sales_Order_Date__c = (date)item.get('maxDate');           accMap.get((id)item.get('Account__c')).Number_of_Sales_Orders__c = (integer)item.get('cnt');    
            update accMap.Values();
             if (!conIds.isEmpty()) {    
     Map<Id, Contact> conMap = new Map<Id, Contact>([SELECT Id, Last_Sales_Order_Date__c, Number_of_Sales_Orders__c FROM Contact WHERE Id IN :conIds]);                  for (AggregateResult item : [SELECT Count(Id) cnt, Max(OrderDate__c) maxDate, Contact__c    
                    FROM Sales_Order__c      
                   WHERE Contact__c IN :conIds 
                       GROUP BY Contact__c])     
      conMap.get((id)item.get('Contact__c')).Last_Sales_Order_Date__c = (date)item.get('maxDate');           conMap.get((id)item.get('Contact__c')).Number_of_Sales_Orders__c = (integer)item.get('cnt');     
              update conMap.Values();  
    } }
Mahesh DMahesh D

If you see the below code:
conMap.get((id)item.get('Contact__c')).Last_Sales_Order_Date__c = (date)item.get('maxDate');           
	  conMap.get((id)item.get('Contact__c')).Number_of_Sales_Orders__c = (integer)item.get('cnt');

I didn't understand what you are trying to achieve with this and error is in these 2 lines only.

If we know the actual requirement then we can help you better.

As this moment the error in those 2 lines where it is get the null value and we can fix it by adding the null check but if we know the requirement then it will be easy to provide better solution.

Mike miller 442Mike miller 442

We are exploring SSO options ...


what do you guys think about?

- Jessy.