function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
visitorvivvisitorviv 

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
erInsert

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
Hi

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

SalesOrderCTrigger  -- Trigger
SalesOrderCTriggerHandler -- Apex Class

Regards,
Mahesh
visitorvivvisitorviv
Also this integration is running for more than a year. 

SalesOrderCtrigger

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

SalesOrderCTriggerHandler
public without sharing class SalesOrderCTriggerHandler {
     public void onAfterInsert(List<Sales_Order__c> newLst) {  
   aggregateCalc(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) {     
      toRecalc.add(item);     
    }    
   }  
     if (!toRecalc.isEmpty()) { aggregateCalc(toRecalc); }   
  }     
    public void onAfterDelete(List<Sales_Order__c> oldLst) {   
    system.debug(oldLst);     
       aggregateCalc(oldLst);   
  }       
   public void onAfterUndelete(List<Sales_Order__c> newLst) {   
  aggregateCalc(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
Hi

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.

Regards,
Mahesh
Mike miller 442Mike miller 442
Hi,

We are exploring SSO options ...

https://www.ssogen.com/spgateway-sso-solution/

what do you guys think about?

Thanks
- Jessy.