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
impalacrazy69impalacrazy69 

Save vf page record to parent object (master detail)

ok so hopefully i explain this correctly. So i have a VF page i have created (code will be below) that captures data from the user. What i need to have happen is when the record is saved it should be associated with a parent campaign. So the campaign is the master detail reocrd i want to have all records from the VF page associated with. I have the VF page working and am trying to right a controller to connect the master detail record (campaign Id) to the child record.

 

So in short user goes to VF page fills in data and when they hit save system relates this record to a campaign. Is this even possible?

 

VF Code:

 

<apex:page standardController="Spiff_Request__c">
  <apex:form >
    <apex:pageBlock title="Spiff Request" mode="Create">
                  
              <apex:pageBlockButtons >
                <apex:commandButton action="{!edit}" id="editButton" value="Edit"/>
                <apex:commandButton action="{!save}" id="saveButton" value="Save"/>
                <apex:commandButton onclick="resetInlineEdit()" id="cancelButton" value="Cancel"/>
              </apex:pageBlockButtons>

     <apex:pageBlockSection title="Spiff Request" columns="2">
         <apex:inputField value="{!Spiff_Request__c.When_was_date_of_Meeting__c}"/> <br></br>
         <apex:inputField value="{!Spiff_Request__c.Product_Interest__c}"/> <br></br>
         <apex:inputField value="{!Spiff_Request__c.New_Customer__c}"/> <br></br>
         <apex:inputField value="{!Spiff_Request__c.Reseller_Company_Name__c}"/>
         <apex:inputField value="{!Spiff_Request__c.Customer_Name__c}"/>
         <apex:inputField value="{!Spiff_Request__c.Reseller_Phone__c}"/>
         <apex:inputField value="{!Spiff_Request__c.Customer_Phone__c}"/>
         <apex:inputField value="{!Spiff_Request__c.Address_to_send_Spiff_to__c}"/>
         <apex:inputField value="{!Spiff_Request__c.Customer_Address__c}"/>
         <apex:inputField value="{!Spiff_Request__c.Who_Attended_Partner_Imperva__c}"/>
         <apex:inputField value="{!Spiff_Request__c.Who_Attended_Customer__c}"/>
         <apex:inputField value="{!Spiff_Request__c.Additional_Details__c}"/>
     </apex:pageBlockSection>
 
    </apex:pageBlock>
  </apex:form>
</apex:page>
             

Controller class code: (this is where im trying to pass the ID to match child recod to parent (the error i get is :

Save error: Initial term of field expression must be a concrete SObject: String)

 

public

withsharingclass CampaignID {

publicCampaign campaignID       {get;set;}

public CampaignID(ApexPages.StandardController sc)

 

{

 

  campaignID = sc.getID()campaign_ID;

 

}

public PageReference saveAndReject() {

 

PageReference requestPage = Page.AccountRecord;

requestPage.getParameters().put(campaignID,

Spiff_Request__c.CampaignID__c);

requestPage.setRedirect(

true);

return

requestPage;

 

}

}

 

I havent added the controller into the VF code yet becasue i cant get it to save.

 

Thanks for all replys....

 

empucempuc

Hi Impala,

 

Of course it is possible but not with Your controller ;) 

 

How the controller should know the right campaign id? how it will be passed? Can't You simply add a lookup field on your vf page to get it? or you want to passed in automagically?

 

Let me know, then I will try to help ya.

 

 

BR,

 

empuc

avijchakavijchak
All you need the campaign ID, Where from you launching your VF page ?
impalacrazy69impalacrazy69

I need the ID to pass automatically. The campaign will control when the page is visible to users. So when the user goes to create a record i need the ID pulled from the campaign without them having to look it up so once they complete the VF page and hit save the record is then added as a related record to the campaign.

impalacrazy69impalacrazy69

The page it launching from our portal page. The user will click a link that takes them to the VF page and once they hit save it should be associated with the parent campaign