You need to sign in to do that
Don't have an account?
johncusackjr
Visualforce Getting SObject Field's Value
Hi,
I have two wrappers, one for SObject objects, one for field types. Based on the field type I need to retrieve the Sobject field value inside VisualForce page.
For example:
<apex:repeat value="{!fieldsWrapper}" var="field" id="customFieldRepeater"> <apex:column headerValue="{!field.label}" value="{!f.mySobject.get(field.id).value}"/> </apex:repeat>
But this is giving Syntax error. Extra '.' error.
Is there a way to do this in VF page, or do i miss something?
Thanks,
John
Yes for sure it will work but you have to set proper type of any object to SOBject and field that you add should belong to that object.
Your class would like this
VFP
I hope it is clear to you now you will see inner class uses SOBject , and its type is Account as I pass new account () in constructor.
All Answers
Your syntax should be like this
mySobject : Should be instance of your SObject
field : Should be API name of the field
Thanks Shashikant,
But it is giving these errors when I try to save the class with your suggested settings:
Error: Insufficient Privileges
Error: Read access denied for {0}
John
How is fieldsWrapper defined?
@aballard,
FieldWrapper is like below, and İ read the values into this wrapper over describe sobject and that portion works fine:
SObjectWrapper has similar like below:
Do you have any idea about the problem?
Thanks,
John
I don't understand your page.... What is the <repeat> supposed to do? You seem to be repeating on a single object?
That is repeating some custom fields that user selects. For example if user selects 'CreatedBy, CreatedDate, Description or similar custom fields etc.' on a custom configuration tab these fields are repeated in the repeater and their header value is set using the fieldwrapper's related field label. That is working fine.
Problem is in the VALUE. This repeater is in a pageBlock and there is a SobjectWrapper that I loop over and get values. That SObject wrapper works fine for the values that are directly set on the controller over wrapper. But for that wrapper's constructor I also set the 'so' variable to an SObject. I need to read the field value of that sobject in visualforce somehow.
What is the salesforce api version of the page. It should be above 20. I would suggest to make it 22 the heighest.
in Your class MySOBject should be like this
Public SObject MySobject {get;set;}
do initialize it in constructor also like
see this example for more : http://forceschool.blogspot.com/2011/06/dynamic-binding-when-object-name-is.html
Yes Shashikant,
It should work in normal cases. But my SObject is inside a SObjectWrapper. So to access the SObject, I need to access the SObjectWrapper first.
So the value should be something
But this is giving those errors that I wrote in previous messages.
Thanks,
John
I have created an example for you hope it will help you
Controller
VFP
save above and see results.
Is it possible that this will work with the explicitly defined Account object but not with the generic SObject?
Yes for sure it will work but you have to set proper type of any object to SOBject and field that you add should belong to that object.
Your class would like this
VFP
I hope it is clear to you now you will see inner class uses SOBject , and its type is Account as I pass new account () in constructor.
Thanks Shashikant,
That solved my problem.
Regards,
John