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
mnz123mnz123 

ActionFunction to create an account?

I'm trying to create an account using actionFunction and display the result in the same page. I have tried successfully the "sayHello" example in http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_actionFunction.htm . But it's not helping me to build this application. Can anyone guide me through this? Any reference would be helpful. Thanks
PrasanntaPrasannta (Salesforce Developers) 
Hi,

I don't understand what that exactly mean.
Are you asking to create person account?
PrasanntaPrasannta (Salesforce Developers) 
Here is the code to create the person account though VF-

Controller code (partial):

Account acct;
public String salutation {get; set;}
public String fname{get; set;}
public String lname{get; set;}

public PageReference save() {
    try {
        // check for person account record type
        recType = [select id,name,sobjectType,ispersontype from recordType where ispersontype=true and sobjectType='account' limit 1];
        if(acct.recordtypeid == recType.id) {
            acct.Salutation=salutation;
            acct.FirstName=fname;
            acct.LastName=lname;
            insert(acct);                   
            PageReference newPage = New PageReference('/'+acct.id);
            newPage.setRedirect(true);
            return newPage;
        }
        else {
            insert(acct);   
            PageReference newPage = New PageReference('/'+acct.id);
            newPage.setRedirect(true);
            return newPage;
        }
    }
    catch(System.DMLException e) {
            ApexPages.addMessages(e);
             return null;
    } 
    return null;
}

Visualforce code (partial):

<apex:pageblocksectionitem >
    <apex:outputlabel value="First Name"/>
    <apex:outputpanel >
        <apex:inputText value="{!salutation}" id="personSalutation"/>
        <apex:inputText value="{!fname}" id="personFname"/>
     </apex:outputpanel>
</apex:pageblocksectionitem>
<apex:pageBlockSectionItem>
    <apex:outputLabel value="Last Name" for="personLname"></apex:outputLabel>
    <apex:inputText value="{!lname}" id="personLname"/>
</apex:pageBlockSectionItem>

Hope it helps.
mnz123mnz123
I have a form with two fields name and email. Can I create an account with these two fields and show the result without refreshing the current page?
mnz123mnz123
I'm trying to learn the usage of actionFunction.
VikashVikash (Salesforce Developers) 
Hi,

Please refer this link to understand about apex:actionFunction
http://www.salesforceworld.blogspot.co.uk/2011/06/parameter-passing-using.html
http://www.cloudforce4u.com/2013/09/passing-parameters-in-action-function.html

Thanks
Vikash_SFDC