You need to sign in to do that
Don't have an account?
AichaSF
visualforce alert message
Hello everyone,
I have commandButton in my visualforce page that retrieves the id in a search box, searches for an object, and modifies the object founded.
I need to display an error message if the id does not exist or the object is already updated?
Any Help please.
I have commandButton in my visualforce page that retrieves the id in a search box, searches for an object, and modifies the object founded.
I need to display an error message if the id does not exist or the object is already updated?
Any Help please.
When you are assigning value of the id, modify the block with null checks and include Apex Message if found null
Cas you give me exemple please.
You can try this like:
COntroller:
public with sharing class add
{
public String res{get;set;}
public PageReference doAdd() {
<Object Name> obj = [Select Id, Name From <Object Name> Where Id =: res];
if(obj == null)
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL, 'Record not found.'));
return null;
}
}
/*****************/
Page:
<apex:page controller="AddController" id="thePage">
<apex:form id="theForm" >
<apex:pageMessages id="someMessages" />
<apex:pageBlock id="theBlock" >
<apex:inputText id="test" value=""/>
<input type="button" value="Click" onclick="doAd()"/> <!-- Your button here or YOu can try below line-->
<!-- <apex:commandButton value="Click" onClick="doAd()" />-->
</apex:pageBlock>
<apex:outputPanel id="out">
<apex:outputText value="{!res}"/>
</apex:outputPanel>
<apex:actionFunction name="doAdd" action="{!doAdd}" reRender="out" >
<apex:param name="firstParam" assignTo="{!res}" value="" />
</apex:actionFunction>
</apex:form>
<script type="text/javascript">
function doAd(){
var recId = document.getElementById('thePage:theForm:theBlock:test').value ;
if(recId) {
doAdd(recId);
}
else {
alert('Plz! provide value for this field');
}
}
</script>
</apex:page>
/****************************************/
Might be it will help you !!
Thanks
Niraj