Apex Class:
public class UpdateObjectOnPageLoadController {
public UpdateObjectOnPageLoadController () {
}
public void updateUser() {
List<User> lstUser = [select id,name,Title from user where id=:UserInfo.getUserId()];
lstUser[0].title ='SFDC King';
update lstUser[0];
system.debug('USER UPDATED :'+lstUser[0]);
}
}
Visualforce Page :
<apex:page controller="UpdateObjectOnPageLoadController" action="{!updateUser}">
</apex:page>
Output: Once we run the above vf page,The title of currently loggedin user will get updated to 'SFDC King' as shown in the image below.
public class UpdateObjectOnPageLoadController {
public UpdateObjectOnPageLoadController () {
}
public void updateUser() {
List<User> lstUser = [select id,name,Title from user where id=:UserInfo.getUserId()];
lstUser[0].title ='SFDC King';
update lstUser[0];
system.debug('USER UPDATED :'+lstUser[0]);
}
}
Visualforce Page :
<apex:page controller="UpdateObjectOnPageLoadController" action="{!updateUser}">
</apex:page>
Output: Once we run the above vf page,The title of currently loggedin user will get updated to 'SFDC King' as shown in the image below.
No comments:
Post a Comment