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
Shravan Kumar 71Shravan Kumar 71 

Drop Down in VF page

Hello There,

I would like to have a drop down option on "Event Type" for the below VF page. The result should display based on the Event type I select.
User-added image
Here is the Controller :
public class UserWebActivityController{
    
    public Account accld; 
    public Lead lID;
    public Opportunity opp;
    public String recordId;
    public List<WebActivity> userWebActivityLstAll{get;set;}
    String currentId = ApexPages.CurrentPage().getparameters().get('id'); 
    
    public UserWebActivityController (ApexPages.StandardController controller) {
    
    //Lead ID
        if (currentId.startsWith('00Q')) {
            try{
                String lEmail;
                String lAltEmail;
                
                recordId      = controller.getId();                
                lID = (Lead)controller.getRecord(); 
                if(lID!=null) {
                    List<Lead> ldLst = LeadSelector.getLeadFromIds(new set<Id>{lID.id});
                    if(ldLst.size()>0){
                        lEmail           = ldLst[0].email;
                        lAltEmail        = ldLst[0].Alternate_Email__c; 
                    }                 
                } 
                                 userWebActivityLstAll=UserWebActivityController.getUserDetailsFromObject(lEmail, lAltEmail); 
            }
            
            catch(exception e){
                system.debug('****Exception in page:-'+e.getMessage()+' at line number:- '+e.getLineNumber());
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'An internal exception has occurred. please contact administrator.'));
            }
        }
        
        
        //Account ID
        if (currentId.startsWith('001')) {
            try{
                String accEmail;
                String accAltEmail;
                
                recordId      = controller.getId();
                accld = (Account)controller.getRecord(); 
                if(accld!=null) {
                    List<Account> accLst = AccountSelector.getAccount(new set<Id>{accld.id});
                    if(accLst.size()>0){
                        accEmail           = accLst[0].PersonEmail;
                        accAltEmail        = accLst[0].Alternate_Email__c; 
                    }                 
                } 
                
userWebActivityLstAll=UserWebActivityController.getUserDetailsFromObject(accEmail, accAltEmail); 
            }
            
            catch(exception e){
                system.debug('****Exception in page:-'+e.getMessage()+' at line number:- '+e.getLineNumber());
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'An internal exception has occurred. please contact administrator.'));
            }
        }
        
        //Opportunity ID
        if (currentId.startsWith('006')) {
            try{
                String accEmail;
                String accAltEmail;
                
                recordId      = controller.getId();
                opp = (Opportunity)controller.getRecord(); 
                if(opp!=null) {
                //  List <Opportunity> oppList = [SELECT id, AccountId FROM Opportunity WHERE ID=:oppId];
                //  if(oppList.size()>0 && oppList.get(0).AccountId!=null){
                   if(opp.AccountId!=null){ 
                    List<Account> accLst = AccountSelector.getAccount(new set<Id>{opp.AccountId});
                        if(accLst.size()>0){
                            accEmail           = accLst[0].PersonEmail;
                            accAltEmail        = accLst[0].Alternate_Email__c; 
                        }
                    }   
                                                
                } 
                
                  userWebActivityLstAll=UserWebActivityController.getUserDetailsFromObject(accEmail, accAltEmail); 
            }
            
            catch(exception e){
                system.debug('****Exception in page:-'+e.getMessage()+' at line number:- '+e.getLineNumber());
                ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,'An internal exception has occurred. please contact administrator.'));
            }
        }
    }
    
    
    // Method to get from the table 
    
    public static List<WebActivity> getUserDetailsFromObject(String accEmail, String accAltEmail) {
        List<WebActivity> userWebActivityLstAll = new List<WebActivity>();
        
        Set<String> emailIdSet= new Set<String>();
        if(accEmail!=null){
            
            emailIdSet.add(accEmail);
        }
        if(accAltEmail!=null){
            
            emailIdSet.add(accAltEmail);
        }
        
        
        if(emailIdSet.size()>0){ 
            Map<Id,Customer_Web_Activity__c>  customerWebActivity = CustomerWebActivitySelector.getCustomerWebActivityFromEmail(emailIdSet);
            
            for(Customer_Web_Activity__c custActivity : customerWebActivity.values()){
                
                WebActivity custWebActivity = new WebActivity();
                custWebActivity.email=custActivity.Email__c;
                custWebActivity.activityDateTime=custActivity.Activity_Time__c;
                custWebActivity.event_type=custActivity.Event_Type__c;
                custWebActivity.description=custActivity.Description__c;
                custWebActivity.url=custActivity.URL__c;
                custWebActivity.activity=custActivity;             
                userWebActivityLstAll.add(custWebActivity);
            }
        } 
    
       return   userWebActivityLstAll;
    }
    
    public class WebActivity{      
        public String email {get;set;} 
        public String activityTime {get;set;} 
        public Datetime activityDateTime{get;set;}
        public String event_type {get;set;}  
        public String description {get;set;}  
        public String url{get;set;}
        public Customer_Web_Activity__c activity{get;set;}
    }
}

Here is the VF Page :
 
<apex:page standardController="Lead" extensions="UserWebActivityController">
    <apex:form >

       <apex:pageBlock >
            
             <apex:pageMessages />

            <apex:pageBlockTable value="{!userWebActivityLstAll}" var="w">
                
                <apex:column headervalue="Time" >
                <apex:outputField value="{!w.activity.Activity_Time__c}"/>                                      
                </apex:column>
                
                <apex:column headervalue="Event Type" >
                    <apex:outputText value="{!w.event_type}"/>                    
                </apex:column>               
                
                <apex:column headervalue="Description" >
                    <apex:outputText value="{!w.description}"/>
                 <apex:outputPanel rendered="{!w.url!=null}"> 
                   <br/>
                    <apex:outputLink value="{!w.url}" target="_blank"><b>Click here for Email Template</b></apex:outputLink>  
                  </apex:outputPanel>                   
                </apex:column>                  
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>

Kindly do the needful.

Thanks,
Shravan