0

can we achieve this scenario ?any help is very much appreciated.

Duplicate case closed and its case comment need to be added to original case???

Some Code written :

trigger CasecommentTrigger on CaseComment (before insert) {         
  Set<String> caseSubs = new Set<String>();        
  Set<Id> caseIds = new Set<Id>();       
  List<Case> listCases = new List<Case>();        
  List<Case> listUpdateCases = new List<Case>();       
  List<CaseComment> listCaseComm = new List<CaseComment>();       
  List<CaseComment> listInsertCaseComm = new List<CaseComment>();        
  Map<String, Id> mapCasSubId = new Map<String, Id>();       
  Map<Id, CaseComment> mapCaseIdCasComm = new Map<Id, CaseComment>();                       

  if(CommonVariables.caseRepeatCheck) {        
    CommonVariables.caseRepeatCheck = false;        
    Case cas1 = [SELECT Id, Subject,status, Description FROM Case 
                  WHERE id=:trigger.new[0].parentid];        
    listCases = [SELECT Id, Subject, Description FROM Case 
                  WHERE Subject=:cas1.subject and id!=:cas1.id  and status='New'];
    system.debug('@@@'+listcases.size());        
    listCaseComm = [SELECT Id, CommentBody, ParentId FROM CaseComment
                     WHERE ParentId =:trigger.new[0].id];          
    if(listCases.size() > 0) {                 
      for(Case cas : listCases) {        
        CaseComment cm=new CaseComment();        
        cm.commentbody=trigger.new[0].CommentBody();        
        cm.ParentId=cas.id;         
        listInsertCaseComm.add(cm);       
      }                
      insert listInsertCaseComm;                       
    }                
    cas1.status='Closed';       
    update cas1; 
  }       
} 
4
  • Can you include where you are getting stuck? Are you getting errors(if yes, what are the errors?), or is it not performing the way you expected? Adding as much detail to the problem with help others in coming up with an answer to help point you in the right direction.
    – Jenny B
    Commented Sep 26, 2014 at 19:20
  • a repost of this after some back and forth... salesforce.stackexchange.com/questions/49653/…
    – cropredy
    Commented Sep 26, 2014 at 20:23
  • @Jenny:Thanks for your reply.The code does not work as per my expectation,Where the Duplicate case with same subject line should get identified by the system and get closed by adding its case comment to the existing case which is open.These cases are created Via Email.Any help is very much appreciated.
    – nikkey
    Commented Sep 29, 2014 at 8:35
  • It looks like crop1645 has you on the right track, the trigger should be on the case object, can you update your question with what your code looks like now?
    – Jenny B
    Commented Sep 30, 2014 at 11:01

0

You must log in to answer this question.

Browse other questions tagged .