1

Is it possible to update an Object from a Vf page while pushing a button.

We have this Object (Products) and it has almost 500 fields and some of the triggers are fired when the object is updated, for now it has to be an human interaction by clicking on 'Edit' and 'Save'. So my goal is to create a VF Page (Updates) which has a button and allows me to update products object when I click on it. This will be huge because some other Objects are having the same problem. Please let me know if you need more details.

2
  • 1
    Short answer is yes, but we need a lot more information on what you are trying to do to actually provide you with any help. Commented Feb 18, 2014 at 16:44
  • Ok, we have this Object (Products) and it has almost 500 fields and some of the triggers are fired when the object is updated, for now it has to be an human interaction by clicking on 'Edit' and 'Save'. So my goal is to create a VF Page (Updates) which has a button and allows me to update products object when I click on it. This will be huge because some other Objects are having the same problem. Please let me know if you need more details. Thank you!
    – Carlos
    Commented Feb 18, 2014 at 16:54

1 Answer 1

5

Yes its possible. The command button will look like:

<apex:commandButton action="{!updateObject}" value="Update"/>

The method in the controller will look something like:

public PageReference updateObject() {
    myObject.dateField__c = Date.today();
    update myObject;
    return null;
}
9
  • Thank you for the code, I just want to make sure if this code will update the whole object?
    – Carlos
    Commented Feb 18, 2014 at 16:56
  • Im not sure what you mean by "update the whole object"
    – BarCotter
    Commented Feb 18, 2014 at 17:01
  • Sorry that was a silly question.. I am very new in apex. Let say I want to use a date field in the object and while I click the button I want to display today's date and Update the object, how would you do that? I appreciate your help!
    – Carlos
    Commented Feb 18, 2014 at 17:08
  • Ive updated my answer so that it sets a date field to the current date. The update will cause all the update triggers you have on that object to fire.
    – BarCotter
    Commented Feb 18, 2014 at 17:18
  • Thank you so much! I will try it and let you know the outcome
    – Carlos
    Commented Feb 18, 2014 at 17:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .