Activity Forums Salesforce® Discussions How can we prevent duplicate records from being processed by Salesforce trigger?

  • Avnish Yadav

    Member
    July 31, 2018 at 7:05 am

    Hello Anjali,

    You can use a Set to store ids, which will prevent duplicate records from being processed.

    Example:-

    Set<SObject> setIdobject = new Set<SObject>();

    for(SObject obj: Trigger.new)

    {

    setIdSobject.add(obj.id);

    }

    Thanks.

  • Parul

    Member
    September 14, 2018 at 4:39 am

    Hi,

    If you are using with List then you will Before.trigger to check duplicate then trigger insert data after check.

     

     

    Thanks

  • shariq

    Member
    September 15, 2018 at 5:00 pm

    Hi,

    Best way to prevent this is to use Map of Id vs record-

    Map<Id, Sobject> mapIdVsRecords = new Map<Id, Sobject>();

    for(Sobject sobj : sObjectList){

    mapIdVsRecords .put(sobj.Id, sobj);

    }

    Hope this helps.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos