+ Start a Discussion
Jim Minichiello 2Jim Minichiello 2 

Lightning Component No Longer Returns Object Query Results

I am not a developer, and our in-house developer left the company, so I need help. We have a Lightning Component that queries a custom object called Suite Products and returns all records. This component stopped working on Monday, 12/19/2018. I checked the browser console in both Firefox and Chrome, and I am getting an error that says "Unable to getSuiteProducts". Here is the code that the error references:
 
(function(){ return (
function () {$A.componentService.addComponentClass("markup://c:ContractBuilderSuiteProducts",function() {
return {
  "meta":{
    "name":"c$ContractBuilderSuiteProducts",
    "extends":"markup://aura:component"
  },
  "controller":{
    "init":function(component, event, helper) {
		var action = component.get('c.getSuiteProducts');
		action.setStorable();
		action.setCallback(this, function(a){
			var state = a.getState();
			if(state === 'SUCCESS'){
				var result = a.getReturnValue();
				component.set('v.products', result);
				helper.initTable(component, event, result, component.get('v.contractElementId'));
				
			}
			else{
				console.warn('Unable to getSuiteProducts');
			}
		});
		$A.enqueueAction(action);
	},
    "attachProducts":function(component, event, helper) {
		helper.attachProducts(component, event, component.get('v.contractElementId'), component.get('v.contractElementType'), component.get('v.selectedIds'));
	},
    "destroy":function(component, event, helper) {
		component.destroy();
	}
  },
  "helper":{
    "initTable":function(component, event, result, contractElementId) {
		var dataSet = [];
		var columnHeaders = [];
		var i;
		for(i = 0; i < result.length; i++){
			
			dataSet.push({
				'id' : result[i].Id,
				'contractelement' : (result[i].Contract_Element__c || ''),
				'event' : (result[i].MSE_Event__r.Name || ''), 
				'suite' : (result[i].Suite__r.Name || ''), 
				'hometeam' : (result[i].Home_Team__c || ''),
				'gamecolor' : (result[i].Game_Color__c || ''),
				'opposingteam' : (result[i].Opposing_Team__c || ''),
				'eventdate' : (moment(result[i].Event_Date__c).format('M/D/YYYY') || ''),
				'status' : (result[i].Status__c || ''),
				'recordtype' : (result[i].RecordType.Name || ''),
				'heldfor' : (result[i].Account_Held_For__c || '')
			});
		}

		


		$(document).ready(function() {
			if ( $.fn.dataTable.isDataTable( '#suiteproducts' ) ){
				$("#suiteproducts").dataTable().fnDestroy();
				console.log('destroyed first.');
			}

			$.fn.dataTable.moment = function ( format, locale ) {
			    var types = $.fn.dataTable.ext.type;

			    
			    types.detect.unshift( function ( d ) {
			        return moment( d, format, locale, true ).isValid() ?
			            'moment-'+format :
			            null;
			    } );

			    
			    types.order[ 'moment-'+format+'-pre' ] = function ( d ) {
			        return moment( d, format, locale, true ).unix();
			    };
			};

			$.fn.dataTable.moment('M/D/YYYY');
			var table = $('#suiteproducts').DataTable( {
			 	destroy: true,
			 	scrollY: 200,
				data : dataSet,
				select : 'single',
		        columns: columnHeaders,
		        pagination : true,
		        search : true,
		        columns : [
		            { data: "event", title : "Event Name" },
		            { data: "eventdate", title : "Event Date" },
		            { data: "suite", title : "Suite" },
		            { data: "hometeam", title : "Home Team" },
		            { data: "opposingteam", title : "Opposing Team" },
		            { data: "status", title : "Status" },
		            { data: "heldfor", title : "Held For/Account Name" }
		        ],
		        initComplete : function () {

	                this.api()
			        		.column(5)
			        		.data()
		        			.unique()
		        			.each(function ( d, j ) {
			                    $('#status').append( '<option value="'+d+'">'+d+'</option>' )
			                } );
			        component.set('v.spinner', false);

  		        },
  		        "createdRow": function ( row, data, index ) {
		            if ( data.contractelement == contractElementId ) {
		                $('td', row).addClass('table-primary-permanent');
		            }
		        }
		    } );

            $('#selectClose').on('click', function(){
            	$('#suiteproducts').html('<table id="suiteproducts" class="table table-bordered slds-table slds-table_bordered"></table>');
            	console.log('table was destroyed!');
            });

		    $('#suiteproducts tbody').on( 'click', 'tr', function () {
		        var data = table.row( this ).data();

		        if ( data.contractelement != contractElementId ) {
			        var selectedIds = component.get('v.selectedIds');
			        var index = selectedIds.indexOf(data);
			        if(index < 0)
			        	selectedIds.push(data);
			        else{
			        	selectedIds.splice(index, 1);
			        }

			        console.log('Selected: ' + JSON.stringify(selectedIds));
			        component.set('v.selectedIds', selectedIds);

			        if ( $(this).hasClass('table-primary') ) {
			            $(this).removeClass('table-primary');
			        }
			        else {
			            $(this).addClass('table-primary');
			        }

			    }
		    });

		    $('#eventdate').on( 'change', function () {
		    	var value = moment(this.value).format('M/D/YYYY');
		    	if(!moment(this.value).isValid()){
		    		value = '';
		    	}
		        table
		        	.columns(1)
		        	.search(value)
		        	.draw();

		    });

		    $('#event').keyup( function () {
			    table
			        .columns( 0 )
			        .search( this.value )
			        .draw();
			});

			$('#hometeam').keyup( function () {
			    table
			        .columns( 3 )
			        .search( this.value )
			        .draw();
			});

			$('#opposingteam').keyup( function () {
			    table
			        .columns( 4 )
			        .search( this.value )
			        .draw();
			});

		    $('#suite').keyup( function () {
			    table
			        .columns( 2 )
			        .search( this.value )
			        .draw();
			});

	        $('#status').on( 'change', function () {
	            table
			        .columns( 5 )
			        .search( this.value )
			        .draw();
	        });

		} );
	},
    "attachProducts":function(component, event, contractElementId, contractElementType, selectedIds) {
		var objects = [];
		for(var i = 0; i < selectedIds.length; i++){
			var status = '';
			if(contractElementType === 'ESPP'){
				status = 'ESPP';
			}
			else if(contractElementType === 'Suite Rental'){
				status = 'Sold';
			}
			else if(contractElementType === 'Suite Lease'){
				status = 'Lease';
			}
			else{

			}

			objects.push({"Id" : selectedIds[i].id, "sobjectType" : "Suite_Products__c", "Contract_Element__c" : contractElementId, "Status__c" : status});
		}

		console.log('Objects to attach: ' + JSON.stringify(objects));

		component.set('v.spinner', true);
		var action = component.get('c.addProducts');
		action.setParams({ 'products' : JSON.stringify(objects) });
		action.setCallback(this, function(a){
			var state = a.getState();
			component.set('v.spinner', false);
			if(state === 'SUCCESS'){
				component.destroy();
			}
			else{
				alert('There is an error!');
			}
		});
		$A.enqueueAction(action);
	}
  }
};
});
 }
)})();
//# sourceURL=https://mse.lightning.force.com/components/c/ContractBuilderSuiteProducts.js
I'm not sure if this information can help you diagnose the problem or not. Any help would be greatly appreciated. 
 
Karan Shekhar KaulKaran Shekhar Kaul
Hi Jim,

Paste below code. Referesh the page where this lighting component is places. Open inspect element & see what errors is shown in console on Line number 22. It will help to debug if you can share the apex code as well? specially getSuiteProducts method. 
 
(function(){ return (
function () {$A.componentService.addComponentClass("markup://c:ContractBuilderSuiteProducts",function() {
return {
  "meta":{
    "name":"c$ContractBuilderSuiteProducts",
    "extends":"markup://aura:component"
  },
  "controller":{
    "init":function(component, event, helper) {
		var action = component.get('c.getSuiteProducts');
		action.setStorable();
		action.setCallback(this, function(a){
			var state = a.getState();
			if(state === 'SUCCESS'){
				var result = a.getReturnValue();
				component.set('v.products', result);
				helper.initTable(component, event, result, component.get('v.contractElementId'));
				
			}
			else{
				var errors = response.getError();
				console.log(errors);
				console.warn('Unable to getSuiteProducts');
			}
		});
		$A.enqueueAction(action);
	},
    "attachProducts":function(component, event, helper) {
		helper.attachProducts(component, event, component.get('v.contractElementId'), component.get('v.contractElementType'), component.get('v.selectedIds'));
	},
    "destroy":function(component, event, helper) {
		component.destroy();
	}
  },
  "helper":{
    "initTable":function(component, event, result, contractElementId) {
		var dataSet = [];
		var columnHeaders = [];
		var i;
		for(i = 0; i < result.length; i++){
			
			dataSet.push({
				'id' : result[i].Id,
				'contractelement' : (result[i].Contract_Element__c || ''),
				'event' : (result[i].MSE_Event__r.Name || ''), 
				'suite' : (result[i].Suite__r.Name || ''), 
				'hometeam' : (result[i].Home_Team__c || ''),
				'gamecolor' : (result[i].Game_Color__c || ''),
				'opposingteam' : (result[i].Opposing_Team__c || ''),
				'eventdate' : (moment(result[i].Event_Date__c).format('M/D/YYYY') || ''),
				'status' : (result[i].Status__c || ''),
				'recordtype' : (result[i].RecordType.Name || ''),
				'heldfor' : (result[i].Account_Held_For__c || '')
			});
		}

		


		$(document).ready(function() {
			if ( $.fn.dataTable.isDataTable( '#suiteproducts' ) ){
				$("#suiteproducts").dataTable().fnDestroy();
				console.log('destroyed first.');
			}

			$.fn.dataTable.moment = function ( format, locale ) {
			    var types = $.fn.dataTable.ext.type;

			    
			    types.detect.unshift( function ( d ) {
			        return moment( d, format, locale, true ).isValid() ?
			            'moment-'+format :
			            null;
			    } );

			    
			    types.order[ 'moment-'+format+'-pre' ] = function ( d ) {
			        return moment( d, format, locale, true ).unix();
			    };
			};

			$.fn.dataTable.moment('M/D/YYYY');
			var table = $('#suiteproducts').DataTable( {
			 	destroy: true,
			 	scrollY: 200,
				data : dataSet,
				select : 'single',
		        columns: columnHeaders,
		        pagination : true,
		        search : true,
		        columns : [
		            { data: "event", title : "Event Name" },
		            { data: "eventdate", title : "Event Date" },
		            { data: "suite", title : "Suite" },
		            { data: "hometeam", title : "Home Team" },
		            { data: "opposingteam", title : "Opposing Team" },
		            { data: "status", title : "Status" },
		            { data: "heldfor", title : "Held For/Account Name" }
		        ],
		        initComplete : function () {

	                this.api()
			        		.column(5)
			        		.data()
		        			.unique()
		        			.each(function ( d, j ) {
			                    $('#status').append( '<option value="'+d+'">'+d+'</option>' )
			                } );
			        component.set('v.spinner', false);

  		        },
  		        "createdRow": function ( row, data, index ) {
		            if ( data.contractelement == contractElementId ) {
		                $('td', row).addClass('table-primary-permanent');
		            }
		        }
		    } );

            $('#selectClose').on('click', function(){
            	$('#suiteproducts').html('<table id="suiteproducts" class="table table-bordered slds-table slds-table_bordered"></table>');
            	console.log('table was destroyed!');
            });

		    $('#suiteproducts tbody').on( 'click', 'tr', function () {
		        var data = table.row( this ).data();

		        if ( data.contractelement != contractElementId ) {
			        var selectedIds = component.get('v.selectedIds');
			        var index = selectedIds.indexOf(data);
			        if(index < 0)
			        	selectedIds.push(data);
			        else{
			        	selectedIds.splice(index, 1);
			        }

			        console.log('Selected: ' + JSON.stringify(selectedIds));
			        component.set('v.selectedIds', selectedIds);

			        if ( $(this).hasClass('table-primary') ) {
			            $(this).removeClass('table-primary');
			        }
			        else {
			            $(this).addClass('table-primary');
			        }

			    }
		    });

		    $('#eventdate').on( 'change', function () {
		    	var value = moment(this.value).format('M/D/YYYY');
		    	if(!moment(this.value).isValid()){
		    		value = '';
		    	}
		        table
		        	.columns(1)
		        	.search(value)
		        	.draw();

		    });

		    $('#event').keyup( function () {
			    table
			        .columns( 0 )
			        .search( this.value )
			        .draw();
			});

			$('#hometeam').keyup( function () {
			    table
			        .columns( 3 )
			        .search( this.value )
			        .draw();
			});

			$('#opposingteam').keyup( function () {
			    table
			        .columns( 4 )
			        .search( this.value )
			        .draw();
			});

		    $('#suite').keyup( function () {
			    table
			        .columns( 2 )
			        .search( this.value )
			        .draw();
			});

	        $('#status').on( 'change', function () {
	            table
			        .columns( 5 )
			        .search( this.value )
			        .draw();
	        });

		} );
	},
    "attachProducts":function(component, event, contractElementId, contractElementType, selectedIds) {
		var objects = [];
		for(var i = 0; i < selectedIds.length; i++){
			var status = '';
			if(contractElementType === 'ESPP'){
				status = 'ESPP';
			}
			else if(contractElementType === 'Suite Rental'){
				status = 'Sold';
			}
			else if(contractElementType === 'Suite Lease'){
				status = 'Lease';
			}
			else{

			}

			objects.push({"Id" : selectedIds[i].id, "sobjectType" : "Suite_Products__c", "Contract_Element__c" : contractElementId, "Status__c" : status});
		}

		console.log('Objects to attach: ' + JSON.stringify(objects));

		component.set('v.spinner', true);
		var action = component.get('c.addProducts');
		action.setParams({ 'products' : JSON.stringify(objects) });
		action.setCallback(this, function(a){
			var state = a.getState();
			component.set('v.spinner', false);
			if(state === 'SUCCESS'){
				component.destroy();
			}
			else{
				alert('There is an error!');
			}
		});
		$A.enqueueAction(action);
	}
  }
};
});
 }
)})();
//# sourceURL=https://mse.lightning.force.com/components/c/ContractBuilderSuiteProducts.js