+ Start a Discussion
sfg1sfg1 

display campaign id in SITE using visualforce page

I tried to display campaign id in site using visulforce page, but i am not able to display.My code is not working fine. Can i use standard controller? if not please let me know. Whether i need to try different code for SITES. please guide me.

class:
public class CampaignRecordIdController{
public String campaignRecordId {get;set;}
public String parameterValue {get;set;}
public Campaign cam{get;set;}
  public CampaignRecordIdController(ApexPages.StandardController controller) {
        campaignRecordId  = ApexPages.CurrentPage().getparameters().get('id');
        cam = [select name,Promotion_Details__c from Campaign where id =: campaignRecordId ];
        parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');      
}
}
Page:
public class CampaignRecordIdController{
public String campaignRecordId {get;set;}
public String parameterValue {get;set;}
public Campaign cam{get;set;}
   public CampaignRecordIdController(ApexPages.StandardController controller) {
       campaignRecordId  = ApexPages.CurrentPage().getparameters().get('id');
       cam = [select name,Promotion_Details__c from Campaign where id =: campaignRecordId ];
       parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');
         }
}
Best Answer chosen by sfg1
Balayesu ChilakalapudiBalayesu Chilakalapudi
Try like this,
 
<apex:page Controller="CampaignRecordIdController">
       <apex:pageBlock >
        <<apex:pageBlockSection title="Current Campaign record Id is : {!campaignRecordId}" collapsible="false">
            <apex:outputField value="{!cam.name}"/>
            <apex:outputField value="{!cam.Promotion_Details__c}"/>
         </apex:pageBlockSection>-->
    </apex:pageBlock>
 
</apex:page>

class:
 
public class CampaignRecordIdController{
    public String campaignRecordId {get;set;}
    public String parameterValue {get;set;}
    public Campaign cam{get;set;}
 
    public CampaignRecordIdController() 
    {
        campaignRecordId =System.currentPageReference().getParameters().get('id');
        cam = [select name,Promotion_Details__c from Campaign where id =: campaignRecordId ];
       //parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');
    }
}

 

All Answers

Balayesu ChilakalapudiBalayesu Chilakalapudi
pass campaign Id as a parameter to your VF page. suppose VFPAGE is the name of your page then it would be

https://yoursalesforceinstance.com/VFPAGE?id='your campaign id'
 
sfg1sfg1
Hi Bala, it is working fine if i pass the campaign id, but, if i add that page to SITE it is not working. PLease suggest me if i need to modify my code to work in SITE.
Balayesu ChilakalapudiBalayesu Chilakalapudi
In the controller of that page, pass the id as given below
 
public PageReference saveNextResponse(){
    //doing a DML as well
    pageRef = new PageReference('/apex/VFPAGE');
    pageRef.setRedirect(true);
    Campaign campId=[SELECT Id FROM Campaign LIMIT 1];
    pageRef.getParameters().put('id',campId);
    return pageRef;
}

 
sfg1sfg1
Hi Bala, Standard controller is not supporting in SITE, can you help me the below logic to work in custom controller.
page:

<apex:page standardController="Campaign" Extensions="CampaignRecordIdController">
       <apex:pageBlock >
        <!--<apex:pageBlockSection title="Current Campaign record Id is : {!campaignRecordId}" collapsible="false">
            <apex:outputField value="{!cam.name}"/>
            <apex:outputField value="{!cam.Promotion_Details__c}"/>
         </apex:pageBlockSection>-->
    </apex:pageBlock>
 
</apex:page>

class:

public class CampaignRecordIdController{
    public String campaignRecordId {get;set;}
    public String parameterValue {get;set;}
    public Campaign cam{get;set;}
 
    public CampaignRecordIdController(ApexPages.StandardController controller) 
    {
        campaignRecordId =System.currentPageReference().getParameters().get('id');
        cam = [select name,Promotion_Details__c from Campaign where id =: campaignRecordId ];
       //parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');
    }
}
 
Balayesu ChilakalapudiBalayesu Chilakalapudi
Try like this,
 
<apex:page Controller="CampaignRecordIdController">
       <apex:pageBlock >
        <<apex:pageBlockSection title="Current Campaign record Id is : {!campaignRecordId}" collapsible="false">
            <apex:outputField value="{!cam.name}"/>
            <apex:outputField value="{!cam.Promotion_Details__c}"/>
         </apex:pageBlockSection>-->
    </apex:pageBlock>
 
</apex:page>

class:
 
public class CampaignRecordIdController{
    public String campaignRecordId {get;set;}
    public String parameterValue {get;set;}
    public Campaign cam{get;set;}
 
    public CampaignRecordIdController() 
    {
        campaignRecordId =System.currentPageReference().getParameters().get('id');
        cam = [select name,Promotion_Details__c from Campaign where id =: campaignRecordId ];
       //parameterValue = ApexPages.CurrentPage().getparameters().get('nameParam');
    }
}

 
This was selected as the best answer
sfg1sfg1
Bala, in visualforce page it is working fine. But if i add that visualforce page to 'SITE' it is throwing error, "Authorization required". at profile level i have given permission at object,field,VF page and class. Please guide me in this.
Balayesu ChilakalapudiBalayesu Chilakalapudi
Open public access settings of your site and and enable permissions for your campaign object and also it's fields.
make sure that the VF page you are accessing must be added to your site page list as well.
sfg1sfg1
Bala, i have enabled permission for campaign object  and its related fields, VF page. Still i am getting "Authorization required" error. Any suggesttions Bala.
sfg1sfg1
Thanks for your help Bala.Now it is working fine. I copied wrong URL.