Skip to main content
Will Edwards ha preguntado en #Apex
I'd like to write an Apex class that lists all campaigns with certain attributes. How do I write such an Apex class?
1 respuesta
  1. 22 jul 2016, 8:25
    Hi,

    Please check the below sample code.

    Apex Class

     

    public with sharing class CampaginList {

    public List<Campaign> listcamp { get; set; }

    public CampaginList(){

    listcamp= new List<Campaign>();

    listcamps();

    }

    public List<Campaign> listcamps(){

    listcamp=[select id, name ,StartDate,EndDate from Campaign limit 5];

    return listcamp;

    }

    }

    VisualForce Page:

     

    <apex:page controller="CampaginList">

    <apex:form >

    <apex:pageBlock >

    <apex:pageBlockTable value="{!listcamp}" var="c">

    <apex:column headerValue="Name">

    <apex:outputfield value="{!c.name}"/>

    </apex:column>

    <apex:column headerValue="StartDate">

    <apex:outputfield value="{!c.StartDate}"/>

    </apex:column>

    <apex:column headerValue="EndDate">

    <apex:outputfield value="{!c.EndDate}"/>

    </apex:column>

    </apex:pageBlockTable>

    </apex:pageBlock>

    </apex:form>

    </apex:page>

    Output:

    Hi,Please check the below sample code.

    Let me know if you need any help!

    Best Regards,

    Jyothsna

     
0/9000