• Nikhil N
  • NEWBIE
  • 25 Points
  • Member since 2019

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 5
    Replies
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;
}

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