java - upload a file to SalesForce programatically -


i build flow create case in salesforce. now, trying upload file case programatically. client uploads file manually in server. question how upload java rest based web service. have links describe topic.

first try read documents below:
see following:
http://www.salesforce.com/in/?ir=1
api doc:
http://www.salesforce.com/us/developer/docs/api/content/sforce_api_objects_document.htm
examples:
http://login.salesforce.com/help/doc/en/fields_useful_field_validation_formulas.htm

the following code allows upload physical file salesforce.com , attach record.
code:

  try {          file f = new file("c:\java\test.docx");         inputstream = new fileinputstream(f);         byte[] inbuff = new byte[(int)f.length()];                 is.read(inbuff);          attachment attach = new attachment();         attach.setbody(inbuff);         attach.setname("test.docx");         attach.setisprivate(false);         // attach object in sfdc          attach.setparentid("a0f600000008q4f");          saveresult sr = binding.create(new com.sforce.soap.enterprise.sobject.sobject[] {attach})[0];         if (sr.issuccess()) {             system.out.println("successfully added attachment.");         } else {             system.out.println("error adding attachment: " + sr.geterrors(0).getmessage());         }       } catch (filenotfoundexception fnf) {         system.out.println("file not found: " +fnf.getmessage());      } catch (ioexception io) {         system.out.println("io: " +io.getmessage());                 } 

please try , let me know in case of concern.


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -