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
Sakthi169Sakthi169 

How to set the default owner name after save the account page using vf

Hi 
i am new to salesforce i create the page using visualforce.

<apex:page standardcontroller="Account" tabstyle="Account">
 
 <apex:form >
 
 <apex:sectionheader title="Account Details" subtitle="{!if(Account.Id==null,'New Account',Account.Name)}"></apex:sectionheader>
<apex:pageblock mode="edit" id="leadPB" title="Account Edit">
 
 <apex:pageblockbuttons >
 <apex:commandbutton action="{!save}" value="Save"></apex:commandbutton>
 <!-- If you wish to implement Save & New functionality you will have to write an Apex Extension with your own Save & New Method -->
 <apex:commandbutton action="{!cancel}" value="Cancel"></apex:commandbutton>
 </apex:pageblockbuttons>
 
        <apex:pageBlockSection >
     
        
            <apex:inputtext value="{!Account.LastName}" label="Customer Name"/>
            <apex:inputtext value="{!Account.PersonMobilePhone}"/>
            <apex:inputtext value="{!Account.CustomLandLine__c}"/>
            <apex:inputField value="{!Account.City__c}"/>
            <apex:inputField value="{!Account.PersonEmail}"/>
             <apex:inputField value="{!Account.Source__c}"/>
             <!-- <apex:commandButton action="{!save}" value="Save!"/>-->
        </apex:pageBlockSection>
    </apex:pageBlock>
<apex:pageMessages />
</apex:form>

after save the page i need update the account owner name is "Umadevi". how to do it??? If any way is there
 
Best Answer chosen by Sakthi169
Sakthi169Sakthi169
Hi Jyothsha,
<apex:page standardcontroller="Account" tabstyle="Account" extensions="MyExtension" >
 
 <apex:form >
 
 <apex:sectionheader title="Account Details" subtitle="{!if(Account.Id==null,'New Account',Account.Name)}"></apex:sectionheader>
<apex:pageblock mode="edit" id="leadPB" title="Account Edit">
 
 <apex:pageblockbuttons >
<apex:commandbutton action="{!save}" value="Save"></apex:commandbutton>
 <!-- If you wish to implement Save & New functionality you will have to write an Apex Extension with your own Save & New Method -->
 <apex:commandbutton action="{!cancel}" value="Cancel"></apex:commandbutton>
 </apex:pageblockbuttons>
 
        <apex:pageBlockSection >
     
        
            <apex:inputtext value="{!Account.LastName}" label="Customer Name"/>
            <apex:inputtext value="{!Account.PersonMobilePhone}"/>
            <apex:inputtext value="{!Account.CustomLandLine__c}"/>
            <apex:inputField value="{!Account.City__c}"/>
            <apex:inputField value="{!Account.PersonEmail}"/>
             <apex:inputField value="{!Account.Source__c}"/>
            
            <!-- <apex:commandButton action="{!save}" value="Save!"/>-->
        </apex:pageBlockSection>
    </apex:pageBlock>
<apex:pageMessages />
</apex:form>



</apex:page>

ApexClass
public with sharing class MyExtension {
    private ApexPages.StandardController sc;
    public MyExtension(ApexPages.StandardController sc) {
        this.sc = sc;
    }
    public PageReference save() {
        Account a = (Account) sc.getRecord();
        a.OwnerId = [select Id from User where LastName = 'Kapoor'].Id;
        return sc.save();
    }
}

It was working fine

All Answers

JyothsnaJyothsna (Salesforce Developers) 
Hi Umadevi,

Please check the below code.
<apex:outputField value="{!Account.Ownerid}"/>
Hope this helps you!
Best Regards,
Jyothsna
 
Sakthi169Sakthi169
Hi Jyothsha,
<apex:page standardcontroller="Account" tabstyle="Account" extensions="MyExtension" >
 
 <apex:form >
 
 <apex:sectionheader title="Account Details" subtitle="{!if(Account.Id==null,'New Account',Account.Name)}"></apex:sectionheader>
<apex:pageblock mode="edit" id="leadPB" title="Account Edit">
 
 <apex:pageblockbuttons >
<apex:commandbutton action="{!save}" value="Save"></apex:commandbutton>
 <!-- If you wish to implement Save & New functionality you will have to write an Apex Extension with your own Save & New Method -->
 <apex:commandbutton action="{!cancel}" value="Cancel"></apex:commandbutton>
 </apex:pageblockbuttons>
 
        <apex:pageBlockSection >
     
        
            <apex:inputtext value="{!Account.LastName}" label="Customer Name"/>
            <apex:inputtext value="{!Account.PersonMobilePhone}"/>
            <apex:inputtext value="{!Account.CustomLandLine__c}"/>
            <apex:inputField value="{!Account.City__c}"/>
            <apex:inputField value="{!Account.PersonEmail}"/>
             <apex:inputField value="{!Account.Source__c}"/>
            
            <!-- <apex:commandButton action="{!save}" value="Save!"/>-->
        </apex:pageBlockSection>
    </apex:pageBlock>
<apex:pageMessages />
</apex:form>



</apex:page>

ApexClass
public with sharing class MyExtension {
    private ApexPages.StandardController sc;
    public MyExtension(ApexPages.StandardController sc) {
        this.sc = sc;
    }
    public PageReference save() {
        Account a = (Account) sc.getRecord();
        a.OwnerId = [select Id from User where LastName = 'Kapoor'].Id;
        return sc.save();
    }
}

It was working fine
This was selected as the best answer