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
shobana shobanashobana shobana 

how to show the event as seperate related list in pagelayout

Hi Everyone
 My scenario is to show the related events record of lead object  in pagelayout.
 For that i took visualforce page and extension controller.
Actually i am getting output but for delete action will get works when i refresh the page .
public class forevents {
public List<OpenActivity> open{get;set;}
    public Boolean refreshPage {get; set;}
    public List<Event> accs { get; set;}
    public Id leadld{get;set;}
    public string SelectedEventId { get; set;}
    public forevents(ApexPages.StandardController controller) {
       leadld = ApexPages.CurrentPage().getparameters().get('id');
        list<lead>   c =[SELECT Name, 
                                  (Select Id,Subject,IsTask, WhoId, ActivityDate,
                                    Status, Priority, OwnerId FROM OpenActivities WHERE IsTask=False) 
                            FROM Lead WHERE Id = :leadld];
        if(c.size() > 0){
            open = c[0].OpenActivities;
        }
        
        }
      
  
     public void DeleteEvent()
   {
   
   
      // if for any reason we are missing the reference 
      if (SelectedEventId == null) {
      
         return ;
         
      }

     
      // find the event record within the collection
     Event tobeDeleted = null;
     accs = [Select id, Whoid,description,subject,activitydate
               from event
               where Whoid=: leadld ]; 
      for(Event a : accs)
       if (a.Id == SelectedEventId) {
          tobeDeleted = a;
          break;
       }
      
      //if event record found delete it
      if (tobeDeleted != null) {
       Delete tobeDeleted;
      }
     
     
   }
  public Pagereference refresh()
  {
  PageReference secondPage = new PageReference('https://ap1.salesforce.com/{!Leadld}');
  secondPage.getParameters().put('id',Leadld); 
        secondPage.setRedirect(true);
         
        return secondPage; 
  
  }    
}


<apex:page standardController="Lead" extensions="forevents" >
<apex:form >
        <apex:pageBlock title="Open Events"  >          
<center><a href="https://ap1.salesforce.com/00U/e?who_id={!leadld}&retURL={!leadld}" target="_top"><button type="button">New Event</button></a>
</center>&nbsp;&nbsp;

                <apex:pageBlockTable value="{!open}" var="each"   ><br/>
                
                    <apex:column headerValue="Action">
                        <apex:outputlink value="/{!each.id}/e?retURL={!each.WhoId}" target="_top" style="font-weight:bold"> Edit </apex:outputlink>&nbsp;|&nbsp;
                       <a href="javascript:if (window.confirm('Are you sure?')) DeleteEvent('{!each.Id}');" style="font-weight:bold">Del</a>
                    </apex:column>
                    <apex:column headerValue="Subject" value="{!each.Subject}"/>
                    <apex:column headerValue="ActiveDate" value="{!each.ActivityDate}"/>
                    <apex:column headerValue="Status" value="{!each.Status}"/>
                </apex:pageBlockTable>
         </apex:pageBlock>
             <apex:actionFunction action="{!DeleteEvent}" name="DeleteEvent" reRender="form" >
                        <apex:param name="eventid" value="" assignTo="{!SelectedEventId}"/>
                    </apex:actionFunction>
                  
 </apex:form>
</apex:page>
Anyone help me out...
Thank you in advance.
Best Answer chosen by shobana shobana
Bhanu MaheshBhanu Mahesh
Hi Shobana,

You are displaying OpenActivity list in the page> so you have to remove that particular element from the list otherwise you need to query the OpenActivities again.

So it is better to remove from the list.

And also in page while reRender you have specified Id but there is no component with Id

Try below code

Extension:
public class forevents {
public List<OpenActivity> open{get;set;}
    public Boolean refreshPage {get; set;}
    public List<Event> accs { get; set;}
    public Id leadld{get;set;}
    public string SelectedEventId { get; set;}
    public forevents(ApexPages.StandardController controller) {
        leadld = ApexPages.CurrentPage().getparameters().get('id');
        list<lead>   c =[SELECT Name, 
                                (Select Id,Subject,IsTask, WhoId, ActivityDate,Status, Priority, OwnerId FROM OpenActivities WHERE IsTask=False) 
                           FROM Lead WHERE Id = :leadld];
        if(c.size() > 0){
            open = c[0].OpenActivities;
        }
    
    }
      
  
    public pageReference DeleteEvent(){
    
        // if for any reason we are missing the reference 
        if (SelectedEventId != null) {
            Event tobeDeleted = [SELECT Id FROM Event WHERE Id =:SelectedEventId];
            if(tobeDeleted != null){
                delete tobeDeleted;
            }
            
            for(Integer i=0;i < open.size();i++){
                if(open[i].Id == SelectedEventId){
                    open.remove(i);
                    i--;
                }
            }
        }
        
        return null;
    }
    public Pagereference refresh(){
        PageReference secondPage = new PageReference('https://ap1.salesforce.com/{!Leadld}');
        secondPage.getParameters().put('id',Leadld); 
        secondPage.setRedirect(true);
        
        return secondPage; 
    
    }    
}

VF Page
<apex:page standardController="Lead" extensions="forevents" >
    <apex:form id="form">
        <apex:pageBlock title="Open Events"  >          
            <center><a href="https://ap1.salesforce.com/00U/e?who_id={!leadld}&retURL={!leadld}" target="_top"><button type="button">New Event</button></a>
            </center>&nbsp;&nbsp;
            
            <apex:pageBlockTable value="{!open}" var="each"   ><br/>
                <apex:column headerValue="Action">
                    <apex:outputlink value="/{!each.id}/e?retURL={!each.WhoId}" target="_top" style="font-weight:bold"> Edit </apex:outputlink>&nbsp;|&nbsp;
                    <a href="javascript:if (window.confirm('Are you sure?')) DeleteEvent('{!each.Id}');" style="font-weight:bold">Del</a>
                </apex:column>
                <apex:column headerValue="Subject" value="{!each.Subject}"/>
                <apex:column headerValue="ActiveDate" value="{!each.ActivityDate}"/>
                <apex:column headerValue="Status" value="{!each.Status}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
        <apex:actionFunction action="{!DeleteEvent}" name="DeleteEvent" reRender="form" >
            <apex:param name="eventid" value="" assignTo="{!SelectedEventId}"/>
        </apex:actionFunction>
    
    </apex:form>
</apex:page>

If you are using refersh method for any other purpose keep it otherwise you can remove that method

Regards,
Bhanu Mahesh

 

All Answers

Bhanu MaheshBhanu Mahesh
Hi Shobana,

You are displaying OpenActivity list in the page> so you have to remove that particular element from the list otherwise you need to query the OpenActivities again.

So it is better to remove from the list.

And also in page while reRender you have specified Id but there is no component with Id

Try below code

Extension:
public class forevents {
public List<OpenActivity> open{get;set;}
    public Boolean refreshPage {get; set;}
    public List<Event> accs { get; set;}
    public Id leadld{get;set;}
    public string SelectedEventId { get; set;}
    public forevents(ApexPages.StandardController controller) {
        leadld = ApexPages.CurrentPage().getparameters().get('id');
        list<lead>   c =[SELECT Name, 
                                (Select Id,Subject,IsTask, WhoId, ActivityDate,Status, Priority, OwnerId FROM OpenActivities WHERE IsTask=False) 
                           FROM Lead WHERE Id = :leadld];
        if(c.size() > 0){
            open = c[0].OpenActivities;
        }
    
    }
      
  
    public pageReference DeleteEvent(){
    
        // if for any reason we are missing the reference 
        if (SelectedEventId != null) {
            Event tobeDeleted = [SELECT Id FROM Event WHERE Id =:SelectedEventId];
            if(tobeDeleted != null){
                delete tobeDeleted;
            }
            
            for(Integer i=0;i < open.size();i++){
                if(open[i].Id == SelectedEventId){
                    open.remove(i);
                    i--;
                }
            }
        }
        
        return null;
    }
    public Pagereference refresh(){
        PageReference secondPage = new PageReference('https://ap1.salesforce.com/{!Leadld}');
        secondPage.getParameters().put('id',Leadld); 
        secondPage.setRedirect(true);
        
        return secondPage; 
    
    }    
}

VF Page
<apex:page standardController="Lead" extensions="forevents" >
    <apex:form id="form">
        <apex:pageBlock title="Open Events"  >          
            <center><a href="https://ap1.salesforce.com/00U/e?who_id={!leadld}&retURL={!leadld}" target="_top"><button type="button">New Event</button></a>
            </center>&nbsp;&nbsp;
            
            <apex:pageBlockTable value="{!open}" var="each"   ><br/>
                <apex:column headerValue="Action">
                    <apex:outputlink value="/{!each.id}/e?retURL={!each.WhoId}" target="_top" style="font-weight:bold"> Edit </apex:outputlink>&nbsp;|&nbsp;
                    <a href="javascript:if (window.confirm('Are you sure?')) DeleteEvent('{!each.Id}');" style="font-weight:bold">Del</a>
                </apex:column>
                <apex:column headerValue="Subject" value="{!each.Subject}"/>
                <apex:column headerValue="ActiveDate" value="{!each.ActivityDate}"/>
                <apex:column headerValue="Status" value="{!each.Status}"/>
            </apex:pageBlockTable>
        </apex:pageBlock>
        <apex:actionFunction action="{!DeleteEvent}" name="DeleteEvent" reRender="form" >
            <apex:param name="eventid" value="" assignTo="{!SelectedEventId}"/>
        </apex:actionFunction>
    
    </apex:form>
</apex:page>

If you are using refersh method for any other purpose keep it otherwise you can remove that method

Regards,
Bhanu Mahesh

 
This was selected as the best answer
shobana shobanashobana shobana
Hi Bhanu Mahesh 
Thank you  for your help.
Its working good.....
Bhanu MaheshBhanu Mahesh
No Prob. Glad it helped.

Regards,
Bhanu Mahesh

Close the thread if your issue solved