You need to sign in to do that
Don't have an account?
ekm
Flex Last Record ID
Hi,
I'm creating an event and then wanting to pass the ID of that newly created event into another table (Event_Attendee__c). I save the ID to a variable (lastEventId). I'm able to retrieve the newly created event ID, but have so far not been able to pass the ID into the function where I am creating a new event_attendee record. I'm getting Null in my trace statement in the createEventAttendee function for lastEventId.
Anyone have any thoughts as to how solve this?
Regards,
public var lastEventId:String;
private function create():void
{
createEvent();
createEventAttendee();
}
private function createEvent():void
{
var evt:SObject = new SObject('Event');
evt.RecordTypeId = '01230000000DkER';
evt.OwnerId = '005300000017Tz4AAE';
evt.WhatId = '00130000008TiPdAAK';
evt.ffCompany_Name1__c = txtCustomerName.text;
evt.ffCompany_Name2__c = txtCID.text;
evt.Type = conferenceCallCheckBox;
evt.ActivityDateTime = new Date(2008, 5, 30, startTimePassHour, startTimePassMinute, 0);
evt.DurationInMinutes = meetingTime;
evt.Travel_Time__c = cmbTravelTime.selectedLabel;
evt.Method__c = cmbMeetingType.selectedLabel;
evt.Purchaser_Delivered__c = purDelivered;
evt.Purchaser_Delivered_Quantity__c = txtPurDeliveredAddQty.text; //Purchaser Delivered Quantity
evt.PIH_Delivered__c = pihDelivered;
evt.PIH_Delivered_Quantity__c = txtPihDeliveredAddQty.text;
evt.Healthworks_Reviewed__c = healthworksReviewed;
evt.Healthworks_Approved__c = healthworksApproved;
evt.Facility_Tour__c = facilityTour;
evt.Subject = subjectSelected;
evt.Objectives__c = objectiveSelected; //Key Objectives
evt.Actual_Outcome__c = txtOtherCommentsAdd.text; //Other Comments;
apex.create([evt],
new AsyncResponder( function (result:Object):void
{
trace( 'new event id: '+(result[0] as SaveResult).id );
lastEventId = (result[0] as SaveResult).id;
trace('last event id: '+ lastEventId);
}, genericFault
) );
}
private function createEventAttendee():void
{
//using customized table Event_Attendee__c
var eventAttendee:SObject = new SObject('Event_Attendee__c');
//forcing this value for now
eventAttendee.Contact__c = '101010101';
eventAttendee.Event_ID__c = lastEventId;
trace("create Event lastEventId: " + lastEventId);
eventAttendee.Status__c = 'Accepted'; //pass 'Accepted' string
apex.create([eventAttendee],
new AsyncResponder( function (result:Object):void
{
}, genericFault
) );
}
I'm creating an event and then wanting to pass the ID of that newly created event into another table (Event_Attendee__c). I save the ID to a variable (lastEventId). I'm able to retrieve the newly created event ID, but have so far not been able to pass the ID into the function where I am creating a new event_attendee record. I'm getting Null in my trace statement in the createEventAttendee function for lastEventId.
Anyone have any thoughts as to how solve this?
Regards,
public var lastEventId:String;
private function create():void
{
createEvent();
createEventAttendee();
}
private function createEvent():void
{
var evt:SObject = new SObject('Event');
evt.RecordTypeId = '01230000000DkER';
evt.OwnerId = '005300000017Tz4AAE';
evt.WhatId = '00130000008TiPdAAK';
evt.ffCompany_Name1__c = txtCustomerName.text;
evt.ffCompany_Name2__c = txtCID.text;
evt.Type = conferenceCallCheckBox;
evt.ActivityDateTime = new Date(2008, 5, 30, startTimePassHour, startTimePassMinute, 0);
evt.DurationInMinutes = meetingTime;
evt.Travel_Time__c = cmbTravelTime.selectedLabel;
evt.Method__c = cmbMeetingType.selectedLabel;
evt.Purchaser_Delivered__c = purDelivered;
evt.Purchaser_Delivered_Quantity__c = txtPurDeliveredAddQty.text; //Purchaser Delivered Quantity
evt.PIH_Delivered__c = pihDelivered;
evt.PIH_Delivered_Quantity__c = txtPihDeliveredAddQty.text;
evt.Healthworks_Reviewed__c = healthworksReviewed;
evt.Healthworks_Approved__c = healthworksApproved;
evt.Facility_Tour__c = facilityTour;
evt.Subject = subjectSelected;
evt.Objectives__c = objectiveSelected; //Key Objectives
evt.Actual_Outcome__c = txtOtherCommentsAdd.text; //Other Comments;
apex.create([evt],
new AsyncResponder( function (result:Object):void
{
trace( 'new event id: '+(result[0] as SaveResult).id );
lastEventId = (result[0] as SaveResult).id;
trace('last event id: '+ lastEventId);
}, genericFault
) );
}
private function createEventAttendee():void
{
//using customized table Event_Attendee__c
var eventAttendee:SObject = new SObject('Event_Attendee__c');
//forcing this value for now
eventAttendee.Contact__c = '101010101';
eventAttendee.Event_ID__c = lastEventId;
trace("create Event lastEventId: " + lastEventId);
eventAttendee.Status__c = 'Accepted'; //pass 'Accepted' string
apex.create([eventAttendee],
new AsyncResponder( function (result:Object):void
{
}, genericFault
) );
}
werewolf
Well since you're setting the lastEventId in an AsyncResponder it's a fair bet that you're actually calling createEventAttendee before the apex.create is actually finished (since it is in fact asynchronous meaning that other stuff can run while you're waiting for it to return). Why not just call createEventAttendee right from the AsyncResponder on createEvent? In that case you could probably just pass in lastEventId, no need to make it a global variable.
ekm
Yes, that does it. Thanks!