upload a file to SalesForce programmatically

I am building a flow that creates a business in the sales department. Now I am trying to upload a file to this case programmatically. Basically, the client uploads the file manually to the server. Now the question is how can I download it using a Java rest-based web service. it’s good to have any links that describe this topic.

+5
source share
2 answers

First try reading the documents below:
See the 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 you to upload a physical file to Salesforce.com and attach it to a record.
 The code:

  try {

        File f = new File("c:\java\test.docx");
        InputStream is = 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 to an 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 this and let me know in case of any problems.

+5
source

The previous answer gave the doc API for Document instead of the application. Doc API for the application: http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_attachment.htm

+2
source

All Articles