Skip to content

Instantly share code, notes, and snippets.

@tyoshikawa1106
Last active December 17, 2015 00:11
Show Gist options
  • Save tyoshikawa1106/5519349 to your computer and use it in GitHub Desktop.
Save tyoshikawa1106/5519349 to your computer and use it in GitHub Desktop.
エラー処理の後にポップアップメッセージ
public with sharing class ErrorPopupController {
public Contact contact {get; set;}
public String errorMsg {get; set;}
public ErrorPopupController() {
this.contact = new Contact();
this.errorMsg = 'bat';
}
public PageReference doClick() {
if (String.isEmpty(this.contact.AccountId) == true) {
this.contact.AccountId.addError(this.errorMsg);
return null;
}
return new PageReference('/' + this.contact.AccountId);
}
}
<apex:page controller="ErrorPopupController" title="ErrorPopupPage" showheader="true" sidebar="false" tabStyle="Contact" id="page">
<apex:form id="form">
<apex:pageBlock >
<apex:pageBlockButtons location="bottom">
<apex:commandButton value=" Click!! " title=" Click!! " action="{!doClick}"
onComplete="return errorPopup();" reRender="form" />
</apex:pageBlockButtons>
<apex:pageBlockSection >
<apex:inputField value="{!contact.AccountId}" />
</apex:pageBlockSection>
</apex:pageBlock>
<script>
function errorPopup() {
alert('{!JSENCODE(errorMsg)}');
return false;
}
</script>
</apex:form>
</apex:page>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment