You need to sign in to do that
Don't have an account?
Tyler Zika
Use standard controller and custom controller together
I have a VF page with a custom controller. It has a sign up form to create a new contact. When I tried adding a picklist field for the MailingStateCode field, I was unsure how to get the prepopulated values. Do I make a setter and getter for it? If so how? If not, what shall I do?
Let me know if it really does :)
:
All Answers
Hi Tyler,
It would be a better option to initialize field in constructor rather than creating a getter setter for this.
Thanks,
Gaurav
But you can implment your above logic by use of extension classes (a page can have multiple extensions)
https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_controller_extension.htm
Let me know if you need any more help.
If you are using the custom controller, then just create a instansce of the contact object and use that in the VF page. Below ids the sample code:
Now u can access any of your contact object fields in your VF page like {!conRecord.Fieldname}
Please let me know if this works for you.
And my controller
It's giving me an error.
Hi Tyler,
Can you please post the error message.
Thanks,
Gaurav
There is no such Standard field MailingStateCode exist for the Contact Object. The standard field is MailingState. If you are using any custom filed then use it like MailingStateCode__c.
Please try and let me know if it helps.
Below is the list of all standard field on Contact object. MailingStateCode is a valid field. Please post the error message so that we can further help you out on this.
Thanks,
Gaurav
I don't get a specific error, it just said Error: Visualforce page couldn't load.
I spoke with a developer I work with. I guess the customer user in our system can't edit a Contact record, and he recommend doing this.
Controller
Visualforce page
Now I don't get an error, and the picklist displays, but it has no values.
Let me know if it works for you.
The states appear in my picklist for the form. But now my visualforce page is getting an error of
"Error: Read only property 'CommunitiesSSignUpController.StateCodes'"
So the state codes do not appear when there is a getter/setter
Let me know if it really does :)
: