function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Pooja NekkalapudiPooja Nekkalapudi 

Create a Person Account using a button that opens a VF page from a custom object

My class 
public class CrossSellRExtensionController {
     public Account ca {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];
           
           ca = new Account();
          
           ca.Cross_Sell_Referral__c = csr.Id;
           
          }
           
public PageReference save() {
       insert ca;
        PageReference pageRef = new PageReference('/' + ca.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('/'+ ca.Cross_Sell_Referral__c);
}
}



And my 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="{!ca.RecordTypeId}" required="true"/><br/>
        <apex:inputField value="{!Cross_Sell_Opportunity__c.Name}" required="true"/><br/>
        <apex:inputField value="{!ca.Salutation}" /> &nbsp;
            <apex:inputField value="{!ca.FirstName}"  /><br/>
            <apex:inputField value="{!ca.LastName}"  required="true"/><br/>
             <apex:inputField value="{!ca.Name}" required="true"/><br/>
             <apex:inputField value="{!ca.PersonEmail}" required="true"/><br/>
              <apex:inputField value="{!ca.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>  

I am having trouble to create a person account and the VF page first name and last name are not editable they dont give a box to type in values , what can be done and also before I create a new Person Account , is there a way I coyld do a vlookup on the contact ( if firstname , lastName and email Id given thru VF page already exists ) and throw error saying contact already exists 
PrabhaPrabha
  1. Try creating an <apex:inputText> tag instead of input field. 
  2. vlookup are formula based function, u can't use them here in code. u have to do a SOQL with these conditions and find out if it whether they exist or not in the DB. Based on result u can throw the error msg.
HTH
Prabhanjan