You need to sign in to do that
Don't have an account?

Lightning Component Upsert - Attempted to upsert a null list
I am using the Expense__c tracker app as a template to create a custom lightning component for adding new Events. When I click save on the form, the log in the developer console returns an error: Attempted to upsert a null list.
Here is my Component:
Here is my Helper:
Any ideas on how to troubleshoot would be appreciated.
Here is my Component:
<aura:component controller="EventController" implements="force:appHostable,flexipage:availableForAllPageTypes" access="global"> <aura:attribute name="allDay" type="Boolean" default="False"/> <aura:attribute name="events" type="Event[]"/> <aura:attribute name="newEvent" type="Event" default="{ 'sobjectType': 'Event', 'Subject': 'Default Subject', 'OwnerId': '005j000000BRyZ1AAL', 'StartDateTime': 'now()', 'WhoId': '005j000000BRyZ1AAL', 'WhatId': '00Q63000001qAPqEAM', 'Consult_Amount__c': '123.10', 'Event_Status__c': 'Completed', 'Event_Type__c': 'Lunch', 'DurationInMinutes': '30' }"/> <!--Assigned To Form Element --> <ui:inputSelect label="Assigned To" multiple="false" required="true"> <ui:inputSelectOption text="All Primary" label="All Contacts" value="true"/> <ui:inputSelectOption text="All Primary" label="All Primary"/> <ui:inputSelectOption text="All Secondary" label="All Secondary"/> </ui:inputSelect> <!--Subject Form Element --> <ui:inputText label="Subject" placeholder="Enter Subject" value="{!v.newEvent.Subject}"/> <!--All Day Event Form Element --> <ui:inputCheckbox label="All Day Event" value="{!v.newEvent.IsAllDayEvent}" /> <!--Renders Date or DateTime UI Input based on All Day Event Check Box --> <aura:if isTrue="{!v.newEvent.IsAllDayEvent}"> <!--Start/End Date Form Elements --> <ui:inputDate aura:id="startdate" label="Start Date" value="{!v.newEvent.StartDateTime}" displayDatePicker="true" /> <ui:inputDate aura:id="enddate" label="End Date" value="{!v.newEvent.EndDateTime}" displayDatePicker="true" /> <aura:set attribute="else"> <!--Start/End DateTime Form Elements --> <ui:inputDateTime aura:id="startdatetime" label="Start Date" class="field" value="{!v.newEvent.StartDateTime}" displayDatePicker="true" /> <ui:inputDateTime aura:id="enddatetime" label="End Date" class="field" value="{!v.newEvent.EndDateTime}" displayDatePicker="true" /> </aura:set> </aura:if> <!--Invitee Form Element --> <ui:inputSelect label="Invitees Of This Event" multiple="True" required="true"> <ui:inputSelectOption text="All Primary" label="All Contacts" value="true"/> <ui:inputSelectOption text="All Primary" label="All Primary"/> <ui:inputSelectOption text="All Secondary" label="All Secondary"/> </ui:inputSelect> <!--Event Type Form Element --> <ui:inputSelect label="Event Type" multiple="False" required="true"> <ui:inputSelectOption text="All Primary" label="All Contacts" value="true"/> <ui:inputSelectOption text="All Primary" label="All Primary"/> <ui:inputSelectOption text="All Secondary" label="All Secondary"/> </ui:inputSelect> <!--Event Status Type Form Element --> <ui:inputSelect label="Event Status Type" multiple="False" required="true"> <ui:inputSelectOption text="Completed" label="Completed" value="true"/> <ui:inputSelectOption text="Canceled" label="Canceled"/> <ui:inputSelectOption text="No/Show" label="No/Show"/> </ui:inputSelect> <!--Rescheduled from Prior Consult Form Element --> <ui:inputCheckbox label="Rescheduled from Prior Consult" value=""/> <!--Is Paid Consult Form Element --> <ui:inputCheckbox label="Is Paid Consult" value=""/> <!--Consult Amount Form Element --> <ui:inputText label="Consult Amount" value="Consult Amount" required="true"/> <!--Related To Form Element --> <ui:inputSelect label="Related To" multiple="False" required="true"> <ui:inputSelectOption text="Matter" label="Matter" value="true"/> <ui:inputSelectOption text="Prospect" label="Prospect"/> </ui:inputSelect> <!--Save Event Button--> <ui:button label="Save" press="{!c.createEvent}"/> </aura:component>Here is my JS Controller:
({ createEvent : function(component, event, helper) { // Validate form fields // Pass form data to a helper function var newEvent = component.get("v.newEvent"); helper.createEvent(component, newEvent); } })
Here is my Helper:
({ createEvent: function(component, event) { //Save the event and update the view this.upsertEvent(component, event, function(a) { var events = component.get("v.events"); events.push(a.getReturnValue()); component.set("v.events", events); }); }, upsertEvent : function(component, event, callback) { var action = component.get("c.saveEvent"); action.setParams({ 'event': event }); if (callback) { action.setCallback(this, callback); } $A.enqueueAction(action); } })Here is my Apex Controller:
public with sharing class EventController { @AuraEnabled public static List<Event> getEvents() { String runningUser = UserInfo.getUserId(); List<Event> events = Database.query( 'SELECT Id, Subject, WhoId, WhatId, EndDateTime, StartDateTime, Matter_Type__c, Color_Code__c, Type, Event_Type__c, OwnerId FROM Event WHERE OwnerId = :runningUser AND (StartDateTime = LAST_N_DAYS:45 OR StartDateTime = NEXT_N_DAYS:45)'); //Add isAccessible() check return events; } @AuraEnabled // Retrieve all primary contacts public static List<Event> getConsult() { List<Event> consultEvents = [SELECT Id, Subject, WhoId, WhatId, EndDateTime, StartDateTime, ActivityDate, OwnerId, Type FROM Event WHERE Event_Type__c = 'Consult' AND OwnerId = '005j000000BRyZ1']; //Add isAccessible() check return consultEvents; } @AuraEnabled public static Event saveEvent(Event event) { // Perform isUpdateable() check here upsert event; return event; } }The extra code in the controller is for another part of the app. It looks like the data is being passed to the Apex controller from the component and that the Apex controller is set up the same way as the example.
Any ideas on how to troubleshoot would be appreciated.
All Answers
http://thekedarjoshi.blogspot.com/2016/03/event-auraattribute-type-in-lightning_39.html
http://salesforce.stackexchange.com/questions/89194/auraattribute-not-working-for-event-object