You need to sign in to do that
Don't have an account?
Ron9
addError() to a dynamic referenced field
Im stuff trying to use the field.addError() method to post validation errors on my VF page.
The standard absolute method call works fine e.g.. customObj.fieldName.addError('myString');
BUT I need to use this with fields I dynamic reference on a generic SObject.
I've tried genericObj.get('fieldname').addError('myString'); but this validates to a method does not exists error
Can anyone help me, please?
Best Regards
Ronni
To use the addError, you will need to apply it on the field. Although I am not absolutely sure of how, I would start by using field tokens.
Thank you Jerun Jose.
That is of cause true.
Does anyone know how to get a field token for a field from a SObject? Preferable by using the fields API name
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dynamic_describe_objects_understanding.htm
Hi Jerun Jose
Thanks again.
The code below shows how I tried to use the gotten SObjectField token, but this still don't give kind of field reference I need. The addError returns an no such method error. But I guess this also makes sense as the reference needs to be to a specific object instance to be able to show the error message at the right field on the page.
Any other suggestions?
Best Ronni
Can you try something in line with Dynamic visualforce?
Basically, you can do AccountObj['AccountNumber'] in VF to get the account number for the account record denoted by AccountObj . Wondering if that can be extended for this purpose.
I don't think it is possible to add the error from the VF XML. Actually I also think that obj[fieldname] is just the same as the obj.get(fieldname) in APEX. It really puzzles me if this isn't possible with dynamic field references.