I have created one custom button to call lightning component. On button click, I want to validate some opportunity field but I'm not getting field value.

Below is my component and controller code.I want to get opportunity field value (custom or standard both) and based on value I validate these fields in my code.

In my case, I want to get lookup field(DivisionDimensionTag__c) and validate lookup field is blank or not. How I achieve this?


    "showSpinner" : function (component, event, helper) {
        var spinner = component.find('spinner');
        var evt = spinner.get("e.toggle");
        evt.setParams({ isVisible : true });

    "doInit" : function(component, event, helper) {
        var name=component.find("opp");
        var stageName=name.get("v.Divisiondimensiontag__c");
        // create a one-time use instance of the serverEcho action
        // in the server-side controller
        var action = cmp.get("c.generate");
        action.setParams({ oppId : component.get("v.recordId") });

        // Create a callback that is executed after 
        // the server-side action returns
        action.setCallback(this, function(response) {

            var state = response.getState();
            if (state === "SUCCESS") {
            else if (state === "INCOMPLETE") {
                else if (state === "ERROR") {
                    var errors = response.getError();
                    if (errors) {
                        if (errors[0] && errors[0].message) {
                            console.log("Error message: " + 
                    } else {
                        console.log("Unknown error");


<aura:component controller="GenerateProducts" implements="force:lightningQuickAction,force:hasrecordid" >
    <aura:attribute name="opp" type="Opportunity" />
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:handler event="aura:waiting" action="{!c.showSpinner}"/>
    <center><ui:spinner aura:id="spinner"/></center>

1 Answer 1


You have to ask for the record first. You can avoid writing Apex Code for this specific purpose via force:recordData:

<aura:attribute name="record" type="Opportunity" />
<force:recordData recordId="{!v.recordId}"
                  recordUpdated="{!c.handleRecordLoaded}" />

In your handleRecordLoaded method, that's where you'd be able to check the value:

handleRecordLoaded: function(component, event, helper) {
  var opp = component.get("v.record"),
      tag = opp.Divisiondimensiontag__c;

Also note that the correct interface is force:hasRecordId, not force:hasrecordid. Always pay attention to your capitalization in Lightning, as everything is case sensitive.

  • In this case i'm getting only one field value that is Divisiondimensiontag__c. how if i want to get other field values in same call??
    – Harish
    Commented Jun 25, 2018 at 19:53
  • @Harish You can provide a list of fields, or you can use the layoutType attribute to get all fields on the page layout. Go ahead and look at the documentation.
    – sfdcfox
    Commented Jun 25, 2018 at 19:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .