You need to sign in to do that
Don't have an account?

Refresh object after update in Controller
I have added a custom field to the User object and I want to update that object and have it available in my javascript. As of now I can get the object but once I update it the visualforce page still gets the old value. I suspect my problem is related to my initial query not being refreshed but rerunning it has no effect. Here is what I have thus far.
public class CustomController {
public User user {get; set;}
public CustomController(ApexPages.StandardController stdController) {
this.user = [select Id, CustomField__c from User where Id=:UserInfo.getUserId() limit 1];
}
public void updateUser() {
update user;
}
}
<apex:page showHeader="false" controller="CustomController">
<apex:form >
<apex:actionFunction name="updateCustomField" action="{!updateUser}" rerender="tokenBlock" >
<apex:param id="customField" name="customField" value="" assignTo="{!User.CustomField__c}"/>
</apex:actionFunction>
</apex:form>
:
:
updateCustomField('new value');
So this all works but if I try to get that value via '{!$user.CustomField__c}' I get the old value... What am I missing.
Thanks
have your controller method return PageReference instead of void, and return null.
public PageReference updateUser(){
return null;
}
Thanks for replying!
I tried that:
public PageReference updateUser() {
update user;
return null;
}
It saves the object correctly but my call to {!$user.CustomField__c} gives me the old value still and not the updated one. What am I missing?
How can I get the variable from the controller at runtime?