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
sukanta Anbu 7sukanta Anbu 7 

Aura component not invoking the apex class. What error. Please help me in identifying the error

I am trying to create a lightning component which gets a URL from a field using SOQL. This URL is returned to the aura component which navigates to the external website in which a document is saved.
But my aura component is not invoking my apex class. Not able to figure the error. Please help in finding the error. Thanks in error.

This is my Lightning component
<aura:component implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,force:lightningQuickAction" access="global" 
                controller="RedirectToSP">
    
    <lightning:card title='Redirect to Sharepoint Form new' >
       <div class="slds-grid slds-m-around--small" style="width:400px;">
    <lightning:button class="slds-m-left_x-small" variant="brand" label="Sharepoint" title="Sharepoint" onclick="{!c.fetchRecord}" />
      </div>
  </lightning:card>  
</aura:component>


This is my controller
({
    fetchRecord: function(component, event, helper) {
        console.log('==3==>' + component.get("v.recordId"));
        helper.recordSearch(component, event, helper)        
    }
})


My helper
({
    recordSearch : function(component, event) {
        var recordId = component.get("v.recordId");
        var action = component.get("c.fetchRecord");
        console.log('==5==>' + recordId);
        action.SetParams({
            recordId : component.get("v.recordId")
        });
         action.setCallback(this, function(response) {
           var state = response.getState();
            if (state === "SUCCESS"){
                var urlEvent = $A.get("e.force:navigateToURL");
            console.log('Response ==60 '+response.getReturnValue());
            urlEvent.setParams({ "url": response.getReturnValue()
                               });
            urlEvent.fire();
        }
        });
    }
})

The following is my apex class
public class RedirectToSP{
 
    public static String fetchRecord (string recordId) {
        system.debug('hi');
        system.debug('id--->'+recordId);
       
      Form_Object__c logdata =[select Id, SharePoint_URL__c from Form_Object__c where Id =: recordId];
        String strAssumptionFloodOnlyUrl = logdata.SharePoint_URL__c;
        return strAssumptionFloodOnlyUrl;
    }  
}
Naveen KNNaveen KN
In the helper method we have to enque the action > $a.enqueueaction(action)

and also change the variable name in the client side 

From > var recordId = component.get("v.recordId"); to var recId = component.get("v.recordId"); sometimes having the same variable name in client and server gives an issue. 
sukanta Anbu 7sukanta Anbu 7
Hi Naveen,
Thanks for your suggestion. I figured out the mistake. I have not enqueued the action method in helper. 
 $A.enqueueAction(action);.
I added this line and it worked perfectly.