1

I have upload the file from the c#.net 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 = folder.id;
            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#.

1
  • 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
    Commented Aug 6, 2014 at 2:17

2 Answers 2

2

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];
1

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

1
  • 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
    Commented Aug 6, 2014 at 2:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .