Skip to content

Instantly share code, notes, and snippets.

@sohalloran
Last active December 28, 2015 22:39
Show Gist options
  • Save sohalloran/7573581 to your computer and use it in GitHub Desktop.
Save sohalloran/7573581 to your computer and use it in GitHub Desktop.
Example of Search Before Create pattern using a Visualforce page
<apex:page standardController="Account" extensions="searchAccounts" sidebar="false" >
<apex:sectionHeader title="Convert Prospect" subtitle="Account Search and Create"/>
<apex:form id="form">
<apex:pageBlock id="crit_block">
<apex:pageblockSection columns="7" id="crit">
<apex:pageBlockSectionItem >
<apex:outputLabel value="Account Name:"/>
<apex:inputText value="{!name}" onkeypress="return noenter();"/>
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem id="buttons">
<apex:commandbutton id="searchBtn" rerender="results" value="Search" status="searchStatus"/>
<apex:commandbutton value="Cancel" action="{!cancel}" />
</apex:pageBlockSectionItem>
<apex:pageBlockSectionItem />
<apex:actionStatus id="searchStatus" startText="Searching..."/>
<apex:actionStatus id="addStatus" startText="Adding..."/>
<apex:pageBlockSectionItem />
</apex:pageblockSection>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageblockSection columns="1" id="results">
<apex:pageMessage rendered="{!name!=null}" severity="info" strength="1" title="Account Suggestions">
<apex:outputPanel rendered="{!name!='' && accounts.size==0}">
<b>{!name}</b> not found in your Customer Master Data.&nbsp;
</apex:outputPanel>
<apex:outputPanel rendered="{!accounts!='' && accounts.size>0}">
The following records match. If you still need to create a new account.&nbsp;
</apex:outputPanel>
<apex:outputPanel rendered="{!accId!=null}">
Create <b>{!account.name}</b> as a Customer Master by submitting it for approval.&nbsp;
<apex:commandButton action="{!URLFOR($Action.Account.Submit,accId,[retURL='/'+accId])}" value="Submit for Approval"/>
</apex:outputPanel>
<apex:outputPanel rendered="{!accId==null}">
Create <b>{!name}</b> as a Prospect Account first.&nbsp;
<apex:commandButton action="/001/e?acc2={!name}&nooverride=1" value="Create Prospect"/>
</apex:outputPanel>
</apex:pageMessage>
<apex:outputPanel rendered="{!accounts!='' && accounts.size>0}">
<apex:pageBlockTable value="{!accounts}" var="a">
<apex:column ><apex:facet name="header"></apex:facet>
<apex:commandLink rendered="{!a.Id==''}" value="Add" status="addStatus" action="{!addAccount}" reRender="results" title="Subscribe to this customer record from the MD Hub">
<apex:param value="{!a.Mdid}" name="mdId" assignTo="{!mdId}"/>
</apex:commandLink>
<br/>
<apex:outputText rendered="{!a.Id!=''}">
<apex:outputLink rendered="{!accId!=null}" target="_self" value="/apex/mergeAccounts?acc1={!a.Id}&acc2={!accId}" title="Merge your account with this Customer Master record">Merge</apex:outputLink>
</apex:outputText>
</apex:column>
<apex:column ><apex:facet name="header">MD Id</apex:facet><apex:outputLink value="{!$Label.MDM_URL}/acc/{!a.Mdid}">{!a.Mdid}</apex:outputLink></apex:column>
<apex:column ><apex:facet name="header">Id</apex:facet><apex:outputLink value="/{!a.Id}">{!a.Id}</apex:outputLink></apex:column>
<apex:column value="{!a.name}"><apex:facet name="header">Name</apex:facet> </apex:column>
<apex:column value="{!a.accountnumber}"><apex:facet name="header">Account Number</apex:facet> </apex:column>
<apex:column value="{!a.billingstreet}"><apex:facet name="header">Billing Street</apex:facet> </apex:column>
<apex:column value="{!a.billingcity}"><apex:facet name="header">Billing City</apex:facet> </apex:column>
</apex:pageBlockTable>
</apex:outputPanel>
</apex:pageblockSection>
</apex:pageBlock>
</apex:form>
<script>
// On hitting enter, click the submit button
function noenter() {
if (window.event && window.event.keyCode == 13) {
var ele=document.getElementById('{!$Component.form.crit_block.crit.buttons.searchBtn}');
ele.click();
return false;
} else {
return true;
}
}
</script>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment