0

I have a lightning component which calls the client side controller, which then calls the server side controller. The server side controller is linked to a method i have in one of my classes.

Component

<aura:component implements="flexipage:availableForRecordHome,force:hasRecordId" access="global">
    <aura:attribute name="loaded" type="Boolean" default="true" />
    <aura:attribute name="opportunityId" type="String" default="{!v.recordId}"/>
    <aura:attribute name="record" type="Object" />
    <aura:attribute name="simpleRecord" type="Object" />
    <force:recordData aura:id="record"
                      layoutType="FULL"
                      recordId="{!v.recordId}"
                      targetRecord="{!v.record}"
                      targetFields ="{!v.simpleRecord}"
                      mode="VIEW"/>
    <aura:attribute name="guid" type="String" default="{!v.simpleRecord.Loan_Guid__c}"/>
    <aura:attribute name="fileCreated" type="Boolean" default="{!not(empty(v.guid))}"/>
    <aura:attribute name="lastSync" type="String" default="{!v.simpleRecord.Last_Encompass_Sync__c}"/>
    <aura:attribute name="disclosuresSent" type="Boolean" default="{!not(empty(v.simpleRecord.Disclosures_Sent_Date__c))}" />
    <lightning:card title="Encompass" iconName="standard:scan_card" >
        <div class="slds-align_absolute-center" style="height: 5rem;">
            <aura:if isTrue="{! v.loaded }">
                <p><lightning:button disabled = "{!v.disclosuresSent}" variant="brand" label="{!v.fileCreated ? 'Update Loan' : 'Create Loan'}" onclick="{!c.push}"/>
                <aura:set attribute="else">
                    <lightning:spinner alternativeText="Loading" />
                </aura:set>
            </aura:if>
        </div>
        <aura:set attribute="footer">
            <p>Last Encompass Sync: <lightning:formattedDateTime value="{!v.lastSync}"/></p>
            <p class="slds-text-title"><lightning:relativeDateTime value="{!v.lastSync}"/></p>
        </aura:set>

</lightning:card>
</aura:component>

The only bit of code that matters here is really just

<lightning:button disabled = "{!v.disclosuresSent}" variant="brand" label="{!v.fileCreated ? 'Update Loan' : 'Create Loan'}" onclick="{!c.push}"/>

Where i call my client controller.

Client controller

({
    "push" : function(cmp) {
        // create a one-time use instance of the serverEcho action
        // in the server-side controller
        var action = cmp.get("c.pushToEn");
        action.setParams({ oppId : cmp.get("v.opportunityId") });

        // Create a callback that is executed after 
        // the server-side action returns
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                // Alert the user with the value returned 
                // from the server
                alert("From server: " + response.getReturnValue());

                // You would typically fire a event here to trigger 
                // client-side notification that the server-side 
                // action is complete
            }
            else if (state === "INCOMPLETE") {
                // do something
            }
            else if (state === "ERROR") {
                var errors = response.getError();
                if (errors) {
                    if (errors[0] && errors[0].message) {
                        console.log("Error message: " + 
                                 errors[0].message);
                    }
                } else {
                    console.log("Unknown error");
                }
            }
        });

        // optionally set storable, abortable, background flag here

        // A client-side action could cause multiple events, 
        // which could trigger other events and 
        // other server-side action calls.
        // $A.enqueueAction adds the server-side action to the queue.
        $A.enqueueAction(action);
    }
})

This is basically just the default example with some pieces swapped out.

Server controller

public class SfEnSyncController {
    @AuraEnabled
    public static String pushToEn(String oppId) {
        String guid = new Sf2EnTransformer(oppId).pushToEN();
        return guid;
    }
}

My server controller is really just a wrapper for another method. My other method can throw errors, i'm not sure if that's relevant though.

Either way. When i click my button i know the execution is getting into my client component. But then it just doesn't do anything. No error message, no response whatsoever. Any idea what could be causing this?

1 Answer 1

3

It doesn't look like you've told your component who your Apex controller is.

Add controller="SfEnSyncController" to your <aura:component> definition and it should see it.

Next time, there are a few things you can do to try and diagnose where the process is breaking down:

  • Open the console

Any errors thrown by javascript will appear there as well, and it can be useful to see why things failed.

  • Add debugger; instructions in your javascript code.

If you run your code with the console open, it'll stop at the point where the debugger instruction is and you can step through the code.

  • Open the Dev Console

This will show if you're apex controller is even being reached (it'll output logs)

There are many other things you could do, but the three above should probably be your starting point.

You must log in to answer this question.

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