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
RajashriRajashri 

Pickup current Lead Id

Hi,

I have hardcoded the lead id in my code.Can anyone please tell me how to get the current lead Id.

I have hardcoded the leadid in my code and it works fine.

Below is my code..just need  help in how to  pickup the Lead Id dynamically like :camp.Id

public with sharing class singleListView {
    public Campaign camp {get; set; }
    
    public singleListView(ApexPages.StandardController controller) {
        camp = (Campaign)controller.getRecord();
        
    }
    
   private List<Schema.Lead> CampaignMembers;
    public List<Schema.Lead> getCampaignMembers() {
   CampaignMembers=[Select Id,Name,(Select id, Campaign.Name,Contact.Phone,Lead.FirstName,Lead.LastName,LeadID,Lead.Phone,Lead.Email, Lastmodifieddate,Status,CampaignId,Campign_ID__c,Lead.MobilePhone  From CampaignMembers where CampaignId =:camp.Id and Status != '' and LeadId != null), 
(Select Subject, Id,lastModifiedDate From ActivityHistories  where lastModifiedDate !=null and Subject !=null order by LastModifiedDate desc limit 1) 
From Lead  where Name !=NULL and Id='00Q90000008fA5OEAU'  order by LastModifiedDate desc];

       return CampaignMembers;
       
     
         }     }
         
Karamala DamodarKaramala Damodar
if u r using page then use apexpages.currentpage().getparameters().get('id');
RajashriRajashri
Thanks. I tried that but it's not working.I want Lead associated with that Campaign Member record and i am in Campaign Layout
Venkat PolisettiVenkat Polisetti
Rajashri,

Can you tells us where and how are you trying to use this class? 

A screen shot will convey a lot of info and also please use "Add Code Sample" button in the editor pallette (< > ).

Thanks,
Venkat 
 
RajashriRajashri
I am using this class in my VF page and i am embedding that VF page in the standard layout campaign.Basically i am trying to change the Campaign Member Related list in the Campaign Layout to Custom List as per the requirement but i am not able to map the Lead Id associated with that Campaign Member.

Below is my VF page code...

<apex:page StandardController="Campaign"  extensions="singleListView">

<apex:form >

        <apex:pageBlock title="Campaign Members Details" mode="maindetail">
                         <apex:pageBlockSection title="Campaign Members"  id="cm3">

                <apex:pageblocktable value="{!CampaignMembers}" var="cm">
                <!-- <apex:column headerValue="Name">
                                 <apex:outputfield value="{!cm.Name}"/>
                                  </apex:column>-->

                           <apex:column >
                  <!-- <apex:outputLink value="{!$Page.somePage}?oppId={!opportunityFromController.Id}" target="_top">click here</apex:outputLink>-->
                 <!-- <apex:outputLink value="{!$Page.singleListView}" >Edit</apex:outputLink>-->

                               <apex:pageblocktable value="{!cm.CampaignMembers}" var="cpm"> 
                                 <apex:column headerValue="Action">
                                 <apex:outputLink value="{!$Page.Edit}" style="color:blue">Edit</apex:outputLink> 
                                    <apex:outputLink value="{!$Page.Delete}" style="color:blue">|Del</apex:outputLink> 
                                   </apex:column> 
                                                        

                                   <apex:column headerValue="Status">

                                       <apex:outputfield value="{!cpm.Status}" rendered="{!cpm.Status != null}"/>

                                    </apex:column> 
                                   
                                  <apex:column headerValue="Name">
                                 <apex:outputfield value="{!cpm.LeadID}" rendered="{!cpm.LeadID != null}"/>
                                  </apex:column>
                                  <apex:column headerValue="Phone">
                                 <apex:outputfield value="{!cpm.Lead.Phone}" rendered="{!cpm.Lead.Phone != null}"/>
                                  </apex:column>
                                    <apex:column headerValue="Mobile">
                                 <apex:outputfield value="{!cpm.Lead.MobilePhone}" />
                                  </apex:column>  
                                  <apex:column headerValue="Email">
                                 <apex:outputfield value="{!cpm.Lead.Email}" rendered="{!cpm.Lead.Email != null}"/>
                                  </apex:column>
                                  <apex:column headerValue="Last Modified Date">
                                 <apex:outputfield value="{!cpm.lastmodifieddate}" rendered="{!cpm.lastmodifieddate != null}"/>
                                  </apex:column>     
                                                                                           

                               </apex:pageblocktable>

                </apex:column>
                        
                   <apex:column >

                               <apex:pageblocktable value="{!cm.ActivityHistories}" var="tm">

                                   <apex:column headerValue="Subject">

                                       <apex:outputfield value="{!tm.Subject}"  rendered="{!tm.Subject != null}"/> 
                                         <!--<apex:outputText value="{! IF((tm.Subject== null), 'NA', tm.Subject) }"/>-->
                                       
                                       

                                   </apex:column>
                                    <apex:column headerValue="Last Modified Date">
                               <apex:outputfield value="{!tm.LastmodifiedDate}" rendered="{!tm.LastmodifiedDate != null}"/>
                         </apex:column>

                               </apex:pageblocktable>

                           </apex:column>

            </apex:pageblocktable>

            
                         </apex:pageBlockSection>
        </apex:pageBlock>

    </apex:form>

</apex:page>

 
RajashriRajashri
I am using this class in my VF page and i am embedding that VF page in the standard layout campaign.Basically i am trying to change the Campaign Member Related list in the Campaign Layout to Custom List as per the requirement but i am not able to map the Lead Id associated with that Campaign Member.

Below is my VF page code...

<apex:page StandardController="Campaign"  extensions="singleListView">

<apex:form >

        <apex:pageBlock title="Campaign Members Details" mode="maindetail">
                         <apex:pageBlockSection title="Campaign Members"  id="cm3">

                <apex:pageblocktable value="{!CampaignMembers}" var="cm">
                <!-- <apex:column headerValue="Name">
                                 <apex:outputfield value="{!cm.Name}"/>
                                  </apex:column>-->

                           <apex:column >
                  <!-- <apex:outputLink value="{!$Page.somePage}?oppId={!opportunityFromController.Id}" target="_top">click here</apex:outputLink>-->
                 <!-- <apex:outputLink value="{!$Page.singleListView}" >Edit</apex:outputLink>-->

                               <apex:pageblocktable value="{!cm.CampaignMembers}" var="cpm"> 
                                 <apex:column headerValue="Action">
                                 <apex:outputLink value="{!$Page.Edit}" style="color:blue">Edit</apex:outputLink> 
                                    <apex:outputLink value="{!$Page.Delete}" style="color:blue">|Del</apex:outputLink> 
                                   </apex:column> 
                                                        

                                   <apex:column headerValue="Status">

                                       <apex:outputfield value="{!cpm.Status}" rendered="{!cpm.Status != null}"/>

                                    </apex:column> 
                                   
                                  <apex:column headerValue="Name">
                                 <apex:outputfield value="{!cpm.LeadID}" rendered="{!cpm.LeadID != null}"/>
                                  </apex:column>
                                  <apex:column headerValue="Phone">
                                 <apex:outputfield value="{!cpm.Lead.Phone}" rendered="{!cpm.Lead.Phone != null}"/>
                                  </apex:column>
                                    <apex:column headerValue="Mobile">
                                 <apex:outputfield value="{!cpm.Lead.MobilePhone}" />
                                  </apex:column>  
                                  <apex:column headerValue="Email">
                                 <apex:outputfield value="{!cpm.Lead.Email}" rendered="{!cpm.Lead.Email != null}"/>
                                  </apex:column>
                                  <apex:column headerValue="Last Modified Date">
                                 <apex:outputfield value="{!cpm.lastmodifieddate}" rendered="{!cpm.lastmodifieddate != null}"/>
                                  </apex:column>     
                                                                                           

                               </apex:pageblocktable>

                </apex:column>
                        
                   <apex:column >

                               <apex:pageblocktable value="{!cm.ActivityHistories}" var="tm">

                                   <apex:column headerValue="Subject">

                                       <apex:outputfield value="{!tm.Subject}"  rendered="{!tm.Subject != null}"/> 
                                         <!--<apex:outputText value="{! IF((tm.Subject== null), 'NA', tm.Subject) }"/>-->
                                       
                                       

                                   </apex:column>
                                    <apex:column headerValue="Last Modified Date">
                               <apex:outputfield value="{!tm.LastmodifiedDate}" rendered="{!tm.LastmodifiedDate != null}"/>
                         </apex:column>

                               </apex:pageblocktable>

                           </apex:column>

            </apex:pageblocktable>

            
                         </apex:pageBlockSection>
        </apex:pageBlock>

    </apex:form>

</apex:page>

 
Venkat PolisettiVenkat Polisetti
First, there are several issues with your code:
  1. getCampaignMemebers() return type is Lead where as you are returning a List. I believe, you should return a list as this method is used in the pageblock table in your VF page
  2. A Campaign can have Leads or Contacts as members. You should return both. If want to show Lead/Contact details along with the member record, you cannot return that as part of the member record. You may want to have an inline class with member details as well as the activityhistory. Create a list of this new inline class type and iterate over it.
  3. Campaign Members is a child of Campaign and when you inline a VF page on Campaign Page layout you will not get Campaign member as a param, only the Campaign.
Thanks,
Venkat
RajashriRajashri
Thanks Venkat..Can you please send me code for help