Created
February 15, 2012 18:52
-
-
Save joshbirk/1838114 to your computer and use it in GitHub Desktop.
Dynamic Field Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public with sharing class TestController { | |
public String mainContactField {get; set;} | |
public TestController(ApexPages.StandardController std) { | |
Contact c = (Contact)std.getRecord(); | |
mainContactField = 'Phone'; | |
List<Contact> cWithRecords = [SELECT Id, Phone, MobilePhone, AssistantPhone, OtherPhone from Contact where ID = :c.Id]; | |
if(cWithRecords.size() > 0) { | |
if(ApexPages.currentPage().getParameters().get('area') != null) { | |
if(cWithRecords[0].Phone.replaceAll('[^0-9]+','').startsWith(ApexPages.currentPage().getParameters().get('area'))) { | |
mainContactField = 'Phone'; | |
} | |
if(cWithRecords[0].MobilePhone != null && cWithRecords[0].MobilePhone.replaceAll('[^0-9]+','').startsWith(ApexPages.currentPage().getParameters().get('area'))) { | |
mainContactField = 'MobilePhone'; | |
} | |
if(cWithRecords[0].AssistantPhone != null && cWithRecords[0].AssistantPhone.replaceAll('[^0-9]+','').startsWith(ApexPages.currentPage().getParameters().get('area'))) { | |
mainContactField = 'AssistantPhone'; | |
} | |
if(cWithRecords[0].OtherPhone != null && cWithRecords[0].OtherPhone.replaceAll('[^0-9]+','').startsWith(ApexPages.currentPage().getParameters().get('area'))) { | |
mainContactField = 'OtherPhone'; | |
} | |
} | |
} | |
//this is just a comment | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<apex:page standardController="Contact" extensions="TestController"> | |
<apex:form > | |
<apex:messages /> | |
Closest Phone Number: <apex:inputField value="{!Contact[mainContactField]}"/><apex:commandButton action="{!save}" value="Save" /> | |
<apex:outputPanel rendered="false"> | |
<!-- pull in values for std controller query --> | |
<apex:outputText value="{!Contact.Phone}" /> | |
<apex:outputText value="{!Contact.MobilePhone}" /> | |
<apex:outputText value="{!Contact.AssistantPhone}" /> | |
<apex:outputText value="{!Contact.OtherPhone}" /> | |
</apex:outputPanel> | |
</apex:form> | |
</apex:page> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment