+ Start a Discussion
himanshu huske 7himanshu huske 7 


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.
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.

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)
                subjects.get(caseRec.Subject).ParentId = caseRec.Id;
                subjects.get(caseRec.Subject).type__c = 'duplicate';

Let me know if this help.