+ Start a Discussion
chandraYeruvaRechandraYeruvaRe 

Creating a Folder and place documents inside that folder

Hi all,

I am new to sales force.I am just a leraner in this area.My requirement is i need to write the code to upload the pdf documents to the server and retrive them using web services.I tried to follow the basic workbook example and i was ended with Email templates.

Now I tried to create a folder in force.com and want to put all my pdfs there.I tried to crate the folder with name "myFolder" it says invalid,then i queried for the folders in the work space I got my Email temlates folder nothing else.I read somewhere saying we can create a private folders in force.com, can anyone please tell me how to crate a folder with the specified name and to put some documents into that.

 

Thanks
Chandra.

SuperfellSuperfell

something like

 

Folder f = new Folder();

f.setName("my folder");

f.setDeveloperName("my folder");

f.setAccessType("Public"); 

f.setType("Document");

SaveResult sr = binding.create(new SObject [] {f})[0];

if (!sr.isSuccess())

   System.out.println(sr.getErrors()[0].getStatusCode() + ":" + sr.getErrors()[0].getMessage());

else {

Document d = new Document();

d.setName("foo");

d.setDeveloperName("foo");

d.setContentType("application/pdf"); 

d.setBody(loadFileAsBytes());

d.setFolderId(sr.getId());

SaveResult sr2 = binding.create(new SObject[]{d})[0];

if (!sr2.isSuccess())

   System.out.println(sr2.getErrors()[0].getStatusCode() + ":" + sr2.getErrors()[0].getMessage());

else

System.out.println("created document with Id " + sr2.getId()); 

sagar123sagar123

hi, i tried same code its giving me error like Method does not exist for line f.setName("my folder");

also 

 

   Error: Compile Error: Invalid type: SaveResult

 

I think create method does not works with Folder object.  Plz check this out and reply