0

I want to save the fields BillingAddress, ShippingAddress and a custom field "FiscalAddress"

I understand that the API only have BillingAddress and ShippingAddress and I need one more.

I want insert in database (SOQL) but the logic of my script is wrong.

What corrections you should do to insert the input text fields in the Account table?

error console:

<apex:inputField> value binding '{!a.BillingStreet}'. <apex:inputField> can only be used with SObjects, or objects that are Visualforce field component resolvable.

Markup

<apex:page Controller="CustomAccount" >
    <apex:form >

        <apex:pageBlock title="Edit Contact">

            <apex:pageBlockSection columns="1">
                <apex:inputField value="{!a.BillingStreet}"/>
                <apex:inputField value="{!a.BillingCity}"/>
                <apex:inputField value="{!a.BillingState}"/>
                <apex:inputField value="{!a.BillingPostalCode}"/>

                <apex:inputField value="{!a.ShippingStreet}"/>
                <apex:inputField value="{!a.ShippingCity}"/>
                <apex:inputField value="{!a.ShippingState}"/>
                <apex:inputField value="{!a.ShippingPostalCode}"/>


                <apex:inputField value="{!a.FiscalStreet}"/>
                <apex:inputField value="{!a.FiscalCity}"/>
                <apex:inputField value="{!a.FiscalState}"/>
                <apex:inputField value="{!a.FiscalPostalCode}"/>

            </apex:pageBlockSection>
            <apex:pageBlockButtons >
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>

        </apex:pageBlock>

    </apex:form>
</apex:page>

Code

public with sharing class CustomAccount {
    public Account a { get; set; }

    public List<Account> samepage { get; set; }

    public CustomAccount(){
       a = new Account();
    }

    public PageReference save() {
       insert a;  

    }


}

Fiscal Address (custom fields)

Markup new version

<apex:page standardController="Account">
  <apex:form>
    <apex:pageBlock>
      <apex:pageBlockSection>
        <apex:inputField value="{!Account.BillingStreet}" />
        <apex:inputField value="{!Account.BillingCity}" />
        <apex:inputField value="{!Account.BillingState}" />
        <apex:inputField value="{!Account.BillingPostalCode}" />

        <apex:inputField value="{!Account.ShippingStreet}"/>
        <apex:inputField value="{!Account.ShippingCity}"/>
        <apex:inputField value="{!Account.ShippingState}"/>
        <apex:inputField value="{!Account.ShippingPostalCode}"/>


        <apex:inputField value="{!Account.FiscalStreet__c}" />
        <apex:inputField value="{!Account.FiscalCity__c}"/>
        <apex:inputField value="{!Account.FiscalState__c}"/>
        <apex:inputField value="{!Account.FiscalPostalCode__c}"/>

      </apex:pageBlockSection>
      <apex:pageBlockButtons>
        <apex:commandButton action="{!save}" value="Save" />
      </apex:pageBlockButtons>
    </apex:pageBlock>
  </apex:form>
</apex:page>
0

You'll need to create the fields in Setup first (Setup > Customize > Accounts > Fields or Setup > Object Manager > Account > Fields & Relationships). Once you do so, you can write your page using the StandardController:

<apex:page standardController="Account">
  <apex:form>
    <apex:pageBlock>
      <apex:pageBlockSection>
        <apex:inputField value="{!Account.BillingStreet}" />
        ... other fields ...
        <apex:inputField value="{!Account.FiscalStreet__c}" />
        ... other fields ...
      </apex:pageBlockSection>
      <apex:pageBlockButtons>
        <apex:commandButton action="{!save}" value="Save" />
      </apex:pageBlockButtons>
    </apex:pageBlock>
  </apex:form>
</apex:page>

Note that Custom Fields that you create end in __c (as demonstrated in the code). You'll want to also read about Display Field Values with Visualforce.

  • thank you so much but my class "CustomAccount" it's correct? for query insert – user65550 Mar 11 at 2:06
  • @Apu There's no such thing as a "query insert" in Salesforce. DML operations and Query statements are two entirely separate concepts. As I stated, you must first create any custom fields you need, then you can reference them in your Visualforce code. In addition, if you're getting an error for a standard field, it is likely that you have another class that is overriding the standard Account object, which won't work. Start from my example to see what I'm talking about. – sfdcfox Mar 11 at 2:13
  • Hi, I added the new version of the apex page. the page is displayed correctly but does not save the data in the database. the logic of my class CustomAccount – user65550 Mar 11 at 7:21
  • @Apu What error messages are you getting, if any? Try adding <apex:pageMessages/> somewhere in your VF page to see if you get any errors. – sfdcfox Mar 11 at 9:51
  • I had to add Account.name. thanks for the advice of the label <apex:pageMessages/> – user65550 Mar 11 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy