function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Amanda Byrne- Carolina Tiger RescueAmanda Byrne- Carolina Tiger Rescue 

Using a query and update in a Page Reference

Modifying some existing code that updates a record and then redirects to a new page. I need to change it so that it runs a query to identify the correct record to update, and then updates the record.
 
public PageReference saveAttendee(){
     
         List<CnP_PaaS_EVT__Event_attendee_session__c> attendee = [SELECT Id, Name, DTCI_Agreement_Active__c, CnP_PaaS_EVT__First_name__c, CnP_PaaS_EVT__Last_name__c, DTCI_Ticket_Level__c, CnP_PaaS_EVT__EventId__r.CnP_PaaS_EVT__category__r.name                                                                                                                                                          
                                                                       FROM CnP_PaaS_EVT__Event_attendee_session__c                                                                            
                                                                       WHERE CnP_PaaS_EVT__Registrant_session_Id__c =:registrantId 
                                                                            AND DTCI_Ticket_Level__c =: ticketLevel           
                                                                            AND DTCI_Attendee_Info_Assigned__c = FALSE
                                                                       ORDER BY DTCI_Ticket_Order__c
                                                                       LIMIT 1
                                                                      ];
        
        attendeeId = attendee.Id;                                                              
        attendeeFirstName = attendee.CnP_PaaS_EVT__First_name__c;
        attendeeLastName = attendee.CnP_PaaS_EVT__Last_name__c;
        mailingCity = attendee.DTCI_Mailing_City__c;
        mailingCountry = attendee.DTCI_Mailing_Country__c;
        mailingCounty = attendee.DTCI_Mailing_County__c;
        mailingState = attendee.DTCI_Mailing_State__c;
        mailingStreet = attendee.DTCI_Mailing_Street__c;
        mailingZip = attendee.DTCI_Mailing_ZIP_Postal_Code__c;
       
                                   
        update attendee;                                        
        
PageReference sendToReleaseForm = new PageReference('/apex/DTCI_Release_Form_Page_AB' + '?attendeePageId=' + attendee.id + '&registrantPageId=' + registrantId + '&eventPageId=' + eventId + '&releasePageType=' + attendee.DTCI_Release_Type__c);  
        sendToReleaseForm.setRedirect(true);                        
        return sendToReleaseForm;     
    }

How can I query the object to find the next suitable record to update and still create the PageReference I need to move forward?

 
Best Answer chosen by Amanda Byrne- Carolina Tiger Rescue
pigginsbpigginsb
Something like this might be helpful. Have the PageReference method call the List<CnP_PaaS_EVT__Event_attendee_session__c> method... This way the list method can still be called from other places in the code.
public PageReference saveAttendee(){
     
        CnP_PaaS_EVT__Event_attendee_session__c attendee;
		
        // use for loop to get the first result, then break out of the loop.
		for (CnP_PaaS_EVT__Event_attendee_session__c firstResult : attendeeListFor(registrantId, ticketLevel) {
			attendee = firstResult;
			break;
		}
		
        // unable to proceed if attendee is not found...
		if (attendee == null)
			return null;
			
        attendeeId = attendee.Id;                                                              
        attendeeFirstName = attendee.CnP_PaaS_EVT__First_name__c;
        attendeeLastName = attendee.CnP_PaaS_EVT__Last_name__c;
        mailingCity = attendee.DTCI_Mailing_City__c;
        mailingCountry = attendee.DTCI_Mailing_Country__c;
        mailingCounty = attendee.DTCI_Mailing_County__c;
        mailingState = attendee.DTCI_Mailing_State__c;
        mailingStreet = attendee.DTCI_Mailing_Street__c;
        mailingZip = attendee.DTCI_Mailing_ZIP_Postal_Code__c;
       
                                   
        update attendee;                                        
        
		PageReference sendToReleaseForm = new PageReference('/apex/DTCI_Release_Form_Page_AB');
		sendToReleaseForm.getParameters().put('attendeePageId', attendee.id);
		sendToReleaseForm.getParameters().put('registrantPageId', registrantId );
		sendToReleaseForm.getParameters().put('eventPageId', eventId );
		sendToReleaseForm.getParameters().put('releasePageType', attendee.DTCI_Release_Type__c);
sendToReleaseForm.setRedirect(true);                        
        return sendToReleaseForm;     
    }
	
    // this method still returns a list, but your PageReference method can call it...
	public List<CnP_PaaS_EVT__Event_attendee_session__c> attendeeListFor(String registrantId, String ticketLevel) {
		return [SELECT Id, Name, DTCI_Agreement_Active__c, CnP_PaaS_EVT__First_name__c, CnP_PaaS_EVT__Last_name__c, DTCI_Ticket_Level__c, CnP_PaaS_EVT__EventId__r.CnP_PaaS_EVT__category__r.name
				   FROM CnP_PaaS_EVT__Event_attendee_session__c                                                                            
				   WHERE CnP_PaaS_EVT__Registrant_session_Id__c =:registrantId 
						AND DTCI_Ticket_Level__c =: ticketLevel           
						AND DTCI_Attendee_Info_Assigned__c = FALSE
				   ORDER BY DTCI_Ticket_Order__c
		  ];
	}

 

All Answers

JeffreyStevensJeffreyStevens
I think we're going to need some more information.  What do you mean my "next suitable record"?  The :registrantId and :ticketLevel fields are already populated by the time you get to this method.
Amanda Byrne- Carolina Tiger RescueAmanda Byrne- Carolina Tiger Rescue
The query would be returning the result needed to identify the record to update- that is, I want to update the first record in the results where the

CnP_PaaS_EVT__Registrant_session_Id__c =:registrantId (registrantId is provided by a variable in the custom controller that collects a URL parameter)
DTCI_Ticket_Level__c =: ticketLevel  (ticketLevel is provided by a variable in the custom controller )       
and DTCI_Attendee_Info_Assigned__c = FALSE

The attendee object may have several records that meet those qualifications- that's why I added LIMIT 1 to the query
pigginsbpigginsb
Are you intending to change any values on the record that is returned by your query? Lines 12-20 are assigning values to class properties from the returned record, then the update statement performs an update on the record returned by the query, but no values have actually been changed on that record.

Also, if you think it helps with readability, you can set url parameters as follows...
PageReference sendToReleaseForm = new PageReference('/apex/DTCI_Release_Form_Page_AB');
sendToReleaseForm.getParameters().put('attendeePageId', attendee.id);
sendToReleaseForm.getParameters().put('registrantPageId', registrantId );
sendToReleaseForm.getParameters().put('eventPageId', eventId );
sendToReleaseForm.getParameters().put('releasePageType', attendee.DTCI_Release_Type__c);

 
Amanda Byrne- Carolina Tiger RescueAmanda Byrne- Carolina Tiger Rescue
Well- that's definitely helpful. The Page Reference saveAttendee() function is called by an action on a Visual Force page with a form. The page uses the Attendee object as the standard controller, and this code is from an extension Class. Originally the specific record to update was identified and already tied to the form; however, we were having problems or users writing over each other because they could access the same record concurrently. So I need to change it so that the values are not set until the form has been completed,

The records already exist- someone purchases 2 adult tickets, 2 youth tickets- this creates 4 attendee records, mostly unpopulated. Attendees fill out the form when they arrive. The attendee chooses their party, and then which ticket to check-in on. I want the attendees to see both adult tickets and youth tickets as what tickets are unassigned, but I don't want to assign a specific ticket until the attendee has filled out the form.

The form looks like this:
 
<detail>First Name<font class='detailError'>*</font></detail>
     <apex:inputField value="{!CnP_PaaS_EVT__Event_attendee_session__c.CnP_PaaS_EVT__First_name__c}" required="true" styleClass="detail" id="firstNameField" >               
          <apex:param name="attendeeFirstNameParam" value="{!CnP_PaaS_EVT__Event_attendee_session__c.CnP_PaaS_EVT__First_name__c}" assignTo="{!attendeeFirstName}"/> 
     </apex:inputField>                          
<br/>  
                
<detail>Last Name<font class='detailError'>*</font></detail>
     <apex:inputField value="{!CnP_PaaS_EVT__Event_attendee_session__c.CnP_PaaS_EVT__Last_name__c}" required="true" styleClass="detail" id="lastNameField" >                          <apex:param name="attendeeLastNameParam" value="{!CnP_PaaS_EVT__Event_attendee_session__c.CnP_PaaS_EVT__First_name__c}" assignTo="{!attendeeLastName}"/>
     </apex:inputField>                          
<br/>

I'm not sure how I would need to change the form so that it doesn't display existing info (b/c would no longer be a defined record- it couldn't). I'm guessing I would remove the value on the input fields and let the param define what field values would be applied for the update?

I hope that clarifies enough.

Here is a sample of the other code from my extension (I didn't include all the fields- but they are similarly set up):
 
public class DTCI_Attendee_AB_Ctrl {
    
    //Variables
    private CnP_PaaS_EVT__Event_attendee_session__c attendee;     
    public String eventId {get; set;}
          
    public String attendeeFirstName {get; set;}     
    public String attendeeLastName {get; set;} 
    public String mailingCity {get; set;}
    public String mailingState {get; set;} 
    public String mailingStreet {get; set;}     
    public String mailingZip {get; set;}  
   
    //Constructor
    public DTCI_Attendee_AB_Ctrl(ApexPages.StandardController controller) {         
        attendee = (CnP_PaaS_EVT__Event_attendee_session__c) controller.getRecord();         
        eventId = ApexPages.currentPage().getParameters().get('eventPageId');
        evtCategory = ApexPages.currentPage().getParameters().get('evtCategory');
        registrantId = ApexPages.currentPage().getParameters().get('registrantPageId');
        isMinorStr = ApexPages.currentPage().getParameters().get('isMinorStr');        
    }
    
    //Save Attendee Button
    
    public PageReference saveAttendee(){...

// the saveAttendee function is described in the original post

 
pigginsbpigginsb
It sounds like you will want to assign values from the extension properties to the attendee record from the database...
attendee.CnP_PaaS_EVT__First_name__c = attendeeFirstName ;
attendee.CnP_PaaS_EVT__Last_name__c = attendeeLastName ;
attendee.DTCI_Mailing_City__c = mailingCity;
attendee.DTCI_Mailing_Country__c = mailingCountry;
attendee.DTCI_Mailing_County__c = mailingCounty;
attendee.DTCI_Mailing_State__c = mailingState;
attendee.DTCI_Mailing_Street__c = mailingStreet;
attendee.DTCI_Mailing_ZIP_Postal_Code__c = mailingZip;
This should at least get the values entered from the form into the database.
 
Amanda Byrne- Carolina Tiger RescueAmanda Byrne- Carolina Tiger Rescue
The problem I was having was structuring the query to select the record. The query itself should be correct. In the current version, a apex button on the VisualForce page has the action of saveAttendee(). In the extension, saveAttendee() is in a Page Reference method (hope I've got the right terminology). I do need it to stay a Page Reference method to redirect to the next page once the changes have been saved; however, in all my other examples my queries are in List methods. If I leave it a list inside the Page Reference method, I get errors for not using a list. Do I nest the method? Wouldn't I need to call it somehow to collect the record to update?

I don't need any fields populated prior to the guest checking in (CnP_PaaS_EVT__Registrant_session_Id__c and DTCI_Ticket_Level__c are populated when the tickets are purchased) - so I collect URL parameters needed for the query.
pigginsbpigginsb
Something like this might be helpful. Have the PageReference method call the List<CnP_PaaS_EVT__Event_attendee_session__c> method... This way the list method can still be called from other places in the code.
public PageReference saveAttendee(){
     
        CnP_PaaS_EVT__Event_attendee_session__c attendee;
		
        // use for loop to get the first result, then break out of the loop.
		for (CnP_PaaS_EVT__Event_attendee_session__c firstResult : attendeeListFor(registrantId, ticketLevel) {
			attendee = firstResult;
			break;
		}
		
        // unable to proceed if attendee is not found...
		if (attendee == null)
			return null;
			
        attendeeId = attendee.Id;                                                              
        attendeeFirstName = attendee.CnP_PaaS_EVT__First_name__c;
        attendeeLastName = attendee.CnP_PaaS_EVT__Last_name__c;
        mailingCity = attendee.DTCI_Mailing_City__c;
        mailingCountry = attendee.DTCI_Mailing_Country__c;
        mailingCounty = attendee.DTCI_Mailing_County__c;
        mailingState = attendee.DTCI_Mailing_State__c;
        mailingStreet = attendee.DTCI_Mailing_Street__c;
        mailingZip = attendee.DTCI_Mailing_ZIP_Postal_Code__c;
       
                                   
        update attendee;                                        
        
		PageReference sendToReleaseForm = new PageReference('/apex/DTCI_Release_Form_Page_AB');
		sendToReleaseForm.getParameters().put('attendeePageId', attendee.id);
		sendToReleaseForm.getParameters().put('registrantPageId', registrantId );
		sendToReleaseForm.getParameters().put('eventPageId', eventId );
		sendToReleaseForm.getParameters().put('releasePageType', attendee.DTCI_Release_Type__c);
sendToReleaseForm.setRedirect(true);                        
        return sendToReleaseForm;     
    }
	
    // this method still returns a list, but your PageReference method can call it...
	public List<CnP_PaaS_EVT__Event_attendee_session__c> attendeeListFor(String registrantId, String ticketLevel) {
		return [SELECT Id, Name, DTCI_Agreement_Active__c, CnP_PaaS_EVT__First_name__c, CnP_PaaS_EVT__Last_name__c, DTCI_Ticket_Level__c, CnP_PaaS_EVT__EventId__r.CnP_PaaS_EVT__category__r.name
				   FROM CnP_PaaS_EVT__Event_attendee_session__c                                                                            
				   WHERE CnP_PaaS_EVT__Registrant_session_Id__c =:registrantId 
						AND DTCI_Ticket_Level__c =: ticketLevel           
						AND DTCI_Attendee_Info_Assigned__c = FALSE
				   ORDER BY DTCI_Ticket_Order__c
		  ];
	}

 
This was selected as the best answer
Amanda Byrne- Carolina Tiger RescueAmanda Byrne- Carolina Tiger Rescue
I think we're getting close! But I'm getting the error:

"Attempt to de-reference a null object
Error is in expression '{!saveAttendee}' in component <apex:commandButton> in page dtci_attendee_info_page_ab: Class.DTCI_Attendee_AB_Ctrl.saveAttendee: line 110, column 1" (this line references the ApexPages.addMessage)

Here's what I have now, I think the only major change I made to what you suggested was changing attendeeListFor to nextAvailableTicket(), and I placed nextAvailableTicket before saveAttendee():
 
public static List<CnP_PaaS_EVT__Event_attendee_session__c> nextAvailableTicket(String registrantId, String ticketLevelId) {
        
            List<CnP_PaaS_EVT__Event_attendee_session__c> nextAvailableTicket = [SELECT Id, Name, DTCI_Agreement_Active__c, CnP_PaaS_EVT__First_name__c, CnP_PaaS_EVT__Last_name__c, DTCI_Ticket_Level__c, CnP_PaaS_EVT__EventId__r.CnP_PaaS_EVT__category__r.name                                                                                                                                                         
                FROM CnP_PaaS_EVT__Event_attendee_session__c                                                                           
                WHERE CnP_PaaS_EVT__Registrant_session_Id__c =:registrantId
                AND CnP_PaaS_EVT__Registration_level__c =:ticketLevelId         
                AND DTCI_Attendee_Info_Assigned__c = FALSE
                ORDER BY DTCI_Ticket_Order__c
                LIMIT 1
                ];
                
            return nextAvailableTicket;
        }

    
        // update attendee record chosen as nextAvailableTicket
        public PageReference saveAttendee(){
            CnP_PaaS_EVT__Event_attendee_session__c attendee;
            
            if(String.isBlank(attendeeId)){
                // use for loop to get the result, then break out of the loop.
                for (CnP_PaaS_EVT__Event_attendee_session__c firstResult : nextAvailableTicket(registrantId, ticketLevelId)) {
                    attendee = firstResult;
                    
                     if (isMinor == true && isEvtCategoryVolunteer == true){
                        releaseType = 'Minor Volunteer';
                        } else if(isMinor == true && isEvtCategoryVolunteer == false){
                        releaseType = 'Minor Visitor';
                        } else if(isMinor == false && isEvtCategoryVolunteer == true){
                        releaseType = 'Adult Volunteer';
                        } else {
                        releaseType = 'Adult Visitor';    
                        }                    
                    break;
                    }
                }    

            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, attendee.Id));
            
            // stop if attendee not found
            CnP_PaaS_EVT__Event_attendee_session__c nextAvailableTicket;
            if (attendee == null){
                return null;
                
                }

        attendeeId = attendee.Id;                                                             
        attendeeFirstName = attendee.CnP_PaaS_EVT__First_name__c;
        attendeeLastName = attendee.CnP_PaaS_EVT__Last_name__c;
        mailingCity = attendee.DTCI_Mailing_City__c;
        mailingCountry = attendee.DTCI_Mailing_Country__c;
        mailingCounty = attendee.DTCI_Mailing_County__c;
        mailingState = attendee.DTCI_Mailing_State__c;
        mailingStreet = attendee.DTCI_Mailing_Street__c;
        unitType = attendee.DTCI_Apt_Ste_Unit_Type__c;
        unitNo = attendee.DTCI_Apt_Ste_Unit_No__c;
        attendeePhone = attendee.DTCI_Phone__c;
        attendeePhoneType = attendee.DTCI_Phone_Type__c;
        attendeeEmail = attendee.DTCI_Email__c;
        subscriptionMail = attendee.DTCI_Subscription_Mail__c;
        subscriptionEmail = attendee.DTCI_Subscription_Email__c;  
        subscriptionNewsletter = attendee.DTCI_Subscription_Newsletter__c;
        volunteerEmergencyName = attendee.DTCI_Emergency_Name__c;
        volunteerEmergencyRelationship = attendee.DTCI_Emergency_Relationship__c;
        volunteerEmergencyPhone = attendee.DTCI_Emergency_Phone__c;
        volunteerFormPurpose = attendee.DTCI_Form_Purpose__c;            
        leadSource = attendee.DTCI_Lead_Source__c;                   
        releaseType = attendee.DTCI_Release_Type__c;
                 
       update attendee;
                                               
       PageReference sendToReleaseForm = new PageReference('/apex/DTCI_Release_Form_Page_AB' + '?attendeePageId=' + attendee.id + '&registrantPageId=' + registrantId + '&eventPageId=' + eventId + '&releasePageType=' + releaseType);  
       sendToReleaseForm.setRedirect(true);                        
       return sendToReleaseForm;
            
    }
I've tested the nextAvailableTicket method, and it is returning results- I called it in the page with javascript to make sure.

I've added some if conditions to set  a value for releaseType, which is a value that needs to be updated if nextAvailableTcket returns a result or remains the record's current value if it is not. It also needs to be passed as a param in sendToReleaseForm.

I don't really think that is what is causing the error. What can I do next?




 
JeffreyStevensJeffreyStevens
Well whenever you get the attempt to derefrence a null object - that is almost always because something is not instanstiated.  Meaning - the variable is declared, but the variable is null.  So, - look at line 110 in the DTCI_Attendee_AB_Ctrl.saveAttendee class and method - find what it's doing there - something on that line is null (not blank).  Usually - it's list a list or map or sObject - stuff like that. 

If you can't get it - we will probably need to see that class and method.
pigginsbpigginsb
There appear to be two scenarios where your attendee variable (declared in line 18 above) will remain null.

1. If the attendeeId is not blank, you will never enter the IF block
2. if your nextAvailableTicket() method returns an empty list, you will not enter the FOR-loop.

When your attendee variable remains null, you will not be able to use "attendee.Id", which is in your addMessage() call, Line 38 above.

It's not clear why a page message would be added there. The IF statement immediately following that page message call checks to see whether an attendee is found, in order to avoid null pointer errors in lines 47-68 above.
Amanda Byrne- Carolina Tiger RescueAmanda Byrne- Carolina Tiger Rescue
Well, I was hoping to use the saveAttendee() in two situations, one where the form is initially blank, and I would use the List<CnP_PaaS_EVT__Event_attendee_session__c> nextAvailableTicket to select the record to update, the other is if attendeeId is supplied in the parameter- allowing me to use the same form to edit the record.

Now I'm getting a
"SObject row was retrieved via SOQL without querying the requested field: CnP_PaaS_EVT__Event_attendee_session__c.DTCI_Mailing_City__c
Error is in expression '{!saveAttendee}' in component <apex:commandButton> in page dtci_attendee_info_page_ab: 

 
//Save Attendee Button
        // Find the next registrant ticket of the same ticket type
 //    @RemoteAction       
        public static List<CnP_PaaS_EVT__Event_attendee_session__c> nextAvailableTicket(String registrantId, String ticketLevelId) {
        
            List<CnP_PaaS_EVT__Event_attendee_session__c> nextAvailableTicket = [SELECT Id, Name, DTCI_Agreement_Active__c, CnP_PaaS_EVT__First_name__c, CnP_PaaS_EVT__Last_name__c, DTCI_Ticket_Level__c, CnP_PaaS_EVT__EventId__r.CnP_PaaS_EVT__category__r.name                                                                                                                                                         
                FROM CnP_PaaS_EVT__Event_attendee_session__c                                                                           
                WHERE CnP_PaaS_EVT__Registrant_session_Id__c =:registrantId
                AND CnP_PaaS_EVT__Registration_level__c =:ticketLevelId         
                AND DTCI_Attendee_Info_Assigned__c = FALSE
                ORDER BY DTCI_Ticket_Order__c
                LIMIT 1
                ];
                
            return nextAvailableTicket;
        }

    
        // update attendee record chosen as nextAvailableTicket
        public PageReference saveAttendee(){
            
            if(String.isBlank(attendeeId)){
                // use for loop to get the result, then break out of the loop.
                for (CnP_PaaS_EVT__Event_attendee_session__c firstResult : nextAvailableTicket(registrantId, ticketLevelId)) {
                    attendee = firstResult;
                    
                     if (isMinor == true && isEvtCategoryVolunteer == true){
                        releaseType = 'Minor Volunteer';
                        } else if(isMinor == true && isEvtCategoryVolunteer == false){
                        releaseType = 'Minor Visitor';
                        } else if(isMinor == false && isEvtCategoryVolunteer == true){
                        releaseType = 'Adult Volunteer';
                        } else {
                        releaseType = 'Adult Visitor';    
                        }                    
                    break;
                    }
                }    

        attendeeId = attendee.Id;                                                             
        attendeeFirstName = attendee.CnP_PaaS_EVT__First_name__c;
        attendeeLastName = attendee.CnP_PaaS_EVT__Last_name__c;
        mailingCity = attendee.DTCI_Mailing_City__c;
        mailingCountry = attendee.DTCI_Mailing_Country__c;
        mailingCounty = attendee.DTCI_Mailing_County__c;
        mailingState = attendee.DTCI_Mailing_State__c;
        mailingStreet = attendee.DTCI_Mailing_Street__c;
        unitType = attendee.DTCI_Apt_Ste_Unit_Type__c;
        unitNo = attendee.DTCI_Apt_Ste_Unit_No__c;
        attendeePhone = attendee.DTCI_Phone__c;
        attendeePhoneType = attendee.DTCI_Phone_Type__c;
        attendeeEmail = attendee.DTCI_Email__c;
        subscriptionMail = attendee.DTCI_Subscription_Mail__c;
        subscriptionEmail = attendee.DTCI_Subscription_Email__c;  
        subscriptionNewsletter = attendee.DTCI_Subscription_Newsletter__c;
        volunteerEmergencyName = attendee.DTCI_Emergency_Name__c;
        volunteerEmergencyRelationship = attendee.DTCI_Emergency_Relationship__c;
        volunteerEmergencyPhone = attendee.DTCI_Emergency_Phone__c;
        volunteerFormPurpose = attendee.DTCI_Form_Purpose__c;            
        leadSource = attendee.DTCI_Lead_Source__c;                   
        releaseType = attendee.DTCI_Release_Type__c;
                 
       update attendee;
                                               
       PageReference sendToReleaseForm = new PageReference('/apex/DTCI_Release_Form_Page_AB' + '?attendeePageId=' + attendee.id + '&registrantPageId=' + registrantId + '&eventPageId=' + eventId + '&releasePageType=' + releaseType);  
       sendToReleaseForm.setRedirect(true);                        
       return sendToReleaseForm;
            
    }

 
pigginsbpigginsb
That error means that if you're going to assign attendee.DTCI_Mailing_City__c to the mailingCity variable, as in line 43 above, you will need to include that field in the query that obtains the record from the database, in line 6 above. Every field that you hope to reference on the record returned from your query should be selected in the query. The row retrieved via SOQL is the attendee record, and the requested field is the one that should have been included in your select statement.

Currently you are requesting only Id, Name, DTCI_Agreement_Active__c, CnP_PaaS_EVT__First_name__c, CnP_PaaS_EVT__Last_name__c, DTCI_Ticket_Level__c, and CnP_PaaS_EVT__EventId__r.CnP_PaaS_EVT__category__r.name. So you'll have to add more fields to the query, particularly all of those referenced in lines 43 through 61.

Keep asking questions. I'm happy to help.
Amanda Byrne- Carolina Tiger RescueAmanda Byrne- Carolina Tiger Rescue
Well, simple enough. THANK YOU. I actually get to the next page now! something's still off, but I've had to rearrange stuff quite a bit, I should be able to figure that out.
Amanda Byrne- Carolina Tiger RescueAmanda Byrne- Carolina Tiger Rescue
OK- now what's happening is that if I add those other fields to the query, it pulls the existing values from the record  suggested by nextAvailableTicket and writes them back, rather than the values that have been entered on the page with the form.

I have an "if" that determines whether or not the page loads with an attendeeId parameter or not, and if so sets attendee = (CnP_PaaS_EVT__Event_attendee_session__c) controller.getRecord();

the next reference to "attendee" is in saveAttendee(), where attendee is set to the first result of the nextAvailableTicket query- presumably replacing the values that would have been collected from the form.

the Form fields read like this:
<apex:inputField value="{!CnP_PaaS_EVT__Event_attendee_session__c.CnP_PaaS_EVT__Last_name__c}" required="true" styleClass="detail" id="lastNameField" >                                
                        <apex:param name="attendeeLastNameParam" value="{!CnP_PaaS_EVT__Event_attendee_session__c.CnP_PaaS_EVT__First_name__c}" assignTo="{!attendeeLastName}"/>                                
                    </apex:inputField>
The original version of this app ran the query for the correct record and the relevant fields before loading the form page, and would populate the form with the values from that. I've commented this code out- because I don't want the record assigned until the "saveAttendee()" is activated. the correct record is called  function called by the page 'before' the form page that uses the same extension class.

This new version needs to assign the record when the form page loads if attendeeId is a URL parameter, otherwise it should not assign a record until saveAttendee() is called. The problem seems to come when I set attendee = firstResult, I replace the values from the form with the values from the record.

I tried changing each field from attendeeFirstName = attendee.CnP_PaaS_EVT__First_name__c to attendee.CnP_PaaS_EVT__First_name__c = attendeeFirstName; this caused errors for all of the 'checkbox' fields that were declared Boolean in the class. But even when I commented those out and could save the extension class- the values on the record remained the same.

Apparently writing it like a SQL query isn't an option, e.g. Update attendee set attendee.CnP_PaaS_EVT__First_name__c = attendeeFirstName...


 
pigginsbpigginsb
I had noticed that there were no new values being written to the attendee record when it was assigned the "firstResult" within the FOR loop. Are you wanting to get the values from the form onto the attendee record that is returned from the database?

You mention, "This new version needs to assign the record when the form page loads if attendeeId is a URL parameter, otherwise it should not assign a record until saveAttendee() is called." This sounds like something that I would typically do in a constructor, or in an initialize() method called from a constructor, where the record to be saved/updated is either located from the database or newly instantiated when the page loads.

So if the url parameter is provided, the constructor in the page's extension would locate the existing record and pre-populate the form fields. If no url parameter is provided, then the save method might search for a matching record based on some information provided by the form, and if a match is found then update it with newly entered information, else create a new record from the information entered into the form.
Amanda Byrne- Carolina Tiger RescueAmanda Byrne- Carolina Tiger Rescue
I do have a getRecord command in the Constructor. I apologize if having the full extension would have presented a more complete picture- trying to keep posts concise. This extension class can be accessed by one of 3 pages.

1. Select from available tickets in party -if ticket type is Youth or Child, skip to Attendee Info
2. Minor Question page for Adults (13 and up) - . The page offers two buttons, one for checking in on behalf of a minor, and the other to check in as an adult.The extension class includes Page References MinorNo() and a MinorYes() for this page 
3. A page listing checked-in Guests, linking to the pre-filled Attendee Info page with AttendeeId, so users/staff can modify incorrect information.

The original application pre-selected the attendee record and had an Id prior to arriving at the Attendee Info page. We have 4 check-in kiosks, so if more than one person in the same party and with the same ticket type checks in on a different kiosk simultaneously, the slower check-in overwrites the first one.

Here's a only slightly summarized breakdown of the entire extension class in its current state.

Thank you so much for your time- this app has been hounding me for months, really upwards of a year.
 
public class DTCI_Attendee_AB_Ctrl {
    
    //Variables
    private CnP_PaaS_EVT__Event_attendee_session__c attendee; 

    // object variables for new attendees checking in   
        public String registrantId {get; set;}   
        public String ticketLevelId {get; set;}
        ...(other fields)
     
// additional var for Checked In attendees updating existing record, some values set by collecting URL parameters in the Contructor, other variables should pre-populate the Attendee Info form when it loads
        public String checkIn {get; set;}        
        public String attendeeId {get; set;}     
        public String attendeeFirstName {get; set;}     
        public String attendeeLastName {get; set;} 
        ... (other fields)

 //Constructor
    public DTCI_Attendee_AB_Ctrl(ApexPages.StandardController controller) {         
       attendee = (CnP_PaaS_EVT__Event_attendee_session__c) controller.getRecord();
        
        // New Attendees Checking In       
        ticketLevelId = ApexPages.currentPage().getParameters().get('ticketLevelId');
        isMinorStr = ApexPages.currentPage().getParameters().get('isMinorStr');

        //... if(){} that uses isMinorStr value to determine release type
        
        // additional var for Checked In attendees updating existing record
        attendeeId = ApexPages.currentPage().getParameters().get('attendeePageId');
        checkIn = ApexPages.currentPage().getParameters().get('checkIn');
        
        if(checkIn =='Complete' ){
        for(CnP_PaaS_EVT__Event_attendee_session__c att : [SELECT CnP_PaaS_EVT__EventId__r.CnP_PaaS_EVT__category__r.name FROM CnP_PaaS_EVT__Event_attendee_session__c WHERE Id =: attendeeId])
                     attendee = att;
        }



// Find the next registrant ticket of the same ticket type to select record to save values 

 public static List<CnP_PaaS_EVT__Event_attendee_session__c> nextAvailableTicket(String registrantId, String ticketLevelId) {
            List<CnP_PaaS_EVT__Event_attendee_session__c> nextAvailableTicket = [SELECT Id,                                                             
                CnP_PaaS_EVT__First_name__c,
                CnP_PaaS_EVT__Last_name__c,
            ...(other fields)
                                       
                            FROM CnP_PaaS_EVT__Event_attendee_session__c                                                                           
                            WHERE CnP_PaaS_EVT__Registrant_session_Id__c =:registrantId
                            AND CnP_PaaS_EVT__Registration_level__c =:ticketLevelId         
                            AND DTCI_Attendee_Info_Entered__c = FALSE
                            AND DTCI_Agreement_Active__c = FALSE
                            ORDER BY DTCI_Ticket_Order__c
                            LIMIT 1
                            ];
                            
                        return nextAvailableTicket;
        }  

public PageReference saveAttendee(){
            
            if(String.isBlank(attendeeId)){

                for (CnP_PaaS_EVT__Event_attendee_session__c firstResult : nextAvailableTicket(registrantId, ticketLevelId)) {
                     attendee = firstResult;
                     if (isMinor == true){
                        releaseType = 'Minor Visitor';
                        } else {
                        releaseType = 'Adult Visitor';    
                        }                    
                    break;
                    }
                }    
                                                             
        attendee.CnP_PaaS_EVT__First_name__c = attendeeFirstName;
        attendee.CnP_PaaS_EVT__Last_name__c = attendeeLastName ;
       ... (other fields)
        attendee.DTCI_Release_Type__c = releaseType;

        // last variable sets a checkbox field to checked so this ticket is no longer available for the nextAvailableTicket
        attendee.DTCI_Attendee_Info_Entered__c = attendeeInfoEntered;

       update attendee;
                                               
        PageReference sendToReleaseForm = new PageReference('/apex/DTCI_Release_Form_Page_AB' + '?attendeePageId=' + attendee.id + '&registrantPageId=' + registrantId + '&eventPageId=' + eventId + '&releasePageType=' + releaseType);  

       sendToReleaseForm.setRedirect(true);                        
       return sendToReleaseForm;
            
    } 

// functions for the Minor Question page, these originally included a query that updated the releaseType based on the response, and thus cause the overlap at check-in

       public PageReference minorYes(){...} 
       public PageReference minorYes(){..}    

  }




 
Amanda Byrne- Carolina Tiger RescueAmanda Byrne- Carolina Tiger Rescue
I DID IT, I DID IT!

The variables are declared, and 'got' and 'set' , but I needed to select the record I was updating in one of the methods. When I created the List for the query results, I needed to include all my fields in order to update them later, but the List reset the values of the variables from the ones I had collected from the form to the empty ones in the database.

I changed
for (CnP_PaaS_EVT__Event_attendee_session__c firstResult : nextAvailableTicket(registrantId, ticketLevelId)) {

                     attendee = firstResult;

(nextAvailableTicket is a List method that calls the record to use)

and instead of setting attendee = firstResult, I set attendee.id=firstResult.Id, so I wasn't writing over all my existing values!
Of course now it seems obvious.

HURRAY!!!!!!

(my head hurts)

 
pigginsbpigginsb
That's well done! Congratulations!