1

I want to make a program where a user uploads any document. On uploading I want the user to be redirected to a folder. So here's what I have tried so far from salesforce documentations...

public class documentExt {
public documentExt(ApexPages.StandardController controller) {
    Document d = (Document) controller.getRecord();
    d.folderid = UserInfo.getUserId(); //this puts it in My Personal Documents

public PageReference save() {
    // Send the user to the detail page for the new account.
    PageReference pageRef = new PageReference('https://na15.salesforce.com/015?fcf=005i00cccc3Djl8');
}

}                 
}

And the VF page...

<apex:page standardController="Document" extensions="documentExt">
<apex:messages />
<apex:form id="theForm">
  <apex:pageBlock >
      <apex:pageBlockSection >
        <apex:inputFile value="{!document.body}" filename="{!document.name}"/>
        <apex:commandButton value="Save" action="{!save}"/>
      </apex:pageBlockSection>
   </apex:pageBlock>
</apex:form>
</apex:page>

Now I'm redirected to the desired folder, But nothing gets added. But if I remove the PageReference method save, I'm able to save but not redirected to the desired folder.

  • How can I save attachment to the folder as well as redirect to the folder.

  • Also, how can I make the folder url more generic?

Thanks in advance.

3

First, you're not updating the document in the save() method: you need to do DML if you want to "save" anything.

Second concerning the PageReference, one never needs to worry about the root part of the url. Try this:

PageReference pageRef = new PageReference('/015?fcf=005i00cccc3Djl8');
2

In your save method, you need to insert the record and then go to the page reference.

public class documentExt {
public Document d{get; set;}

public documentExt(ApexPages.StandardController controller) {
     d = (Document) controller.getRecord();
     d.folderid = UserInfo.getUserId(); 
}

public PageReference save() {
     insert d;
     return (new PageReference('/015?fcf=' + UserInfo.getUserId()));
}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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