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
joestuartjoestuart 

Form to pre-populate from Campaigns and save to cases

Hi,

 

This is my first force page form and I need to make a form with pre-populated fields and fields that need to be manually filled out.

The fields that are pre-populated will be populated from "campaign" but I don't want to update the campaign I want the form to save the data to "Cases" as it is a feedback form about a campaign.

 

This is the code I have so far, these are the fields that I want to pre populate.

 

<apex:page standardController="Campaign" sidebar="false">
<apex:pageBlock >
    <apex:form >
        <apex:pageblockSection >
            
             <apex:inputField value="{!Campaign.Organising_Contact__c}"/>
            <apex:inputField value="{!Campaign.Organising_Contact_Company__c}"/>
            <apex:inputField value="{!Campaign.Organising_Contact_Email__c}"/>
            <apex:inputField value="{!Campaign.Long_Start_Date__c}"/>
            <apex:inputField value="{!Campaign.Product_Name__c}"/>
            <apex:inputField value="{!Campaign.Facilitator__c}"/>
            <apex:commandButton action="{!save}" value="Save!"/>
        </apex:pageblockSection>
    </apex:form>
</apex:pageBlock>
</apex:page>

 But when I save it will update the controller "Campaign" so how do I tell it to make a new case and save it to "Cases"

 

Thank you in advance.  

I am new to force pages so I would appreciate any help on this or even if someone could point me in the right direction.

 

Joe

 

 

ezdhanhussainezdhanhussain

Create two objects in apex one for campaign one for cases. Assign the values you want to respective fields.

public class camcase{
public campaign cam{set;get;}//campaign object
public case cas{set;get;}//case object
//constructor
public camcase(){
cam = new campaign();
cas = new case();
}

public void save(){
cas.contact = Cam.Organising_Contact__c;
insert cas;
}

}

 here i am taking dummy fields you use your fields as required. Don't forget to supply data for mandatory fields in cases else insert operation will be failed

joestuartjoestuart

Thank you for your reply HussainSFDC.

 

Is there any way that I can add the apex class inline in the forcepage?  Or do I need to create an apex class file?

 

Thanks again

 

Joe

ezdhanhussainezdhanhussain
<apex:inputField value="{!cas.contact}"/>

 here is vf page code which creates an inline edit input field to contact. and this field gets data form campaign, as we have declared cas.contact = cam.Organising_contact__c;. Remember this value is assigned to case only when you call save method in controller through command button.