Display Generic sObject in Lightning

 

In the last post we study how we can iterate map in Lightning. There is one more thing which we face many time is dynamic field binding. Visualforce wit dynamic field binding we can dynamically create field instance but in lightning this is a major limitation.

Today we will see how we can use dynamic sObject binding in visualforce. For this we will create a sample component to display dynamic fields.

Here we will create app to get Object details. for demo I have select Account object we can select any object here. We can also select any fields here including the parent fields(cross reference field).

Now we will pass the object and field name in another component. Where we will display them on UI.

So here we are using JavaScript to to get data from the field. This is similar of what we have done in Map Iteration post.

To display on UI I am using lightning:formattedText we can also use any other component as well.

dYnamicsObject.png

You can find the complete code here as well.

DO you want to add anything let me know in comments section. Happy programming 🙂

Advertisements

5 thoughts on “Display Generic sObject in Lightning

  1. Is there anywhere to query data and depend on objects that lighting component display? Let me explain my requirement.

    1.there are 2 objects that was using same my lighting component that i want to create
    2.one object, i want to query by where objecta__c= RecordID and another, i want to query by where accountID=recordID

    Could you please help me to guide with this

    1. Yes, Just create a new attribute where we define our where condition and then pass same in controller. In controller Add this in where condition if(String.isNotBlank(whereCond)) { query+= ‘ and ‘+whereCond; }

  2. I am using same for input fields, i am able to display existing value in input field, but when i am updating with new value its not updating. when I debugged the new value is not getting its displaying old value. I am updating in parent component

    Can you please help on this how to use for input fields(child component)

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.