Take the 2-minute tour ×
Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. It's 100% free, no registration required.

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#.

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 at 2:17

2 Answers 2

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 at 2:32

Your Answer

 
discard

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.