You need to sign in to do that
Don't have an account?

VF controller extension - binding record to controller, then passing it to another page w/ same controller
I'm building an app to move Chatter from leads to contact/acct/oppty upon lead conversion.
I want to allow customers to pick which of the 3 objects to move the feed to (or can be all 3), and want to store that in a custom setting.
I figure a VF page is the best way to go to show the settings, but I'm struggling with the some very basic concepts. How do I:
1) Load the custom setting row when the detail page loads
2) From an "Edit" button on that detail page, pass the record to the edit page
My controller code doesn't seem to do either of these right now:
public with sharing class LeadConvertChatterController{ public final LeadConvertChatter__c lcc; public static String settingName='default'; public LeadConvertChatterController(ApexPages.StandardController controller) { this.lcc=getSetting(); }//LeadConvertChatterCustomSettingsController //need new button that creates the defaults if they aren't there yet. needs to be hidden if there is a record, and then show the details instead public PageReference newSetting(){ PageReference pageRef=null; return pageRef; } public PageReference editSetting(){ PageReference pageRef=page.LeadConvertChatterSetupEdit; return pageRef; } public LeadConvertChatter__c getSetting(){ Map<String, LeadConvertChatter__c> settings=LeadConvertChatter__c.getAll(); if (settings.containsKey(settingName)==FALSE){ LeadConvertChatter__c setting=new LeadConvertChatter__c(Name=settingName, Contact__c=TRUE, Account__c=FALSE, Opportunity__c=FALSE, MergeLeadContact__c=TRUE); insert setting; return setting; }else{ LeadConvertChatter__c setting=settings.get(settingName); return setting; } }//getSettings }//LeadConvertChatterController
VF detail page which doesn't seem to take the record assignment in the controller:
<apex:page standardController="LeadConvertChatter__c" extensions="LeadConvertChatterController"> <apex:sectionHeader title="Lead Convert Chatter Settings" subtitle="Edit Settings" /> <apex:form > <apex:pageBlock title="Edit Settings" id="thePageBlock"> <apex:pagemessages /> <b><Font Color="#FF0000"></Font></b> <apex:pageBlockButtons > <apex:commandButton value="Edit" action="{!editSetting}"/> </apex:pageBlockButtons> <apex:pageBlockSection title="Where should Chatter people posts on the Lead move upon Lead Convert?"> <table > <tbody> <tr> <td> <apex:outputField value="{!LeadConvertChatter__c.Contact__c}"/> </td> </tr> <tr> <td> <apex:outputField value="{!LeadConvertChatter__c.Account__c}"/> </td> </tr> <tr> <td> <apex:outputField value="{!LeadConvertChatter__c.Opportunity__c}"/> </td> </tr> </tbody> </table> </apex:pageBlockSection> <apex:pageBlockSection title="Should Chatter posts be moved on Lead or Contact merge?"> <table> <tbody> <tr> <td> <apex:outputField value="{!LeadConvertChatter__c.MergeLeadContact__c}"/> </td> </tr> </tbody> </table> </apex:pageBlockSection> </apex:pageBlock> </apex:form> </apex:page>
It looks like you're using a List type Custom Setting. You probably meant to use a heirarchy custom setting. Once you use that type of custom setting, you can use "MyCustomSetting__c.getInstance( UserInfo.getUserId( ) )" to retrieve their settings, or if they have none, the default settings from their profile or the org (which you can then upsert to save). You probably don't mean to use an extension, either, just a custom controller would be acceptable. The heirarchy custom setting is actually designed to provide "per-user customization" settings, as opposed to the other type, which is generally used to store "org-wide settings" of defined values (such as the countries of the world).
All Answers
It looks like you're using a List type Custom Setting. You probably meant to use a heirarchy custom setting. Once you use that type of custom setting, you can use "MyCustomSetting__c.getInstance( UserInfo.getUserId( ) )" to retrieve their settings, or if they have none, the default settings from their profile or the org (which you can then upsert to save). You probably don't mean to use an extension, either, just a custom controller would be acceptable. The heirarchy custom setting is actually designed to provide "per-user customization" settings, as opposed to the other type, which is generally used to store "org-wide settings" of defined values (such as the countries of the world).
Thanks! I felt dumb for not realizing the extension vs. custom controller thing before, and fixed the problem easily with that. New code:
Controller: