I want show a alert message when list size is greater than zero. I received like this error.
This is my controller:
public class OpportunityVFPageExtension {
public Opportunity getOpportunity {get;set;}
public List<Opportunity> oldOpportunity {get;set;}
public OpportunityVFPageExtension(ApexPages.StandardController sc){
getOpportunity = (Opportunity)sc.getRecord();
}
Public Void Save(){
oldOpportunity = [SELECT Id,Name FROM Opportunity WHERE Name =: getOpportunity.Name];
insert getOpportunity;
}
}
This is my VF page:
<apex:page standardController="Opportunity" extensions="OpportunityVFPageExtension">
<apex:sectionHeader title="New Opportunity"/>
<script>
function validateName(){
if('{oldOpportunity.size}' > 0){
alert('This is duplicate record. Do you want to submit?');
}
}
</script>
<apex:form >
<!-- <apex:actionFunction name="callSave" action="{!Save}"/>-->
<apex:pageBlock title="Opportunity Edit" >
<apex:pageBlockButtons >
<apex:commandButton value="Save" action="{!Save}" onclick="validateName();" />
<apex:commandButton value="Cancel" action="{!Cancel}" />
</apex:pageBlockButtons>
<apex:pageBlockSection title="Opportunity Information" columns="1" collapsible="true" >
<apex:inputField value="{!Opportunity.Name}" />
<apex:inputField value="{!Opportunity.CloseDate}" />
<apex:inputField value="{!Opportunity.StageName}" />
<apex:inputField value="{!Opportunity.Last_Name__c}" />
<apex:inputField value="{!Opportunity.Email__c}" />
<apex:inputField value="{!Opportunity.Phone__c}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
Thanks in advance.
update
operation on it but notinsert
. You should explain what you want to do in the save method? – abdn Aug 28 '16 at 11:54confirm message box
and if user select yes then in your controller insert the record. – Tushar Sharma Aug 28 '16 at 12:56insert oldOpportunity
line from class and, in the VF page, call the JS function on load like this:window.onload= validateName()
– abdn Aug 28 '16 at 13:08