Skip to main content
added 443 characters in body
Source Link

##UPDATE:## Thank you @AdrianLarson very helpful answer/post.

To summarize: On my VF page I needed to get the {!Account.OwnerId} Inputfield variable into my apex controller extension. @AdrianLarson pointed out the the line to do this would be This snippets of code:

     final Account template;
     template = (Account)controller.getRecord();//<--same record as{!Account.OwnerId}
     Id ownerId = template.OwnerId; 

##UPDATE:## Thank you @AdrianLarson very helpful answer/post.

To summarize: On my VF page I needed to get the {!Account.OwnerId} Inputfield variable into my apex controller extension. @AdrianLarson pointed out the the line to do this would be This snippets of code:

     final Account template;
     template = (Account)controller.getRecord();//<--same record as{!Account.OwnerId}
     Id ownerId = template.OwnerId; 
added 64 characters in body; edited tags
Source Link
Adrian Larson
  • 151.3k
  • 38
  • 247
  • 431
    <apex:page standardController="Account" recordSetVar="accounts" extensions="quickEmail">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection >
                <!--I Want to use this value in the extension-->
                <apex:inputField value="{!Account.OwnerId}" />
            </apex:pageBlockSection>

            <apex:pageBlockTable value="{!selected}" var="account">
                <apex:column value="{!account.name}"/>
            </apex:pageBlockTable>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Do Something" action="{!doSomething}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>

</apex:page>

    <apex:page standardController="Account" recordSetVar="accounts" extensions="quickEmail">
<apex:form>
    <apex:pageBlock>
        <apex:pageBlockSection >
            <!--I Want to use this value in the extension-->
            <apex:inputField value="{!Account.OwnerId}" />
        </apex:pageBlockSection>

        <apex:pageBlockTable value="{!selected}" var="account">
            <apex:column value="{!account.name}"/>
        </apex:pageBlockTable>
        <apex:pageBlockButtons location="bottom">
            <apex:commandButton value="Do Something" action="{!doSomething}"/>
            <apex:commandButton value="Cancel" action="{!cancel}"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
</apex:form>

</apex:page>

<apex:page standardController="Account" recordSetVar="accounts" extensions="quickEmail">
    <apex:form>
        <apex:pageBlock>
            <apex:pageBlockSection >
                <!--I Want to use this value in the extension-->
                <apex:inputField value="{!Account.OwnerId}" />
            </apex:pageBlockSection>

            <apex:pageBlockTable value="{!selected}" var="account">
                <apex:column value="{!account.name}"/>
            </apex:pageBlockTable>
            <apex:pageBlockButtons location="bottom">
                <apex:commandButton value="Do Something" action="{!doSomething}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Source Link

Pass InputField into Controller Extension, mass edit of Owner

Trying to make an Accounts List View with a button. Selected accounts go to my visual force page, where the user selects to Account Owner (via search field) they want those records/accounts to be changed to.

In short I'm trying to get the value from Account Owner field and pass it to the extension where I am attempting to override the save function from the standardsetcontroller to save both the accounts and contacts OwnerId.

Apex:

    public with sharing class quickEmail {

    ApexPages.StandardSetController setCon;

    public sObject ownThing {get;set;}


    public quickEmail(ApexPages.StandardSetController ctrl) {
    setCon = ctrl;

    }

    public PageReference doSomething() {
    //do something with the selected records

    /*Test - get contact id as well*/
    List<Contact> selectedContacts = new List<Contact>();
    List<Account> selectedAccounts = new List<Account>();
    /*******************************/

    for (Account acc : (Account[])setCon.getSelected() ) {
     System.debug('Account name = ' + acc.Name);
     System.debug('Here is Account: ' + acc);

     List<Account> alist = [SELECT Id, Name FROM Account WHERE Id = :acc.Id];
     System.debug('a' + alist);

     List<Contact> clist = [SELECT Id, Name FROM Contact WHERE Contact.AccountId IN :alist];
     System.debug('c' + clist);

     for(Contact c : clist) {
     c.OwnerId = Account.OwnerId; //*****Error Here*****
    selectedContacts.add(c);
    }
    System.debug('Here is selectedContacts: ' + selectedContacts);
    /****/
    }


    /*Test - get contact id as well*/
    ApexPages.StandardSetController myContacts = new ApexPages.StandardSetController(selectedContacts);
    myContacts.save();
    ApexPages.StandardSetController myAccounts = new ApexPages.StandardSetController(selectedAccounts);
    myAccounts.save();
    /*******************************/

    return null;
    }
    }

Here is VisualForce Page:

    <apex:page standardController="Account" recordSetVar="accounts" extensions="quickEmail">
<apex:form>
    <apex:pageBlock>
        <apex:pageBlockSection >
            <!--I Want to use this value in the extension-->
            <apex:inputField value="{!Account.OwnerId}" />
        </apex:pageBlockSection>

        <apex:pageBlockTable value="{!selected}" var="account">
            <apex:column value="{!account.name}"/>
        </apex:pageBlockTable>
        <apex:pageBlockButtons location="bottom">
            <apex:commandButton value="Do Something" action="{!doSomething}"/>
            <apex:commandButton value="Cancel" action="{!cancel}"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>
</apex:form>

</apex:page>