<apex:page standardController="Contact" recordSetVar="Contacts" id="updateOwnerPage"> <apex:form> <apex:sectionheader title="Change Owner for Contacts"/> <apex:pageblock mode="edit"> <apex:pagemessages /> <apex:pageblocksection title="Change" columns="1"> <apex:pageblocksectionitem> <apex:outputlabel for="owner">New Owner</apex:outputlabel> <apex:inputfield id="owner" value="{!Contact.OwnerId}"/> </apex:pageblocksectionitem> </apex:pageblocksection> <apex:pageblocksection title="Selected Contacts" columns="1"> <apex:pageblocktable value="{!selected}" var="j" bgcolor="#F3F3EC" width="100%" styleClass="list" rowClasses="dataRow" onRowMouseOver="hiOn(this);" onRowMouseOut="hiOff(this);"> <apex:column> <apex:facet name="header">Contact Name</apex:facet> <apex:outputlink value="{!URLFOR($Action.Contact.View, j.id)}"> {!j.FirstName} {!j.LastName}</apex:outputlink> </apex:column> <apex:column> <apex:facet name="header">Account Name</apex:facet> <apex:outputlink value="{!URLFOR($Action.Account.View, j.Account.id)}"> {!j.Account.Name}</apex:outputlink> </apex:column> <apex:column> <apex:facet name="header">Current Owner</apex:facet> {!j.Owner.Name} </apex:column> </apex:pageblocktable> </apex:pageblocksection> <apex:pageblockbuttons location="bottom"> <apex:commandbutton value="Save" action="{!save}"/> <apex:commandbutton value="Cancel" action="{!cancel}"/> </apex:pageblockbuttons> </apex:pageblock> </apex:form> </apex:page>Button: Go to Setup -> Contact -> Buttons and Links Create a new button, set it to execute in the current window with sidebar and header, and set it to call a Visualforce page. Select the page you just created. Then add the button to Contact Search Layout and to any Contact related lists you like. Voila!
Project: Change Owner Button in Visualforce
Mass Transfer Opportunity Owner (uses AJAX), Mass Update Contact Addresses (AJAX), Mass Update Opportunity Owner, Mass Update Opportunity Close Dates, etc. All of these are "thick client" tools, meaning that data must be loaded onto your computer, altered, and then uploaded back to Salesforce.
Ron Hess released a super bit of code, found in the Visualforce documentation and elsewhere, to Mass Update Opportunity Stage and Close Date. It could, theoretically, be expanded to other fields as well. This got me thinking about doing so with other objects.
A while ago, I took the code for the Mass Delete button and altered it to change the owner of the selected records to the User clicking the button. It was like an Accept button, but I could use it for any object. Actually, it wasn't as easy as that. I had to make one button for each object, and maintenance was a pain--whenever I created a new object, I needed to clone my code.
Drawing upon some code I found in the Developers Guide, I have written a Visualforce page to mass-change the owner of all selected records to any active User in Salesforce. Yes, it only works with Contacts for now, but my next step will be to use Dynamic Apex to pass the sObject name to the page and its extension/controller, allowing me to reuse one bit of code for multiple objects. We'll see how it goes. But in the meantime, enjoy this page that lets you perform a search, check which records you want to transfer, and then input a User. I've tested it with 50 records at once, so that should suffice for most uses.
VF Page:
Salesforce Labs has put out a series of Mass Action packages on the AppExchange. There is
Depton says
Hi,
I would like to create a change owner button (to shown besides the “edit” or ” delete” buttons) in a custom object
The ownership is based on a look up field:(users)
Assigned to
Can you please provide some tips for it!!
Thank you
David Schach says
Make a button that opens a web page: //a&retURL=
That’s it! Enjoy.
Adam says
This is exactly what I need, but need to modify for the case object. getting a few errors though?!
David Schach says
With no specifics, I can’t help you. Did you just change every “Contact” to “Case?” What are the errors?
athi says
Is it possible to do same thing for all contacts?
I just changed value=”{!selected}” as value=”{!Contacts}” but it doesnt seem working. It is not changing ownership. Also It display only 20 records
David Schach says
This code requires a list such as on a search results page or on a related list. That’s how it populates the Selected list. Just doing Contacts won’t work here.
Julian Olsen says
Hi David,
I had nearly no experience with VF, but was able to copy your “code” and adjust it to do the same with a custom object. Did you get further with the generic version? I would be really interested in the outcome.
Thank you for the great work and especially for sharing!
Julian