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
degmodegmo 

Lightning Component Apex Controller constructor

Hi,
I have a custom object called Transaction and on its page layout I have a button that uses a lightning component to create related Transaction_Line_Item__c records with 2 different record types.

Component:
<aura:component controller="myController" implements="flexipage:availableForAllPageTypes,force:hasRecordId" access="global">
    <div class="slds-grid_vertical-align-center ">
    <lightning:button class="slds-m-top_small" label="Run" onclick="{!c.createLineItems}" />
     </div>
</aura:component>
Controller:
({
    createLineItems : function(component, event, helper) {
        var action = component.get("c.processLineItems");
        action.setParams(
            {
                'currentId' : component.get("v.recordId")
            }
        );
        action.setCallback(this, function(response) {
            var state = response.getState();
            if(state === "SUCCESS")  {
                //display success message
            }else{
                //display error message
            }
        });
        $A.enqueueAction(action);
    })
Apex Controller:
public class myController{

    @AuraEnabled
    public static List<Transaction_LineItems__c>processLineItems(String currentId){ 
         List<Transaction__c> curTransaction = [SELECT Id, field1, field2, field3 FROM Transaction__c WHERE Id=:currentId];

   //Delete all existing line items first
   deleteLineItems(curTransaction);
   //Start creating new line items
   List<Transaction__Lineitem__c> newTranLineItem = createNewLineItems(curTransaction);
}
public List<Transaction_Lineitem__c> createNewLineItems(Transaction__c curTransaction) {

}
}
I have a couple of questions:
1.  In my "processLineItems" method, I am querying the same record that initiated the process.  I need the extra fields and that is why I am querying it there but is it more efficient for the lightning component to pass the object with the fields I need so I don't have to do a SOQL query?
2.  I am passing the Transaction__c object from one method to another and instead of that, can I declare a static varible of type Transaction__c and set it once inside "processLineItems"?
3.  I am creating two types of Transaction_Line_Item__c records (2 record types).  Is it again to efficient to have the record type Ids defined as static and set them once inside "processLineItems"?