I am having a Custom Object, which has a field Country__c
. (Picklist).
When I am clicking the Edit page, it is going to a Custom Visualforce page. But, there in that page, Country__c
is showing blank, as if it didn’t remember the country that was chosen.
I've written Extension Controller for this particular object.
Any solution for this?
Below is my Constructor for Extension Class
Apex Code
public class MyGroupConfigControllerExt {
public final My_Config__c mpgcObj {get; private set;}
ApexPages.StandardController stdController;
public list<SelectOption> specDiscountPicklist {get; private set;}
public String selectedDiscount {get; set;}
public MyGroupConfigControllerExt(ApexPages.StandardController Controller) {
stdController = Controller;
//we cannot use addFields within test methods, so we have to wrap it in a Test.isRunningTest()
if (!Test.isRunningTest()) {
stdController.addFields(new List<String> {
'country__c'
});
}
this.mpgcObj = (My_Config__c)stdController.getRecord();
// Here I have to set mbgObj.Country__c, but how???
mpgcObj.Country__c = ?;
}
selectedDiscount
which will never be read or written. (Settingid="country"
is immaterial.) If you want the standard controller to take care of the reading and writing you will have to bind a field that is on the SObject e.g.mpgcObj.Country__c
to your input field.