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
Andrew DayAndrew Day 

how do i take my ids from the url and get a list of objects

Hey Guys,

I am try to put together my first vf page and I have a question.

The page I am creating is a page where the user can select some contacts from the contact page then pust a button called 'Create Event' that will take then to a page where that can fill out the event info and the selected contacts will be assigned then saved.

So right now I have a button then when clicked will take them to the new page with the selected Id's in the URL.

ex:  &type=whoid&Ids=003e000000IidjU%2C003e000000Iidji%2C003e000000HkFlA

I would like to display a list of the selected contacts in the new page but I am not sure how to get a list a contact objects form the Id's in the URL.

Here is my event page: (note: this is just a start)

<apex:page standardController="Event" extensions="CreateEvent_Controller" >
  <h1>Create Event With Selected Contacts</h1>
  <apex:sectionHeader title="Event" subtitle="New Event" help="/help/doc/user_ed.jsp?loc=help&target=creating_tasks.htm&section=Activities"/>
 <apex:form >
     <apex:pageMessages ></apex:pageMessages>
     <apex:pageBlock title="Event Edit"  mode="edit">
         <apex:pageBlockSection columns="1" title="Event Information"  >
        
                <apex:inputField value="{!Event.Subject}" />
                <apex:inputField value="{!Event.Location}" />
                <apex:inputField value="{!Event.StartDateTime}" />
                <apex:inputField value="{!Event.EndDateTime}" />
               
         </apex:pageBlockSection>
        
         <apex:pageBlockSection columns="1" title="Description Information" >
                 <apex:inputTextarea value="{!Event.Description}" cols="75" rows="5" richText="false"/>
         </apex:pageBlockSection>
        
         <apex:pageBlockSection columns="1" title="Description Information" >
            <apex:dataList value="{!contacts}" var="contact">
                <apex:outputText value="{!contact.Name}"/>
            </apex:dataList>
         </apex:pageBlockSection>  
           
         <apex:pageBlockButtons >
             <apex:commandButton value="Save" action="{!save}" immediate="true" />
             <apex:commandButton value="Cancel" action="{!cancel}" immediate="true" />
         </apex:pageBlockButtons>
     </apex:pageBlock>
    
 </apex:form>
</apex:page>

And here in my controller:

public with sharing class CreateEvent_Controller
{

   
    public ApexPages.StandardController myUserController {get; set;}
    public List<Contact> contacts {get; set;}


    public ApexPages.StandardController standardContactController;
   
    public CreateEvent_Controller(ApexPages.StandardController cntrl)
    {
   
        standardContactController = cntrl;
       
        /*contacts = (Contact)cntrl.getRecord();*/
   
    }
   
}

Any help on how to get the contact object list would be great, and any overall suggestions after that would be helpfull






MaddySinghMaddySingh
MaddySingh
I believe you are seperating your ids via a ,(comma)
Try seperating it using  semi colon ;

And then use this code in your constructor.

String ids = ApexPages.currentPage().getParameters().get('Ids');
List<Id> theIds = ids.split(';');

then do your procesing. I mean add a query using these ids,

List<Contact> contacts = Select  Name from contact where id in: theIds;

Display these using pageblock table or list
Andrew DayAndrew Day

thanks for your help, it was suggested to me do take a different approch so now my page header looks like

 <apex:page standardController="Contact"  recordSetVar="contacts" extensions="CreateEvent_Controller">

and this gives my the selected contacts just fine, I changed to this because if they select to many contacts then
my url could exceed the max length for a url.

I no longer have a check for items being selected before the button click but I will come back to that one later.

But I now have another issue mabe you can help me with.

I am trying to insert an event, when my event gets inserted and the values are hard coded in my controller it works
fine but if i comment out the hard coded values and use the vf page values I get a required field error.

The values from my vf page to not look to be getting populated into my event object in my controller.

vf page:

<apex:page standardController="Contact"  recordSetVar="contacts" extensions="CreateEvent_Controller">
  <h1>Create Event With Selected Contacts</h1>
  <apex:sectionHeader title="Event" subtitle="New Event" help="/help/doc/user_ed.jsp?loc=help&target=creating_tasks.htm&section=Activities"/>
  <apex:form >
      <apex:pageMessages >
      </apex:pageMessages>
    
         <apex:pageBlock title="Event Edit"  mode="edit">
        
             <apex:pageBlockSection columns="1" title="Event Information"  >
            
                    <apex:inputField value="{!event.Subject}" />
                    <apex:inputField value="{!event.Location}" />
                    <apex:inputField value="{!event.StartDateTime}" />
                    <apex:inputField value="{!event.EndDateTime}" />
                   
             </apex:pageBlockSection>
        
             <apex:pageBlockSection columns="1" title="Description Information" >
                     <apex:inputTextarea value="{!event.Description}" cols="75" rows="5" richText="false"/>
             </apex:pageBlockSection>   
        
             <apex:pageBlockButtons >
                 <apex:commandButton value="Save" action="{!SaveEvent}" immediate="true"  disabled="{!ISNULL(selected)}" />
                 <apex:commandButton value="Cancel" action="{!cancel}" immediate="true" />
             </apex:pageBlockButtons>
            
             <apex:pageBlockSection columns="1" title="Selected Contacts" >
                    <apex:dataList value="{!selected}" var="contact">
                        <apex:outputText value="{!contact.Name}"/>
                    </apex:dataList>
                     <apex:outputText rendered="{!ISNULL(selected)}" value="No Contact Records Selected"  />
             </apex:pageBlockSection>   
            
         </apex:pageBlock>
    
  </apex:form>
</apex:page>


controller:

public with sharing class CreateEvent_Controller
{

    public Event event {get; set;}
    private ApexPages.StandardSetController standardSetController ;

    public CreateEvent_Controller(ApexPages.StandardSetController controller)
    {
   
        standardSetController = controller;
       
        event = new Event();

    }

    public PageReference SaveEvent()
    {
   
        System.debug('AD TEST: Save Event');
   
        //event.Description = 'gfdgsdfg';
        event.OwnerId = UserInfo.getUserId(); //Assigned To
        event.WhoId = '003e000000IidjU'; //Name
        event.IsAllDayEvent = true;
        //event.StartDateTime = datetime.now();
        //event.EndDateTime = datetime.now().addDays(2);
        //event.Location = 'here';
        //Attendance
        //
        //

 

        insert event;
       
        PageReference pageRef = new PageReference('/003?fcf=00Bi0000003uX7v');
        //PageReference pageRef = ApexPages.currentPage();
        pageRef.setRedirect(true);
        return pageRef;
       
    }
   
    /*
   
    public ApexPages.StandardController myUserController {get; set;}
   


    public ApexPages.StandardController standardContactController;
   
    */
   
   
}