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.


You can find the complete code here as well.

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


2 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; }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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