You need to sign in to do that
Don't have an account?
qvision
Update Standard Controller Field from Extension
I am driving crazy...I created a controller extension for a custom object and a page that overrides the Edit button...except one feature the page is working as expected:
I have a picklist field Status__c in the custom object that is not displayed on VF page, but should be updated when the user saves. Basically, when the record is created it has status 'New', once updated it should be 'Resolved'.
Now, it saves all fields that are on the page or any additional methods. But how can I override the set method for Status__c?
I have a save method, that does update a specific account...but I cannot get the Status__c field set to resolved.
Do you have any idea?
public class MyExtension {
private final MyCustomObject__c myObj;
private Account account;
private final ApexPages.standardController theController;
public MyExtension (ApexPages.StandardController theController) {
MyCustomObject__c myObj = (MyCustomObject__c) theController.getRecord();
this.theController = theController;
this.myObj = [Select Id, TestField__c, Status__c from MyCustomObject__c where Id = :myObj.Id];
}
...
public PageReference save () {
update this.account; // works fine
// This one does not work
this.myObj.Status__c = 'Resolved';
update this.myObj;
// Method does not exist...
// this.myObj.setStatus__c('Resolved');
return theController.save();
}
}
I have a picklist field Status__c in the custom object that is not displayed on VF page, but should be updated when the user saves. Basically, when the record is created it has status 'New', once updated it should be 'Resolved'.
Now, it saves all fields that are on the page or any additional methods. But how can I override the set method for Status__c?
I have a save method, that does update a specific account...but I cannot get the Status__c field set to resolved.
Do you have any idea?
public class MyExtension {
private final MyCustomObject__c myObj;
private Account account;
private final ApexPages.standardController theController;
public MyExtension (ApexPages.StandardController theController) {
MyCustomObject__c myObj = (MyCustomObject__c) theController.getRecord();
this.theController = theController;
this.myObj = [Select Id, TestField__c, Status__c from MyCustomObject__c where Id = :myObj.Id];
}
...
public PageReference save () {
update this.account; // works fine
// This one does not work
this.myObj.Status__c = 'Resolved';
update this.myObj;
// Method does not exist...
// this.myObj.setStatus__c('Resolved');
return theController.save();
}
}
I think if you get rid of this line:
this.myObj = [Select Id, TestField__c, Status__c from MyCustomObject__c where Id = :myObj.Id];
and also this line from your save method:
update this.myObj;
it should work.
The update is not necessary, because the update happens in standard controller save method. As long as you get the record directly from the standardController and edit its fields directly, the standardController should take care of the rest for you.
thanks for your help. Reason why I queried for the record after the getRecord call, is that I read and update fields that are not displayed on the page itself. And if I don't show them, I understood, I need to query for them...
Now, it put them into hidden fields and it works with getRecord and to set the field values...without a specific update call...
Is there any other solutions than posting them into hidden fields?
Best regards,