I have created a vf page with Contact standard controller to create a Contact record.
User will create record in vf page and should be redirected to the related Contact detail page created. Here is the vf page sample code:
<apex:page standardController="Contact" extensions="onboardform">
<apex:form id="form">
<apex:outputPanel id="EntryForm">
<table>
<tr>
<td>
<b>First Name:</b>
<apex:inputField value="{!con.FirstName}" style="width:225px;" />
</td>
</tr>
<tr>
<td>
<b>Last Name:</b>
<apex:inputText value="{!con.LastName}" style="width:225px;" required="true" />
</td>
</tr>
<tr>
<td>
<apex:commandButton value="Submit" action="{!submit}" />
</td>
</tr>
</table>
</div>
</div>
</apex:outputPanel>
</apex:form>
</apex:page>
Controller Code:
public class onboardform {
public Contact con {get;set;}
String conId;
String stdcon;
public onboardform(ApexPages.StandardController stdcon) {
conId = ApexPages.CurrentPage().getParameters().get('Id');
if (conId != null && conId != '') // if id is in url means record is for edit
con = (Contact) stdcon.getRecord();
else // else you r gonna create new record
con = new Contact();
}
public PageReference submit() {
if (conId != null && conId != '')
update con;
else {
Contact newContact = new Contact();
newContact.FirstName = con.FirstName;
newContact.LastName = con.LastName;
newContact.HUB_ID__c = con.HUB_ID__c;
newContact.Approver_Requestor__c = con.Approver_Requestor__c;
insert newContact;
conId = ApexPages.CurrentPage().getParameters().get('Id');
PageReference requestPage = new pagereference(+newContact.id);
return requestPage;
}
return null;
}
}
When I am entering the details in the vf page , the contact is getting created but not redirected to the related contact detail standard salesforce page and getting error msg
Formula Expression is required on the action attributes
Any suggestions where I am going wrong?