0

Could someone explain what is happening within these lines in detail, as I am getting an error pointed to these lines. Also please advise on any fixes possible. thanks

approvePaymentRequest: function(component) {
        this.submitAction(component, "c.approvePaymentRequest");
      },
      submitAction: function(component, methodName) {
        component.set("v.disabled", true);
        this.enqueueAction(component, methodName, { paymentRequestId: component.get("v.paymentRequest.Id") },
          function() {
            var refreshComponentEvent = $A.get("e.c:refreshComponentEvent");
            refreshComponentEvent.setParams({ "event": "paymentRequestUpdated" });
            refreshComponentEvent.fire();
            component.find("recordLoader").reloadRecord(true);
            $A.get("e.force:refreshView").fire();
          },
          function() {
            component.set("v.disabled", false);
          }
        );
      },

APEX

  @AuraEnabled
  public static void approvePaymentRequest(Id paymentRequestId) {
    Payment_Request__c paymentRequest = [SELECT Id, Status__c, Coop_Campaign__c FROM Payment_Request__c WHERE Id = :paymentRequestId];
    paymentRequest.Approved_Date__c = Date.today();
    paymentRequest.Status__c = 'Approved';
    update paymentRequest;

    List<Coop_Campaign__c> coopCampaigns = [SELECT Id, Payment_Status__c FROM Coop_Campaign__c WHERE Id = :paymentRequest.Coop_Campaign__c AND (Payment_Status__c = 'Pending Finance Approval')];
    if (coopCampaigns.size() > 0) {
      Coop_Campaign__c coopCampaign = coopCampaigns[0];
      List<Payment_Request__c> paymentRequests = [SELECT Id FROM Payment_Request__c WHERE Coop_Campaign__c = :coopCampaign.Id AND (Status__c = 'Pending Finance Approval')];
      if (paymentRequests.size() == 0 && coopCampaign != null) {
        coopCampaign.Payment_Status__c = 'Approved';
        update coopCampaign;
      }
    }
  }

And here is the error message I get enter image description here

4
  • In your .cmp file do you have any component which has aura:id='recordLoader'. Your code is trying to look for that component in line component.find("recordLoader").reloadRecord(true); and is not able to find it?
    – manjit5190
    Commented Feb 17, 2021 at 19:20
  • @manjit5190 the cmp file does not have a component with that id. Not sure why the developer is referring to a component which does not exist.
    – sumchans
    Commented Feb 17, 2021 at 19:39
  • It can be that this component is extending a template. You can check it in top level tag, if not I would suggest reviewing the code with the developer.
    – manjit5190
    Commented Feb 17, 2021 at 19:42
  • @manjit5190 Could you please elaborate when you say this component is extending a template. The developer is long gone from the company.
    – sumchans
    Commented Feb 17, 2021 at 19:59

1 Answer 1

1
component.find("recordLoader").reloadRecord(true);

In the above code, when you get the undefined error , you need to make sure that whichever variables throws undefined error, is assigned a value to it.

In this case, component.find("recordLoader")

recordLoader would normally be an assigned ID of what would probably be another aura component in the template of the JS file.

If you are not familiar with what might be going on I would suggest you take a look at Calling Component Methods.

1
  • Thanks @glls, it is working as ofnow.
    – sumchans
    Commented Feb 17, 2021 at 20:57

You must log in to answer this question.

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