Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have upload the file from the by using the following code and document created successfully in Salesforce org.

 sforce.Document docvar = new sforce.Document();
            docvar.Name = documentName;
            docvar.Description = description;
            docvar.FolderId =;
            string extension = fileinfo.Extension;
            docvar.Type = extension.Replace(".", "");

            sforce.SaveResult saveResult = SFDCService.create(new sforce.sObject[] { docvar})[0];
            return saveResult;

I dont know how to update the document. I have tried following code. But no luck.

sforce.QueryResult qr = null;
            string SOQL = "";
            SOQL = "select id,name,description from document where id='" + _documentId + "'"; 
            qr = SFDCService.query(SOQL);
            sforce.sObject[] records1 = qr.records;

            sforce.Document doc = (sforce.Document)records1[0];

            sforce.SaveResult saveResult = SFDCService.update(new sforce.sObject[] {doc})[0];
            return saveResult;

Can you let me know how to update when click the update button form the c#.

share|improve this question
What does your save result give you for errors? What happens when you attempt the update? Are you positive that the _documentId variable is actually populated with a salesforce documents ID and not null? – Eric Aug 6 '14 at 2:17
up vote 2 down vote accepted

I have reviewed your code and you are jsut fetching the record and update without assign the new value.

Please use the follwoing code to resolve the issue.

qr = SFDCService.query(SOQL);
            sforce.sObject[] records1 = qr.records;
            sforce.Document doc = (sforce.Document)records1[0];
            doc.Name = documentName;
            doc.Url = filePath;
            sforce.SaveResult saveResult = SFDCService.update(new sforce.sObject[] {doc})[0];
share|improve this answer

Your code is creating an empty document.

you need to set either the Body or URL parameter of the document while creating..

and then when updating you can replace the URL or the Body of the document and call the update method

you can check this for the api object and the fields

share|improve this answer
Crated is working fine. I am uploading the file by choosing from open dialog box. can you look the code. in where I miss. because i have assign the record to new doc. but it is not updated – Lemon Aug 6 '14 at 2:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.