2

This page has an error. You might just need to refresh it. Error in $A.getCallback() [Cannot read property 'setParams' of undefined] Failing descriptor: {markup://c:OMSiteVisitFormLightning}

Hi,I'm getting this error.I'm new to lightning.please help...

My component-

<div style="slds">
    <div class="slds-page-header" role="banner">
  <div class="slds-grid">

    <div class="slds-col">

      <p class="slds-text-heading--label"></p>

      <h1 class="slds-text-heading--medium">Site Visit Form</h1>

    </div>

  </div>

</div>
    <br/>

<div class="slds-form--horizontal">
    <div class="slds-form-element">
        <label class="slds-form-element__label" for="inputSample2">Lead ID</label>
        <div class="slds-form-element__control">
            <ui:inputText aura:id="LeadID" class="slds-input"/>
        </div>
    </div>

    <div class="slds-form-element">
        <label class="slds-form-element__label" for="inputSample2">Mobile No.</label>
        <div class="slds-form-element__control">
            <ui:inputText aura:id="MobileNo" class="slds-input"/>
        </div>
    </div>

    <div>
        <ui:button label="Print" press="{!c.PrintData}"/>
    </div>


</div>
</div>

helper :

({
    getPrintData : function(component,LeadID,MobileNo) {
        var action = component.get("c.print");
        action.setParams({ strLeadNo : LeadID,strMobileno : MobileNo});
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS")
            {
                var url = response.getReturnValue();
                this.navigate(component,url);
                alert('url'+url+'state'+state);
            }
            else if(state === "INCOMPLETE")
            {
                alert('Incomplete');
            }
            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");
                    }
                }
            }
        });
       $A.enqueueAction(action);
    },

        navigate : function(component, event, helper) {
        var urlEvent = $A.get("e.force:navigateToURL");
        urlEvent.setParams({url});
        urlEvent.fire();
}
})

Controller -

public class OMVisitFormLightning 
{
    @AuraEnabled
    public static string print(string strLeadNo,string strMobileno)
    {
        list<Lead> lstLead;
        if(strMobileno != null && strMobileno != '')
        {
            system.debug('strLeadNo'+strLeadNo);
            system.debug('strMobileno'+strMobileno);
            lstLead = [select id, name, OM_Lead_Number__c, MobilePhone, OM_Project__c, OM_Project__r.OM_SM_User__c from  Lead where 
                              OM_Lead_Number__c =:strLeadNo and MobilePhone =: strMobileno];
            system.debug('strLlstLeadeadNo'+lstLead);
            if(lstLead != null && lstLead.size() > 0)
            {
                if(lstLead[0].OM_Project__c != null)
                {
                    if(lstLead[0].OM_Project__r.OM_SM_User__c != null)
                    {
                        lstLead[0].ownerid = lstLead[0].OM_Project__r.OM_SM_User__c;
                        try
                        {
                            update lstLead;
                            string URL = 'https://omkar--sfdev--c.cs6.visual.force.com/apex/omGuestProfileFormPdf?id='+lstLead[0].id;
                            return URL;
                            /*PageReference objReference = new PageReference('/apex/omGuestProfileFormPdf?id='+lstLead[0].id);
                            objReference.setRedirect(true);
                            return objReference; */
                        }
                        catch(exception e)
                        {
                            //ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, e.getmessage()));
                            return null;
                        }
                    }
                    else
                    {
                        //ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No SM Found For this Project.'));
                        return null;
                    }
                }
                else
                {
                    //ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'No Project found unser the lead.'));
                    return null;
                }

            }
            else
            {
                //ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please Ensure that you have entered correct Mobile No. and Lead.'));
                return null;
            }
        }

        else
        {
            //ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR,'Please Enter Required Details' ));
            return null;
        }
        return null;
    }
}

I want to pagereference to another page but instead getting the error.

$A.getCallback() [Cannot read property 'setParams' of undefined] Failing descriptor: {markup://c:OMSiteVisitFormLightning}

Please help

6
  • Can you please try wrapping content of helper functions(getPrintData and navigate) inside if(component.isValid()){.....} ?
    – SE_User
    Commented Dec 14, 2016 at 9:59
  • if (component.isValid() && state === "SUCCESS") { var url = response.getReturnValue(); this.navigate(component,url); alert('url'+url+'state'+state+component.isValid()); } You mean something like this ?? Commented Dec 14, 2016 at 10:32
  • No, getPrintData : function(component,LeadID,MobileNo) { if(component.isValid()){ Your current code }} Similar ly for the other function too..
    – SE_User
    Commented Dec 14, 2016 at 11:59
  • Done..but still facing some issueThis page has an error. You might just need to refresh it. Error in $A.getCallback() [response is not defined] Failing descriptor: {markup://c:OMSiteVisitFormLightning} Commented Dec 14, 2016 at 12:53
  • Shouldn't you write urlEvent.setParams({url: "your url"}); instead of urlEvent.setParams({url});
    – Kevan
    Commented Feb 13, 2017 at 7:06

3 Answers 3

0

Maybe you have to declare the event with aura:registerevent in the XML part of the component, to declare to your component that it can fire such event

0

I can redirect to another page now. I had to use windows.open:

({
    getPrintData : function(component,LeadID,MobileNo) {
        if(true){ //component.isValid()
        var action = component.get("c.print");
        console.log('action -- ---');
        console.log(action);
        action.setParams({"strLeadNo" : LeadID,
                          "strMobileno" : MobileNo});
        action.setCallback(this, function(response){
            var state = response.getState();
            if (state === "SUCCESS")
            {
                var url = response.getReturnValue();
                this.navigate(component,url);
                //alert('url : '+url+'  state'+state+'isValid'+component.isValid());
            }
            else if(state === "INCOMPLETE")
            {
                alert('Incomplete');
            }
            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");
                    }
                }
            }
        });
       $A.enqueueAction(action);
        }},

        navigate : function(component, url) {

        window.open(url,"_self");

        }}
})
0

Did you specify the controller in your .cmp file?

FIle should look like this:

<aura:component controller="OMVisitFormLightning">

!component body!

</aura:component>
1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Commented Sep 7, 2023 at 15:15

You must log in to answer this question.

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