On click of save button a new record as to be created with the values inputted by user and it should be able to redirect user to company detail page. Add error messages on page if user clicks on this button leaving any field blank.I have created VF page as shown below.but even after entering the value for blank field I am getting the error message instead of redirecting to detail page.pls someone help me to solve this task.
apex Page:
<apex:page standardController="Company__c" extensions="errorMsg">
<apex:form >
<apex:pageBlock >
<apex:pageBlockSection title="Company Record" collapsible="false" columns="1">
<apex:inputField value="{!Company__c.Name}"/>
<apex:pageMessages id="showMsg"></apex:pageMessages>
<apex:inputField value="{!Company__c.company_Owner_Name__c}"/>
<apex:pageBlockSection title="Address" collapsible="false" columns="1">
<apex:inputField value="{!Company__c.Country__c}"/>
<apex:inputField value="{!Company__c.State__c}"/>
<apex:inputField value="{!Company__c.Zip_Code__c}"/>
<apex:commandButton value="Save" action="{!save}">
<apex:commandButton value="Cancel" action="{!cancel}" >
</apex:commandButton>
</apex:commandButton>
</apex:pageBlockSection>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
extension:
public with sharing class errorMsg {
public Company__c comp{get; set;}
public errorMsg(ApexPages.StandardController controller) {
comp=new Company__c();
}
public PageReference save(){
if(comp.Name == null){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Please enter Company Name');
ApexPages.addMessage(myMsg);
return null;
}
// otherwise save as usual
insert comp;
return null;
}
}