I'm designing a VF SPA that uses remote objects. Much of the page is dynamic, and I use user input to define which sObjects I look up. I wanted to know how, given a user input for a sObj, I can return the fields on that object as well as which are "nillable"/required.
A simple example of this would be a page that allows a user to create a new sObj. The user can select the type of sObj they would like to create, i.e. Contact, and the page would render all of the required fields on that sObj.
Can this be done solely via remote objects?
If not, perhaps the way to go is to use remoting and pass an apex method an object type and have the method return an array of fields that are required? In that case, how do I use javascript remote objects where you have to define which fields you want to pull from each object ()? Is it possible to just pull all fields and then, depending on the results from the remote apex class, use only a subset of them?
Thank you!
RemoteAction
and describes seem like a good approach. You will need some manual maintenance though as fields can become "required" through validation rules or triggers and you can't really interpret that programmatically.SObjectType
toList <SObjectField>
for those values. You could augment that collection with describes so you don't need to do quite as much work.