You need to sign in to do that
Don't have an account?
Aditya Mohan
List of Attachments returned to Custom Button has no value in Javascript
I am trying to access a list of Attachments related to a Contact from Custom Button during OnClick Javascript in a Javascript Array. But, the array doesn't display any value. It's blank.
Apex Class:
Javscript Button:
Apex Class:
global class ZipAndSendAttachments { webservice static List<AttachmentWrapper> getAttachments(String contactId) { List<Attachment> lstAttachments = new List<Attachment>(); lstAttachments = [SELECT Id, Name, ContentType, Body, ParentId FROM Attachment WHERE ParentId = :contactId]; List<AttachmentWrapper> attWrapper = new List<AttachmentWrapper>(); AttachmentWrapper a; for(Attachment att : lstAttachments){ a = new AttachmentWrapper(); a.attName = att.Name; a.attEncodedBody = EncodingUtil.base64Encode(att.Body); attWrapper.add(a); } System.debug('attWrapper '+attWrapper); return attWrapper; } global class AttachmentWrapper { public String attEncodedBody {get; set;} public String attName {get; set;} }}
Javscript Button:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} {!REQUIRESCRIPT("/resource/JSZip/Stuk-jszip-3a39a71/dist/jszip.min.js")} var queryResult = []; var query = "SELECT Id, ParentId FROM Attachment WHERE ParentId = '{!Contact.Id}'"; queryResult.push(sforce.connection.query(query)); if(queryResult != null) {result = sforce.apex.execute("ZipAndSendAttachments","getAttachments",{contactId:"{!Contact.Id}"}); console.log('result::' + result); }
Can you try the below one,
Hi Arun,
Thanks for your reply.
We need to get attachments while after invoking getAttachments function. That is:
Here the result is blank, instead of attachments list
Since already you have queried attachment in button itself and checked the list size there. Again you are doing same in class and adding it to wrapper instance.
could you try and see the response in alert box,
What exactly you are trying to display on console.log?