0

Requirement: Show the Account Name, Phone and Industry as output whose Account ID will be given as an input. We have to do this using Lightning component.

Below is my Lightning Component:

 <div>

    <h2 class="header">Account Details</h2> <br/>
    <lightning:input type="text" name='input1' label="Enter Account Id" />
    <br/>  <lightning:button value= "Account Details" label= "Submit" onclick= "{!c.doClick}" />


</div>

Now I have also created a custom formula field on the Account object which gets populated by the respective Account ID of that Account. I have also written a SOQL query which worked successfully(Tried in the Query Editor).

I have to use Controller to give the functionality of the submit button. Please help me what to write there. What I tried in the controller is given below:

({
    doClick : function(component, event, helper) {
        component.set('v.outPut', (SELECT Name, Phone, Industry FROM Account where Account.Id = '{!v.input1}'));   
    }
})

I am just learning and a beginner. Please ignore any foolish mistakes i have made.

1

Great to see you're going to learn Lightning Components and ask questions. StackExchange is rather a place where you want to land whenever you get a complicated/unusual issue. To learn Lightning Components I'd suggest you go to through Trailhead, the best place to learn Salesforce.

Here's what you can take a look at to solve your case: Aura Components Basics, especially those two units: Attributes and Expressions and Handle Actions with Controllers. Good luck on your trail!

| improve this answer | |
0

I agree with Bartosz, do have a look on specific trails to have a better understanding of Ligthning. But for now I'm providing a solution which can help you.

<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" controller="AccountDetails">
<aura:attribute name="AccData" type="List" />
<div>

<h2 class="header">Account Details</h2> <br/>
<lightning:input type="text" name='input1' label="Enter Account Id" aura:id="btn1"/>
<br/>  <lightning:button value= "Account Details" label= "Submit" onclick= "{!c.doClick}" />

({
    doClick : function(component, event, helper) {
        var RecrdId = component.find("btn1").value;
        var action = component.get("c.getAcc");
        action.setParams({  AccId : RecrdId  });
        action.setCallback(this, function(response) {
            var response = action.getReturnValue();
            var state = response.getState();
            if (state === "SUCCESS") {
                component.set("v.AccData",response);
            }
    });
    }

})

You need APEX Controller in order to execute SOQL.

    public with sharing class AccountDetails {

    @AuraEnabled
    public Static List<Account> getAcc(Id AccId){
        List<Account> lstAcc = [Select id,name,phone,Industry from Account where Id =: AccId ];
        return lstAcc;
    }


}
| improve this answer | |
  • Thank you Abhishek but your Apex Controller which is executing the SOQL Quer is showing a Problem: "Illegal assignment from List<Account> to List<Account>" – Night Guy Mar 3 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.