0

I have a vf page tied to a force.com site which is being used at different places on my company website like support FAQ page, new account request etc and I want to pre populate the subject field on my vf page based on the page the user is redirected from.

Is this possible?

This is what i have now <apex:inputField required="true" value="{!c.Subject}" id="subject" />

1

Yes, it is possible.

You should implement a controller Extension that modifies the field subject of your object if is there a "subject" parameter in the url, just something as following:

public class CustomExtension {
    Private ApexPages.StandardController stdController;
    Private Case c;

    public CustomExtension(ApexPages.StandardController stdController) {
        this.stdController = stdController;
        c = (case)this.stdController.getRecord();

        //Perform actions...
        updateSubject();

    }

    private void updateSubject() {
        // Check if param exists and assign it.
        if(ApexPages.currentPage().getParameters().containsKey('subject')) {
            c.subject = ApexPages.currentPage().getParameters().get('subject');
        }
    }
}

The url should contain your parameter, something as following...

/apex/CustomVisualforce?id=5001i000003COdIAAW&subject=My%20Subject
  • Hi Dahn, thanks for your response, my force.com site is XXX-XXXX.csxx.force.com/form which is hosted on mycompanydomain.com/support. Now when a user is redirected to my force.com site from my company's support page, i want the subject field on my vf page to pre-populate to 'support'. I tried ApexPages.currentPage().getParameters().get('retURL') but debug logs return NULL for retURL – Khyber Mar 11 at 19:58
  • 1
    ApexPages.currentPage().getParameters().get('YourGetParamName'). This function returns for your GET param name. Your GET param name is defined before the "=". In your previous case: subject=My%20Subject. If you wanted to add a param to your url called 'support' you should append at the end of your url "&support=yourValue" (without quotes, for instance: /apex/CustomVisualforce?id=5001i000003COdIAAW&subject=My%20Subject&support=My%20Support%20Value) and assign it to your variable binded to your visualforce. – Dahn Mar 13 at 9:18

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.