1

The below controller is attempting to grab an custom object id from the URL. The logs show that it fails to assign the string var para the id value from the URL. The system.debug for var para returns null. This controller must be structured wrong, please let me know where I have skipped a step.

public class getpara_Controller {

private ApexPages.StandardController sc;
public getpara_Controller(ApexPages.StandardController sc) {
    this.sc = sc;

}

public String para = ApexPages.currentPage().getParameters().get('custompara');

custom_object__c obj = new custom_object__c(lookup__c = para);

public PageReference insertRedirect() {

    sc.save();
    PageReference endpage = new PageReference('https://www.example.com');
   endpage.setRedirect(true);
    return endpage;
}

}

1 Answer 1

2

Those getParameters() line should be inside constructor as follows:

public class getpara_Controller {

    private ApexPages.StandardController sc;
    public String para {get;set;}

    public getpara_Controller(ApexPages.StandardController sc) {
        this.sc = sc;
        para = ApexPages.currentPage().getParameters().get('custompara');
        custom_object__c obj = new custom_object__c(lookup__c = para);
    }



    public PageReference insertRedirect() {

        sc.save();
        PageReference endpage = new PageReference('https://www.example.com');
        endpage.setRedirect(true);
        return endpage;
    }

}
1
  • 1
    or the para property getter can fetch from ApexPages Commented Jul 21, 2017 at 21:36

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.