I have an apex class with one method that returns a list of Standard Campaign objects that I'm trying to print in a visualforce page. For some reason, the list does not print in the visualforce page but another list of a custom type (defined in the class) is successfully printed on the page. In the visualforce page, I'm setting the controller attribute to the name of the controller class so I was thinking that maybe the controller doesn't recognize objects of types that aren't specified in the <apex:page/>
tag.
I'm not directly extending any classes in the visualforce page and I'm accessing other classes besides Campaign so I'm not sure if I would need to set each sObject I use as a controller or even how I would do that. How do I display standard objects in a visualforce page?
EDIT: visual force page code:
<apex:page controller="CreateCampaign" >
<apex:form >
<apex:pageBlock title="Quick Edit: ">
<apex:pageBlockButtons >
<apex:commandButton action="{!createCampaignFromPage}" value="Save"/>
</apex:pageBlockButtons>
</apex:pageBlock>
<h1>Hello World</h1>
<apex:repeat value="{!availMailingsRet}" var="string" id="theRepeat3">
<apex:outputText value="{!string}" id="theValue3"/><br/>
</apex:repeat> //This works
<apex:repeat value="{!campaignsRet2}" var="string" id="theRepeat4">
<apex:outputText value="{!string}" id="theValue3"/><br/>
</apex:repeat> // This doesn't
</apex:form>
</apex:page>
CONTROLLER CODE:
The method included in the snippet below works if I switch out the standard Campaign
object with CampaignObj
which is a class defined within the controller
public class CreateCampaign {
public static List<CampaignMember> campaignMembersRet {get; set;}
public static List<AvailableMailing> availMailingsRet {get; set;}
public static List<Campaign> campaignsRet {get; set;}
public static List<CampaignObj> campaignsRet2 {get; set;}
public List<Campaign> upsertCampaigns(){
/*Create campaigns that don't currently exist
*/
List<Campaign> campaigns = new List<Campaign>();
List<AvailableMailing> availMailings = getAvailableMailings();
List<Integer> campaignsNotFound = new List<Integer>();
List<Campaign> allCampaigns = [SELECT Id , Campaign_Key__c FROM Campaign WHERE Campaign_Key__c <> ''];
List<CampaignObj> nullCampaigns = new List<CampaignObj>();
for(Integer i = 0; i < availMailings.size(); i++){
for(Campaign cmp : allCampaigns ){
if(availMailings[i].Campaign_Key == cmp.Campaign_Key__c){
break;
}
}
campaignsNotFound.add(i);
}
for(Integer i = 0; i < campaignsNotFound.size();i++){
AvailableMailing currentMailing = availMailings[campaignsNotFound[i]];
Campaign camp = new Campaign(Campaign_Key__c = currentMailing.Campaign_Key, name = currentMailing.name,Mailing_ID__c= currentMailing.MailingId,Type = currentMailing.type);
campaigns.add(camp);
}
try{
upsert campaigns Campaign_Key__c;
}
catch (DmlException e) {
System.debug(e.getMessage());
}
return campaigns;
}
{! }
) inline or in the components you are using.