+ Start a Discussion
uHaveOptionsuHaveOptions 

Updating Account info in APEX/VF

So I've been tinkering on this and wondering if you guys can guide me.  All my fields update on but the Account information portion doesn't.  Like the name and number.  The goal is simple update the phone then the account updates.  Any clue?

Here is my VF.

<apex:page controller="AccountFormController" sidebar="false" showHeader="true" id="pg">
         
     <apex:pageBlock mode="maindetail">
       
         <apex:form id="form" styleClass="form-horizontal">
             <div class="panel panel-default">
                <apex:pageBlockSection columns="1">
                <div class="panel-heading"><h4>Company Information</h4> 
             </div>
         </apex:pageBlockSection>


     <apex:pageBlockSection columns="2">
               
         <apex:pageBlockSectionItem HelpText="{!$ObjectType.Account.fields.Name.inlineHelpText}" >
             <apex:outputLabel value="Name" for="{!lender.Name}" style="font-weight:bold;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px;;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px;"/>
             <apex:inputField value="{!lender.Name}" style="width:85%;" />   
         </apex:pageBlockSectionItem>     
                          
         <apex:pageBlockSectionItem HelpText="{!$ObjectType.Account.fields.Phone.inlineHelpText}">
             <apex:outputLabel value="Phone" for="{!lender.Phone}" style="font-weight:bold;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif;     font-size: 14px;"/>
             <apex:inputField value="{!lender.Phone}" style="width:85%;" />      
         </apex:pageBlockSectionItem> 

     
     </apex:pageBlockSection>
     
     </div>

         </apex:pageBlockSection>
                
            <apex:pageBlockSection columns="1">    
                
                    <apex:pageBlockSectionItem HelpText="{!$ObjectType.Account_Update__c.fields.Primary_Focus__c.inlineHelpText}">
                        <apex:outputLabel value="Primary Focus" for="{!accountUpdate.Primary_Focus__c}" style="font-weight:bold;font-family:'Helvetica Neue',Helvetica,Arial,sans-serif; font-size: 14px;"/>
                        <apex:inputField value="{!accountUpdate.Primary_Focus__c}" style="width:100%;"/>   
                    </apex:pageBlockSectionItem>


                </apex:pageBlockSection>

                

                <apex:commandButton value="Update" action="{!save}" styleClass="btn pull-right" />

            </apex:form>


        
        <div class="modal fade" id="pleaseWaitDialog" data-backdrop="static" data-keyboard="false">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-body">
                        <h3>Processing...</h3><br/>
                        <div class="progress">
                            <div class="progress-bar progress-bar-striped active" role="progressbar"
                            aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:100%">
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!--
        <div>{!Options}</div>-->
    </apex:pageBlock>

    </body>
                           <!-- </apex:pageBlock>-->
</div>
</apex:page>



Here is my APEX

 

public class AccountFormController {
    
    public Account lender {get; set;}
    public Account_Update__c accountUpdate {get; set;}
    
    private String accountId;
    
    public AccountFormController() {
        accountId = ApexPages.currentPage().getParameters().get('id');
        
        if(String.isBlank(accountId)) {
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Could not find account id in the parameter.'));
            return;
        }
        
        accountUpdate = new Account_Update__c();
        getAccount();
    }

    public PageReference save() {   //***************************NOTE: Save Code works.  it's just too long************************  

   }
}       

************ This is where I'm lost******************

private void getAccount() {
        try {
            lender = [
                select
                    Id,
                    Name,
                    Phone,
                    Primary_Focus__c,

                from Account
                where Id = :accountId
            ];
        
            if(lender == null) {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Could not find the account with the given id.'));
                return;
            }
            
             accountUpdate.Phone__c = lender.Phone;
             accountUpdate.Primary_Focus__c = lender.Primary_Focus__c;

            
            
            
        } catch(Exception e) {
            System.debug('------------- ERROR: ' + e.getStackTraceString());
            ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'There was a problem while getting the account information.' + e.getStackTraceString()));
            return;
        }
    }

The update should update the ACcount object. Also tried using Phone__c but says field doesn't exist.  If I update the Primary focus it updates just fine.  Thanks in advance
Best Answer chosen by uHaveOptions
uHaveOptionsuHaveOptions
UPDATE:  You cant update account using external sites.  Salesforce license limitation.

All Answers

SandhyaSandhya (Salesforce Developers) 
Hi,

Refer below sample code
public without sharing class AccountController {
	public Account account{get; set;}
	public AccountController(){
		account = new Account();
	}
	
	public void save(){
		upsert account;
	}
}
 
<apex:page controller="AccountController">
    <apex:form>
        <apex:pageBlock title="My Content" mode="edit">
            <apex:pageBlockButtons>
                <apex:commandButton action="{!save}" value="Save"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="My Content Section" columns="2">
                <apex:inputField value="{!account.name}"/>
                <apex:inputField value="{!account.site}"/>
                <apex:inputField value="{!account.type}"/>
                <apex:inputField value="{!account.accountNumber}"/>
            </apex:pageBlockSection>
        </apex:pageBlock>
    </apex:form>
</apex:page>

If this helps you, please mark it as solved so that it will be available for others as a solution.

Best Regards,
Sandhya 
uHaveOptionsuHaveOptions
UPDATE:  You cant update account using external sites.  Salesforce license limitation.
This was selected as the best answer