function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sv Krishna ReddySv Krishna Reddy 

list type

from this picture if i select Account Account details will come, if i am select Contact contact details will be come
PriyaPriya (Salesforce Developers) 

Hi Krishna,

This is really hard to follow. Can you please elaborate your requirement.

Regards,

Priya Ranjan

Sv Krishna ReddySv Krishna Reddy
In select list type --None--,Account,Contact,cas. If iam select Account , Account pageblock should be come .if i am select Contact Contact page block shoud be come.this is my requirement
Sv Krishna ReddySv Krishna Reddy
will you get my requirement
Suraj Tripathi 47Suraj Tripathi 47
Hi Krishna,
Please Share your error here.
please discuss in detail

Thank you!

Regards,
Suraj Tripathi
Sv Krishna ReddySv Krishna Reddy
Basically I don't know how to resolve it
ANUTEJANUTEJ (Salesforce Developers) 
Hi Krishna,

I was able to find one approach that you can modify to fit accordingly, below is the link for the same can you try checking it once?

>> https://pritamshekhawat.wordpress.com/category/lightning-component/lightning-web-component/

Let me know if it helps you and close your query by marking it as the best answer so that it can help others in the future.  

Thanks.
PriyaPriya (Salesforce Developers) 

Hi Krishna,

You can try with below sample code.

In this example, if you select Account, it will display the account id, and account name. If you select Contact, it will display the contact id and contact name. Same for the lead object. You can querry as many feilds as per your requirement.

Component :- 

<aura:component controller="accountDetailController" >
    <aura:attribute name='componentString' type='String' default="Lead" 
                    description='Selected entity type'/>
        <aura:attribute name='sObjList' type='sObject[]' 
                        description = 'Returned list from server side controller'/>
            
            <aura:handler name='init' value='{!this}' action='{!c.changeEntity}' 
                          description = 'Trigger defined action on initialization of component'/>
                
                <div >
                    <lightning:select label='Entity Type'
                                      name='cmpString' 
                                      value='{!v.componentString}' 
                                      onchange='{!c.changeEntity}' >
                        <option value='Account' >Account </option >
                        <option value='Contact' >Contact </option >
                        <option value='Lead' >Lead </option >
                    </lightning:select >
                    
         <table class="slds-table slds-table_bordered slds-table_cell-buffer" >
             <tr >
                 <th >Id </th >
                 <th >Name </th >
             </tr >
             <aura:iteration items='{!v.sObjList}' var="sObj" >
                 <tr >
                     <td >{!sObj.Id} </td >
                     <td >{!sObj.Name} </td >
                 </tr >     
             </aura:iteration >
         </table >
     </div >
    
 </aura:component >

Js Controller :-
 
({
	changeEntity : function(component, event, helper) {
        var action = component.get('c.getEntity'); 
         action.setParams({
            "entityType" : component.get('v.componentString') 
        });
        action.setCallback(this, function(a){
            var state = a.getState(); // get the response state
            if(state == 'SUCCESS') {
                component.set('v.sObjList', a.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    }
})

Apex Class :-
 
public class accountDetailController {
    
    @AuraEnabled
    public static List<sObject> getEntity(String entityType){
        List<sObject> sobj = new List<sObject>();
        if(entityType != null) {
            String query = 'SELECT Name, Id FROM '+entityType ;
            sobj = database.query(query);
        }
        return sobj;
    }
}


​​​​​​​If the above information helps you, please mark it as best answer so that it can helps others in future.

Regards,

Priya Ranjan