Activity Forums Salesforce® Discussions How to Remove a Duplicate CaseID Programatically in Salesforce?

  • Piyush

    Member
    August 8, 2019 at 7:48 am

    Hi,

    You can use trigger to delete the duplicate ids as follows:-

    Trigger deleteduplicate on Student__c (before insert)
    {
    set<String> uniqueIds = new set<Id>();

    for (Student__c s : Trigger.new)
    uniqueIds.add(s.StudentId__c);

    list<Student__c> existingstudents = [select StudentId__c from Student__c where StudentId__c in :uniqueIds];

    list<Student__c> dupestodelete = new list<Student__c>();
    for (Student__c s : Trigger.new)
    {
    for (Student__c existing : existingstudents)
    {
    if (s.StudentId__c == existing.StudentId__c)
    {
    dupestodelete.add(s);
    continue;
    }
    }
    }

    delete dupestodelete;

    }

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos