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
John MJohn M 

getting error action.SetCallback is not a function

Hi,
I am new to Lightning please help me with this. I am getting the following error:
Uncaught Action failed: c:LinkToAttachment$controller$preview [action.SetCallback is not a function]
when I try to run my lightning component on button click. Please Help
Here is my Code:
LinkToAttachment.cmp
<aura:component controller = "LinkToAttachment" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes" access="global" >
   <aura:attribute name="contentId" type="String" default="0691h0000001LU8AAM"/>
<lightning:button variant="brand" label="Quick Reference Guide" onclick="{!c.preview }" />
</aura:component>
LinkToAttachmentController.js
({
   preview : function(component, event, helper) {
       var action = cmp.get("c.openfile1");
       action.SetCallback(this, function(response){
       var state = response.getState();
           if(state == "SUCCESS"){
               alert("From server: " + response.getReturnValue());
       var Cdid = response.getReturnValue();
       cmp.set("v.contentId", Cdid);
       $A.get('e.lightning:openFiles').fire({
        recordIds: ["v.contentId"]
    });
           }
});
       $A.enqueueAction(action);
   }
})

LinkToAttachment.apxc
public with sharing class LinkToAttachment {
    
    @AuraEnabled
    Public static List<ContentDocument> openfile1(){
        List<ContentDocument> Cdid=[SELECT id FROM ContentDocument 
                             where Title=' Test Document'];
        return Cdid;
    } 

}

Thanks
 
John TowersJohn Towers
You're defining the action using 
var action = cmp.get("c.openfile1");

but your component reference is 'component' not 'cmp'. Try:
 
var action = component.get("c.openfile1");
Narender Singh(Nads)Narender Singh(Nads)

Hi,
You are using incorrect variable name 'cmp' and the variable you have passed in your preview function is 'component'.

In your Js controller change lines 3 and 9 to this:
 

var action = component.get("c.openfile1"); // REPLACE LINE 3 WITH THIS
component.set("v.contentId",Cdid); // REPLACE LINE 9 WITH THIS

Let me know if it helps.
Thanks
Prabhat Sharma 6Prabhat Sharma 6
Two things,

1. As John and Narendra have already hightlighted, you're referring incorrect variable name. 
Replace line no. 3 and no. 9 referring "cmp" with "component".
2. The "SetCallback" first character "S" should be in lower case i.e "setCallback".