function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rohit K SethiRohit K Sethi 

Can we find the duplicate attachment inserted on the bases of there body ?


Actually we insert the attachment under account as pdf
and once a pdf  is attached with the account and next time If with same content the pdf is attached with same account then I have to prevent.
Thanks.
 
Ishwar ShindeIshwar Shinde
Hi,
I don't think so. Easier way is to follow naming covention while uplaoding the file in salesforce or you can write trigger to create name for attachment, 
Main challenge in comparing the two attachmnet is the heap size issue. Attachment size can be upto 5MB and comparing two attachment we need 5 MB + 5 MB + some variables memory. And salesforce only support 6 MB hep size in sync mode.

Hope it will help!!
Rohit K SethiRohit K Sethi
Hi Ishwar,

Thanks for quick reply. 
But My file maximum contains the (1KB-100KB) data.

So size is not matter for my problem so plz suggest the way how we will check.


Thanks.
Ishwar ShindeIshwar Shinde
Hi Rohit,
You can try by converting the attachment body in string format and then compare the two strings. Let me know if it works for you.

Code to covert the attachment body in string is -

        Attachment csvFileBody = [SELECT Id,Body, Name FROM Attachment where id = attach.Id];
        Blob csvBlob = csvFileBody.Body;
        String csvAsString = csvBlob.toString();

Thanks,
Ishwar
Rohit K SethiRohit K Sethi
Hi Ishwar ,

I am allready try this but its not worked.

Thanks.
Ishwar ShindeIshwar Shinde
Hi Rohit,

I also had a doubt about it, but there was no other solution for it. I hope, it should work for text files.

Else, you need to follow the naming convention for file to identify the duplicate. 

Hope it is helpful.

Thanks and Regards,
Ishwar Shinde