Try below VF page
<apex:page standardcontroller="Cross_Sell_Opportunity__c" extensions="CrossSellRExtensionController">
<apex:sectionHeader title="Title" subtitle="Person Accounts"/>
<apex:form >
<apex:outputPanel >
</apex:outputPanel>
<apex:pageMessages />
<apex:pageBlock title="Please fill in the details for creating *Contacts*">
<apex:pageBlockSection >
<apex:inputField value="{!Cross_Sell_Opportunity__c.Name}" required="true"/><br/>
<apex:inputField value="{!newPersonAccount.Salutation}" />
<apex:inputField value="{!newPersonAccount.FirstName}" /><br/>
<apex:inputField value="{!newPersonAccount.LastName}" required="true"/><br/>
<apex:inputField value="{!newPersonAccount.PersonEmail}" required="true"/><br/>
<apex:inputField value="{!newPersonAccount.Status__c}" /><br/>
</apex:pageBlockSection>
<apex:pageBlockButtons >
<apex:commandButton action="{!save}" value="Save" />
<apex:commandButton action="{!cancel}" value="Cancel"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Below controller class
public class CrossSellRExtensionController {
public Account newPersonAccount {get; set;}
public CrossSellRExtensionController(ApexPages.StandardController controller)
{
Cross_Sell_Opportunity__c csr = (Cross_Sell_Opportunity__c) controller.getRecord();
csr = [Select Id, Name from Cross_Sell_Opportunity__c where Id =: csr.Id];
RecordType personAccountRecordType = [SELECT Id FROM RecordType WHERE Name = 'Person Account' and SObjectType = 'Account'];
newPersonAccount = new Account();
newPersonAccount.Cross_Sell_Referral__c = csr.Id;
newPersonAccount.recordtypeId = personAccountRecordType.id ;
}
public PageReference save()
{
insert newPersonAccount; //this is line 17
PageReference pageRef = new PageReference('/' + newPersonAccount.Cross_Sell_Referral__c);
pageRef.setRedirect(true);
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'new *contact* created.'));
return pageRef;
}
public PageReference cancel()
{
return new PageReference('/'+ newPersonAccount.Cross_Sell_Referral__c);
}
}
Let us know if this will help you
9 respostas