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
XVLXVL 

Dynamic Apex Class to Reference Static Resources for Sites

Hello, 

I am trying to minimize the amount of sites that I use for a project. The project involves a site with a list of various white papers. The goal is that a link will send an individual to a site form. After submission the form sends one to a "Thank You Page" using  the Web2Lead Extension (and enters the data into Salesforce.  On the "Thank You Page" , there is a direct reference to the whitepaper.  I had to create a page for each. The way I have done this there is 1 site used for each series, but I would like to utilze a more dynamic apex class as the form is the same as is Thank You Page.  Does anyone have any idea how to do this? Below is my code. I have tried using get;set, but they system doesn't let me save. 

Web2Lead Form

<apex:page standardController="Lead" extensions="myWeb2LeadExtension" title="Contact Us" showHeader="false" standardStylesheets="false">

   <apex:define name="body">

   <apex:form >

    <apex:messages id="error" styleClass="errorMsg" layout="table" style="margin-top:1em;"/>

      <apex:pageBlock title="" mode="edit">

        <apex:pageBlockButtons >

           <apex:commandButton value="Save" action="{!saveLead}"/>

        </apex:pageBlockButtons>

        <apex:pageBlockSection title="Contact Us" collapsible="false" columns="1">

         <apex:inputField value="{!Lead.Salutation}"/>

         <apex:inputField value="{!Lead.Title}"/>

         <apex:inputField value="{!Lead.FirstName}"/>

         <apex:inputField value="{!Lead.LastName}"/>

         <apex:inputField value="{!Lead.Email}"/>

         <apex:inputField value="{!Lead.Phone}"/>

         <apex:inputField value="{!Lead.Company}"/>

         <apex:inputField value="{!Lead.Street}"/>

         <apex:inputField value="{!Lead.City}"/>

         <apex:inputField value="{!Lead.State}"/>

         <apex:inputField value="{!Lead.PostalCode}"/>

         <apex:inputField value="{!Lead.Country}"/>

        </apex:pageBlockSection>

     </apex:pageBlock>

   </apex:form>

  </apex:define>


</apex:page>



myWeb2LeadExtension

public class myWeb2LeadExtension {



    private final Lead weblead;



    public myWeb2LeadExtension(ApexPages.StandardController stdController) {

       weblead = (Lead)stdController.getRecord();

    }

    

     public PageReference saveLead() {

       try {

       insert(weblead);

       }

       catch(System.DMLException e) {

           ApexPages.addMessages(e);

           return null;

       }

     PageReference p = Page.ThankYouPageWhitePaper;

       p.setRedirect(true);

       return p;
      
    }
   
}


ThankYouPageWhitePaper



<apex:page showheader="false">
<head>
<link href="//fonts.googleapis.com/css?family=Varela+Round:400" rel="stylesheet" type="text/css"></link>
<title>2 Column CSS Layout - parellel design</title>
<style type='text/css'>
.container{
position: relative;
   left: 0.00%;
   width: 100.00%;
   background-color: #FFFFFFF
}
.header{
   position: relative;
   float: left;
   left: 0.00%;
   width: 100.00%;
   background-color: #FFFFFFF
}
.wrapper{
   left: 0.00%;
   width: 75.00%;
   height: 75.00%;
   background-color: #FFFFFFF
}
.left{
   position: relative;
   float: left;
   left: 0%;
   width: 25.00%;
   background-color: #F0F0F0
}
.right{
   position: relative;
   float: right;
   right: 0.00%;
   width: 75.00%;
   background-color: #FFFFFFF
}
.footer{
   position: relative;
   float: left;
   left: 0.00%;
   width: 100.00%;
   background-color: #FFFFFFF
}
body {
 
   margin:70px 40px 10px 50px;
   font-size: 90%;
   background-color: #FFFFFFF
   float: left;
}

</style>
</head>
<body>
<div class="container">
   <div class="header">
<center>
  <h1> Registration complete</h1>
<p>An email has been sent to you with a link to the document.</p>
<p>You should be redirected within 5 seconds. If you are not, then click the following link:
<a href= "http://sandbox-companywebsite.cs10.force.com/AD/whitepaper"> Click Here</a>
</p>
</center>
</div>
</div>
</body>
</apex:page>

White Paper


<apex:page showheader="false" showChat="false" sidebar="false">
<style>
object {display:block;position:absolute;height:100%;}
</style>
<object data="{!URLFOR($Resource.AACredit)}" type="application/pdf" width="100%" height="auto">

 
</object>
</apex:page>
Best Answer chosen by XVL
Bhawani SharmaBhawani Sharma
Probably you are looking for this:
https://developer.salesforce.com/blogs/developer-relations/2012/05/dynamic-apex-class-instantiation-in-summer-12.html