Cannot read property 'state' of undefined
I am new at coding and receiving an error "Action failed: c:NewMarketingTicket$controller$init [Cannot read property 'state' of undefined]" when accessing a custom LC button override when creating a new record. Can I please have some help resolving this error? Thank you in advance! Edit: Controller below fixed above error, but produces new error: Action failed: c:NewMarketingTicket$controller$init [action is not defined] Component Controller
({ init : function (component) { // Find the component whose aura:id is "flowData" var flow = component.find("flowData"); var pageRef = component.get("v.pageReference"); action.setCallback(this, function(response) { var state = pageRef.getState; if (state === "SUCCESS") { console.log("From server: " + response.getReturnValue() + 'n' + JSON.stringify(response.getReturnValue())); } else if (state === "INCOMPLETE") { alert("Continuation action is 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"); } } var base64Context = state.inContextOfRef; if (base64Context.startsWith("1.")) { base64Context = base64Context.substring(2); } var addressableContext = JSON.parse(window.atob(base64Context)); }); //Pass input IDs var inputVariables = [ { name : 'recordId', type : 'String', value : '{!v.recordId}' }, { name : 'TicketsInfoId', type : 'String', value : '{!v.recordId.Ticket_Number__c.Id}' } ]; //Run flow flow.startFlow("Marketing_Ticket_Tracker_New_Record", inputVariables); }})
Edit: New code Cmp
JS controller
({ init : function (component) { // Find the component whose aura:id is "flowData" var flow = component.find("flowData"); var pageRef = component.get("v.pageReference"); var action = component.get("c.getVenueAttendees"); action.setParams({ paramName : component.get("v.recordId") }); action.setCallback(this, function(response) { var state = pageRef.getState; if (state === "SUCCESS") { console.log("From server: " + response.getReturnValue() + 'n' + JSON.stringify(response.getReturnValue())); } else if (state === "INCOMPLETE") { alert("Continuation action is 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"); } } var base64Context = state.inContextOfRef; if (base64Context.startsWith("1.")) { base64Context = base64Context.substring(2); } var addressableContext = JSON.parse(window.atob(base64Context)); }); //Pass input IDs var inputVariables = [ { name : 'recordId', type : 'String', value : '{!v.recordId}' }, { name : 'TicketsInfoId', type : 'String', value : '{!v.recordId.Ticket_Number__c.Id}' } ]; //Run flow flow.startFlow("Marketing_Ticket_Tracker_New_Record", inputVariables); }})
Apex Controller
public with sharing class MarketingTickets { @AuraEnabled(cacheable=true) public static ListgetVenueAttendees(String VenueTicketId) { return [SELECT Ticket_Number__r.Id, Id FROM Venue_Attendee__c WHERE Ticket_Number__r.Id = :VenueTicketId LIMIT 1]; }}
Buddy, for cannot read property 'state' of undefined error, just include this before:
var action = cmp.get("c.myApexMethodName"); action.setParams({ paramName : cmp.get("v.ParamValue") }); // Create a callback that is executed after // the server-side action returns action.setCallback(this, function(response) { //logic }
Also do not forget to include the controller reference in your aura:component tag