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
Sean TisdaleSean Tisdale 

JavaScript Button to Update Record Owner

 have a custom object called "SupportRequest" with a record type used by our sales and contracts team. I need to have a manual trigger (in this case a detail page button) that allows the creator of the record to update the record owner to a queue with a single click.

I am using this JS for the button:
{!REQUIRESCRIPT("/soap/ajax/35.0/connection.js")} try{ var CCA_QueueId; var CCA_QueueName = "CCA_Queue"; var queues = sforce.connection.query( "SELECT Id " + "FROM Group " + "WHERE Name = '" + CCA_QueueName + "'" ); if( queues.getArray( "records" ).length === 0 ) { alert( "Couldn't find a Queue with Name: " + CCA_QueueName + "!" ); } else { CCA_QueueId = queues.getArray( "records" )[0].Id; } if( CCA_QueueId !== undefined ) { var reqToUpdate = new sforce.SObject( "SupportRequest__c" ); reqToUpdate.Id = "{!SupportRequest__c.Id}"; reqToUpdate.OwnerId = CCA_QueueId; var result = sforce.connection.update( [reqToUpdate] ); if( result[0].getBoolean( "success" ) === true ) { location.reload(); } else { alert( "An Error has Occurred. Error: " + result[0].errors.message ); } } } catch( e ) { alert( "An Error has Occurred. Error: " + e.message ); }

This is code modified from other used and not my original work. I'm sure I'm missing somethign elementary but this falls outside of my skillset.  
Another note - the Queue API name is CCA_Queue but the Label is Contracts Queue if that makes any difference.

Thanks 
Matt SmelserMatt Smelser
Sean-
This can be handled using flow. That way your solution is ready for Lightning Experience.
Sean TisdaleSean Tisdale
Unfortunately, for our current business process the trigger to updated the record owner to the queue needs to be manual and not automatically triggered.  I would love to automate this process and it's part of a future plan but for now the requirment is a manual button click.
Matt SmelserMatt Smelser
Sean-
You can call a flow from a button. Just create an URL button and call the url for the flow you create. Example of the url would be "/flow/FLOWNAME"