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>