0

I need to create a custom lightning component(exact same as layout - Object Name - Rider) and add it on object actions(Object name - Order) . On click of button, the lightning component should pop up. I have done till here.

problem statement
some set of fields should be pre populated from (object name - Population). Here i need to pass the current objectid(orderId) and query from population object and prepopulate on custom component like Rider.name = population.name and Rider.Phone = population.Phone

cmp

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" controller="RFO_OrderController">
         <aura:attribute name="orderRecord" type="Order" /> 
    <aura:attribute name="recordId" type="String" />
                <aura:handler name="init" value="{!this}" action="{!c.doInit}"/> 
                <lightning:recordForm objectApiName="Contact"
                                      layoutType="Full"
                                      targetRecord="{!v.account}"
                                      columns="2"
                                      aura:id="test"/> 
            </aura:component>

controller.js

({
    doInit : function(component, event, helper){
        var orderId = component.get("v.recordId");

        var action = component.get("c.getOrderDetails");

        action.setParams({
            "orderId" : orderId
        });       

        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                //following hardcode is also not working.
                component.set("v.firstname", 'test');
                //how to setup value from query
            }
        });
        $A.enqueueAction(action);
    },
})

public class RFO_OrderController {

    @AuraEnabled 
    public static Order getOrderDetails(String orderId){
        population__C pop = [SELECT Id, Name, OrderNumber, ContractId, Type, AccountId, RFO_PriceClassification__c, 
                     RFO_LeaseTerms__c, RFO_LeaseRate__c, RFO_Commodity_lookup__c, RFO_Quantity__c,
                     RFO_ReportingMarks__c, RFO_RunningNumbers__c, RFO_CarType__c
                     FROM population__c where Id = :orderId];
        System.debug('pop :'+pop );
        return pop ;
    }

}

1 Answer 1

0

You need to create an attribute of type Population__c and set the response from server to this attribute. You're method name says getOrderDetails but you are returning a population record. Also the return type of your method is Order. This needs to be corrected.

Component:

<aura:attribute name="populationRecordReturned" type="Population_c" /> 

Controller.js

({
    doInit : function(component, event, helper){
        var orderId = component.get("v.recordId");

        var action = component.get("c.getOrderDetails");

        action.setParams({
            "orderId" : orderId
        });       

        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS") {
                //Set attribute , the value of population returned from apex.
                component.set("v.populationRecordReturned", response.getReturnValue());
            }
        });
        $A.enqueueAction(action);
    },
})

Apex:

public class RFO_OrderController {

    @AuraEnabled 
    public static Population__c getOrderDetails(String orderId){
        population__C pop = [SELECT Id, Name, OrderNumber, ContractId, Type, AccountId, RFO_PriceClassification__c, 
                     RFO_LeaseTerms__c, RFO_LeaseRate__c, RFO_Commodity_lookup__c, RFO_Quantity__c,
                     RFO_ReportingMarks__c, RFO_RunningNumbers__c, RFO_CarType__c
                     FROM population__c where Id = :orderId];
        System.debug('pop :'+pop );
        return pop ;
    }

}

You must log in to answer this question.

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