+ Start a Discussion
himanshu huske 7himanshu huske 7 

Case_Trigger

In case object there is one custom text field type_c
case has record with any subject, and if we create another record with same subject, type_c field should be populated as 'duplicate'.
and this newly created case should b displayed in related list of previus case record.
SATHISH REDDY.SATHISH REDDY.
Hi Himanshu,

This should help you out with out any need to code https://developer.salesforce.com/forums/?id=906F0000000Ag6IIAS

Please mark it as the best answer if this helps.

Cheers!
Sathish
 
Abdul KhatriAbdul Khatri
Here is the trigger. I placed the original one in the Parent Field of the case, not sure what you mean by related list
trigger CaseDuplicate on Case (before insert) {

    Map<String, Case> subjects = new Map<String, Case>();
    
    for(Case caseRec : Trigger.new)
    {
        if(caseRec.Subject != null)
        {
            subjects.put(caseRec.Subject, caseRec);
        }
    }
    
    if(subjects.isEmpty()) return;
    
    for(List<Case> caseList : [SELECT Id, Subject FROM Case WHERE Subject = :subjects.keySet() AND ParentId = null])
    {
        for(Case caseRec : caseList)
        {
            if(subjects.containsKey(caseRec.Subject))
            {
                subjects.get(caseRec.Subject).ParentId = caseRec.Id;
                subjects.get(caseRec.Subject).type__c = 'duplicate';
            }
        }
    }    
   
}

Let me know if this help.