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

One Event for multiple Contacts


I need to assigen one event to mutliple contacts in my vf page

my scenario is :in the vf page if i select add(button) to enter the event details

I have one more button 'add contacts',

in the click of that button i have to select some contacts


If i save the records,i have to assigen that event to the all the selected contact.


here i write the vf page and class ,in my code only the first one inserting but it not assigening the multiple contacts.



this is the vf page

<apex:page standardController="Contact" extensions="ADD_Showings_To_Contact">
<apex:form >
<apex:pageBlock >
 <apex:commandLink value="Add New Showing" action="{!addshwoing}"  />
  <apex:pageBlockTable value="{!ev}"  var="e">
<apex:column headerValue="Subject">
        <apex:inputField value="{!e.Subject}"/>
    <apex:column headerValue="Name" >
        <apex:inputField value="{!e.WhoId}" />
    <apex:column headerValue="Start Date Time">
        <apex:inputField value="{!e.StartDateTime}"/>
    <apex:column headerValue="End Date Time">
        <apex:inputField value="{!e.EndDateTime}"/>
    <apex:column headerValue="Location">
        <apex:inputField value="{!e.Location}"/>
    <apex:column headerValue="Summary">
        <apex:inputField value="{!e.Summary__c}"/>
    <apex:column headerValue="Description">
        <apex:inputField value="{!e.Description}"/>
<apex:commandLink value="Add New Contact" action="{!addnewcontact}"  />
 <apex:pageBlockTable value="{!evt}"  var="et" rendered="{!addshwoingcntbtn}">
 <apex:column headerValue="Name" >
        <apex:inputField value="{!et.WhoId}" />

<apex:pageblockSection columns="1" >
       <apex:pageblockSectionItem >
                <apex:commandButton action="{!addshowingsavemethod}" id="saveButton" value="Save" />

this is my class

public class ADD_Showings_To_Contact {
public id conid{get;set;}
Contact con =new contact();
public list<Event> ev{get;set;}
public list<Event> evt{get;set;}
public event  addevent{get;set;}
public boolean addshwoingbtn{get;set;}
public boolean addshwoingcntbtn{get;set;}

    public ADD_Showings_To_Contact(ApexPages.StandardController controller) {
 conid= apexpages.currentpage().getparameters().get('id');
   con=[SELECT AccountId,stage__c,name,Email,Phone from contact where id=:conid];
         ev=new list<Event>();
                ev=[select WhatId,Subject,StartDateTime,Location,EndDateTime,Description,ShowAs from event where WhoId=:conid];
                 evt=new list<Event>();
evt=[select WhatId,Subject,StartDateTime,Location,EndDateTime,Description,ShowAs from event where WhoId=:conid];
    public void addshwoing()
       ev.add(new event());      
     public void addnewcontact()
    evt.add(new event());
     public pagereference addshowingsavemethod()
     insert ev;
     insert evt;
        system.debug('insert the addevent records'+ev);
        system.debug('insert the addeventsss records'+evt);
        catch(Exception e)
         pagereference pr=new pagereference('/apex/opportunitytab?id=conid');
    return pr;



Can one help me

Thanks to advance.





You can not assign one event to multiple contacts in you requirement for sure because the contacts and the number of contacts you have to select are dynamic.


The solution is to create the event for each of the contacts you selected. Suppose, if you have selected 4 contacts, you need to create 4 events (with the same details you entered) - each assigned to each of the contacts.




For your replay

Can you tel me the how can i assigen the same detials to all contacts