Play Games

Search This Blog

Thursday, October 6, 2016

How to update an object on page load Salesforce

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.


No comments:

Post a Comment