You need to sign in to do that
Don't have an account?
Force.com
Fetch attachment body of Salesforce from Java
I am fetching attachment object from java. So, I am getting the Attachement Body in base64 type.
How can I get complete body of attachment in Java.
Please suggest.
You can simple read the field value convert it into byte[] and write it to the file with the name of Attachment.
All Answers
You can simple read the field value convert it into byte[] and write it to the file with the name of Attachment.
Thanks a lot.
I did the same and it worked.
Hii,
how to get the Account object attachment file from salesforce through java.......,Plss help me
Thanks & Regards..,
Nims
you'd use a soql query, something like select body from attachment where parentId = 'some account id'
Hi Simon thank you...,
simon i want,we have some attachment files in account object.now we get that attachment file and that file stores in our local machine like desktop using java application. so pls snd me java code
Regards,
Nims
Hi Nims,
Try this java code for fetching attachments of Account.
Thanks,
Pragati
Thank you Pragathi I will try.......
Regards,
Nims.
Hi Pragathi This query is correct,i applyed this query,file was attached but i want also that attachment file is store in our local machine how to store plss tell me...
Thanks & Regards,
Nims.
Hi Nims,
Try this out
Thanks,
Pragati
Hi Pragati,
This fn is correct,its working....,Thank you Pragati Thank you very much.......
Happy to help.
Thanks,
Pragati
HI Pragati,
this fn is working,i got the attachment file,Thank you Pragati Thank you sooo much..
Regards,
Nims.
Hello Pragati,
I am trying the to convert body of attachment object back into the pdf using java
my code is
where pdfBody is base 64 encoded string (body from attachment )
and finaly am converting this byte array to InputStram and passing as response to struts actoion,but i am getting error as
Failed to load pdf document.
Please help ...thanks in advance
Hi Montmorency_143,
I converted the Attachment into PDF using these steps. Check if these can help you.
Cheers,
Pragati
import com.sforce.ws.util.Base64;
and use
String s1= (String)s.getField("Body");
FileOutputStream output = new FileOutputStream(f1);
output.write(Base64.decode(s1.getBytes()));
( This is how I did for partner wsdl) , can use for Enterprise WSDL as well
I am fetching the attachment in java and I need to pass it to Box serevr, for that I am using "FileInputStream stream1 = new FileInputStream(filepath); " But I need to pass the file which is stored as attachment.
But not able to pass the file location as given. As Prasanna__d has suggested the solution. Can you please share some code snippet for the this. It will be very usefull.
Thanks
Sunil
Pragati
Whats is q variable above code
what it holds
q = (Attachment)queryResultsAttach.getRecords();