+ Start a Discussion
Luke Higgins 22Luke Higgins 22 

CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY error on trigger

I recieved this error when testing a few things on a recently implemented trigger - "CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, addPTMplc: execution of AfterUpdate caused by: System.DmlException: Update failed"
Here's the code:
trigger addPTMplc on jstcl__PlacementTeamMember__c (after insert, after update) {

    List<ID> listIds = new List<ID>();
    
    for(jstcl__PlacementTeamMember__c ptm : Trigger.new){
        listIds.add(ptm.jstcl__Placement__c);
    }
    List<String> lstNames = new List<String>();
	List<ts2__Placement__c> plcList = [SELECT Id, Placement_Team_Member_List__c FROM ts2__Placement__c WHERE Id IN :listIds];
    for(jstcl__PlacementTeamMember__c ptm : [SELECT jstcl__User__r.name From jstcl__PlacementTeamMember__c WHERE jstcl__Placement__c IN :listIds]){
        
        if(lstNames.contains(ptm.jstcl__User__r.Name)){

        }
        else{
            lstNames.add(ptm.jstcl__User__r.Name);
        }
    for(integer i=0;i<plcList.size();i++){
        String names = string.join(lstNames, ', ');
        plcList[i].Placement_Team_Member_List__c =names;
    	}
    }
    update plcList;
}

 
Best Answer chosen by Luke Higgins 22
Nikhil NNikhil N
Hi Luke Higgins,

If you trying this on after update,Remove "After Insert" event on trigger. OR If you trying this on after Insert,Remove "After Update" event on trigger.No need to perform 2 trigger events for this Scenario.You can try with Single trigger event "After Insert" OR "After Update".