You need to sign in to do that
Don't have an account?
Bella
Updating Records Based on Input to Custom VF Page
Could someone please tell me how I would update a record from a custom vf page? I'm selecting fields from opportunities and useres and passing them to a custom vf page, then possibly editing them on that page, and those edits should be reflected in the records. How would I do that? Thanks!
You can use outputField to show the information for those not-updatable fields. They would be rendered the field as text on the page instead of input box.
Your markup would be something that look like this:
Please note, firstname and name are also fields you can't update through apex / visualforce.
Hope this solves your issue.
All Answers
very basic question ...
did you read the VF docu, especially the Standard Component Reference about apex:form, apex:inputField and about Custom Controllers and extensions?
link to VF docu
in brief:
You controller needs to query the records and store them in one or more lists.
You VF page then references these records and their fields in apex:inputFields within an apex:from.
A Save button on the page calls a action method in your controller that saves the list variables mentioned in step 1 back to the database (update).
Hope this gets you started
I tried that and I actually manage to update the fields that belong to the record itself. But when it comes to the referanced records, I get an error that reads "Error: j_id0:j_id1:j_id2:j_id13:j_id17: An error occurred when processing your submitted information." And I'm not sure what that means because I get it even if I don't change anything.
related records need to be updated in a separate call, see this page in the apex docu: update DML
if you have multiple records, you might have to iterate through the records, add the related records to a separate list, and then update that list.
Well I only have two things: an opportunity and a user that that opportunity refrences. I'm also getting something like DML currently not allowed exception. I know it has something to do with the way I'm calling my methods, but I'm really at a loss. I'll keep at it, I guess. Thanks.
if you post your VF and controller code, somebody might be able to help
:-)
Good call. Ok so this is my controller:
And then the component for the page is roughly like this:
So what I need to happen is when I update the fields in the user like name or email or whatever, it then needs to update in the object. Thanks in advance!
your page references
Shouldn't it use the outer class "findOpportunity" instead? Your save method is not part of findOpportunityProposals, so the Save button might not be able to call the Save method.
What does the debug log say?
Sorry I forgot to rename it everywhere when I posted. Pretend it all says findOpportunity. The names match and the correct fields do appear on the VF page so it's not that.
What does the debug log say?
I also would look into the source code of the output in the browser and search for that long id stated in the error message. That should give you an idea what field is causing the trouble
and o is final. Is that causing the conflict? You are returning something to o, even if the value has not changed
There are some fields on the user you can't update through Apex / Visualforce.
From the markup of your components, these fields are:
User.Lastname
User.Fax
User.Email
If you remove these fields from your component, you can save correctly.
A question, why would you want to change the user information this way? The user object manages login access for your account. If someone forgot their password and you changed their email, how would they retrieve their password?
If you intention is to switch the owner to a different user, you can probably provide a drop-down of the available user in the system.
Well the short answer is that I need to do it this way because that's my assignment. And that makes sense because those are the fields that are giving me the errors. So I guess the question now is, is there any way I can display all the fields on the VF page but make only the updatable ones actually... well, update?
You can use outputField to show the information for those not-updatable fields. They would be rendered the field as text on the page instead of input box.
Your markup would be something that look like this:
Please note, firstname and name are also fields you can't update through apex / visualforce.
Hope this solves your issue.
Thank you very much! That works perfectly ^_^