1

I have an Invocable Apex Method which I am using in a Flow and I want to call from my LWC.
I have created a separate AuraEnabled Method to call the Invocable method.

public with sharing class CustomerOrg_Helper {
    @AuraEnabled(cacheable=true)
    public static List<CustomerOrg_Controller.Response> customerOrgLogin (string customerOrgId) {
        
        CustomerOrg_Controller.Request curRequest = new CustomerOrg_Controller.Request();
            curRequest.CustomerOrgId = customerOrgId;

        List<CustomerOrg_Controller.Request> curRequests = new List<CustomerOrg_Controller.Request>();
                curRequests.add(curRequest);

        List<CustomerOrg_Controller.Response> curResponses = CustomerOrg_Controller.execute(curRequests);
                System.debug('Response:' + curResponses);   
        
        return curResponses;
    }
}

When I run the Anonymous Apex Script below I receive the expected results..

List<CustomerOrg_Controller.Response> data = 
  CustomerOrg__Helper.customerOrgLogin('a8i3G0000008ONZQA2');
System.debug('Results ' + data[0].status);

Debug = (Response:[Url=https://test.com, status=OK])

I am unable to translate this to my LWC and return the status value using the code below. The console is returning Undefined

@wire(getCustomerOrg, {customerOrgId: '$recordId'})
  WiredLogin ({data}) {
    if (data) {
      console.log('Customer Org ' + data[0].status);
    }
  }
3
  • Javascript is case-sensitive. Double check that matches.
    – Adrian Larson
    Commented Jan 24, 2023 at 3:44
  • Thanks Adrian. I checked the cases and did not see any errors Commented Jan 24, 2023 at 4:47
  • You're going to have to add more Javascript debugging. Normally my first step would be to console.debug(JSON.parse(JSON.stringify(data)) to get around the proxies.
    – Adrian Larson
    Commented Jan 24, 2023 at 15:27

1 Answer 1

0

Because I only needed the single Status field I modified the @Aura Method accordingly.

@AuraEnabled
public static String customerOrg (string customerOrgId) {
    
    CustomerOrg__Controller.Request curRequest = new CustomerOrg_Controller.Request();
        curRequest.CustomerOrgId = customerOrgId;

    List<CustomerOrg_Controller.Request> curRequests = new List<CustomerOrg_Controller.Request>();
            curRequests.add(curRequest);

    List<CustomerOrg_Controller.Response> curResponses = CustomerOrg_Controller.execute(curRequests);
            System.debug('Status:' + curResponses[0].status);   
    
    String status = curResponses[0].status;
    return status;
}

You must log in to answer this question.

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