Skip to content

Instantly share code, notes, and snippets.

@jvolkov
Last active July 10, 2017 23:06
Show Gist options
  • Save jvolkov/528eb1404c1e2a2d1e22776fb921ef4e to your computer and use it in GitHub Desktop.
Save jvolkov/528eb1404c1e2a2d1e22776fb921ef4e to your computer and use it in GitHub Desktop.
Transfer data from one username to another inside Salesforce
#!/bin/bash
# get users old user id
echo -e "enter the user id for the old username: "
read user_id
# get users new user id
echo -e "enter the user id for the new username: "
read new_user_id
say "thanks! just a second, let me get all those records"
# query the rep’s email templates to a csv
echo " number of email templates to be transferred for \"$user_id\": "
¬ "select count() from EmailTemplate where folderid = '$user_id' "
USERTEMPLATES="$( /applications/force bulk query EmailTemplate "select id, folderid from EmailTemplate where folderid = '$user_id' " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s qualifying and qualified leads to a csv
echo " number of leads to be transferred for \"$user_id\": "
/applications/force query "select count() from lead where isconverted = false and ownerid = '$user_id' and (status='qualifying' or status='qualified')"
USERLEADS="$( /applications/force bulk query lead "select id, ownerid from lead where isconverted = false and ownerid = '$user_id' and (status='qualifying' or status='qualified') " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s accounts to a csv
echo " number of accounts to be transferred for \"$user_id\": "
/applications/force query "select count() from account where ownerid = '$user_id' "
USERACCTS="$( /applications/force bulk query account "select id, ownerid from account where ownerid = '$user_id' " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s contacts to a csv
echo " number of contacts to be transferred for \"$user_id\": "
/applications/force query "select count() from contact where ownerid = '$user_id' "
USERCONS="$( /applications/force bulk query contact "select id, ownerid from contact where ownerid = '$user_id' " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s won opportunities for this month to a csv
echo " number of won opportunities to be transferred for \"$user_id\": "
/applications/force query "select count() from opportunity where ownerid = '$user_id' and isclosed = true and closedate = this_month "
USERWON="$( /applications/force bulk query opportunity "select id, ownerid from opportunity where ownerid = '$user_id' and isclosed = true and closedate = this_month " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s open opportunities to a csv
echo " number of open opportunities to be transferred for \"$user_id\": "
/applications/force query "select count() from opportunity where isclosed = false and stagename != 'Closed Lost' and ownerid = '$user_id' "
USEROPPS="$( /applications/force bulk query opportunity "select id, ownerid from opportunity where ownerid = '$user_id' and isclosed = false and stagename != 'Closed Lost' " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s open tasks to a csv
echo " number of open tasks to be transferred for \"$user_id\": "
/applications/force query "select count() from task where ownerid = '$user_id' and isclosed = false "
USERTASKS="$( /applications/force bulk query task "select id, ownerid from task where ownerid = '$user_id' and isclosed = false " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s upcoming events to a csv
echo " number of upcoming events to be transferred for \"$user_id\": "
/applications/force query "select count() from event where ownerid = '$user_id' and startDateTime >= today "
USEREVENTS="$( /applications/force bulk query event "select id, ownerid from event where ownerid = '$user_id' and startDateTime >= today " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s leads
/applications/$USERLEADS > desktop/leads_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/leads_to_transfer.csv
# update the leads
/applications/force bulk update lead desktop/leads_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s accounts
/applications/$USERACCTS > desktop/accounts_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/accounts_to_transfer.csv
# update the accounts
/applications/force bulk update account desktop/accounts_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s contacts
/applications/$USERCONS > desktop/contacts_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/contacts_to_transfer.csv
# update the contacts
/applications/force bulk update contact desktop/contacts_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s won opportunities
/applications/$USERWON > desktop/won_opps_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/won_opps_to_transfer.csv
# update the won opportunities
/applications/force bulk update opportunity desktop/won_opps_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s open tasks
/applications/$USERTASKS > desktop/open_tasks_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/open_tasks_to_transfer.csv
# update the open tasks
/applications/force bulk update task desktop/open_tasks_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s upcoming events
/applications/$USEREVENTS > desktop/upcoming_events_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/upcoming_events_to_transfer.csv
# update the upcoming events
/applications/force bulk update event desktop/upcoming_events_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s open opportunities
/applications/$USEROPPS > desktop/open_opps_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/open_opps_to_transfer.csv
# update the open opportunities
/applications/force bulk update opportunity desktop/open_opps_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s email templates
/applications/$USERTEMPLATES > desktop/email_templates_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/email_templates_to_transfer.csv
# update the upcoming events
/applications/force bulk update emailtemplate desktop/email_templates_to_transfer.csv
#!/bin/bash
# get users old user id
echo -e "enter the user id for the old username: "
read user_id
# get users new user id
echo -e "enter the user id for the new username: "
read new_user_id
say "thanks! just a second, let me get all those records"
# query the rep’s email templates to a csv
echo " number of email templates to be transferred for \"$user_id\": "
¬ "select count() from EmailTemplate where folderid = '$user_id' "
USERTEMPLATES="$( /applications/force bulk query EmailTemplate "select id, folderid from EmailTemplate where folderid = '$user_id' " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s qualifying and qualified leads to a csv
echo " number of leads to be transferred for \"$user_id\": "
/applications/force query "select count() from lead where isconverted = false and ownerid = '$user_id' and (status='qualifying' or status='qualified')"
USERLEADS="$( /applications/force bulk query lead "select id, ownerid from lead where isconverted = false and ownerid = '$user_id' and (status='qualifying' or status='qualified') " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s accounts to a csv
echo " number of accounts to be transferred for \"$user_id\": "
/applications/force query "select count() from account where ownerid = '$user_id' "
USERACCTS="$( /applications/force bulk query account "select id, ownerid from account where ownerid = '$user_id' " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s contacts to a csv
echo " number of contacts to be transferred for \"$user_id\": "
/applications/force query "select count() from contact where ownerid = '$user_id' "
USERCONS="$( /applications/force bulk query contact "select id, ownerid from contact where ownerid = '$user_id' " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s won opportunities for this month to a csv
echo " number of won opportunities to be transferred for \"$user_id\": "
/applications/force query "select count() from opportunity where ownerid = '$user_id' and isclosed = true and closedate = this_month "
USERWON="$( /applications/force bulk query opportunity "select id, ownerid from opportunity where ownerid = '$user_id' and isclosed = true and closedate = this_month " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s open opportunities to a csv
echo " number of open opportunities to be transferred for \"$user_id\": "
/applications/force query "select count() from opportunity where isclosed = false and stagename != 'Closed Lost' and ownerid = '$user_id' "
USEROPPS="$( /applications/force bulk query opportunity "select id, ownerid from opportunity where ownerid = '$user_id' and isclosed = false and stagename != 'Closed Lost' " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s open tasks to a csv
echo " number of open tasks to be transferred for \"$user_id\": "
/applications/force query "select count() from task where ownerid = '$user_id' and isclosed = false "
USERTASKS="$( /applications/force bulk query task "select id, ownerid from task where ownerid = '$user_id' and isclosed = false " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s upcoming events to a csv
echo " number of upcoming events to be transferred for \"$user_id\": "
/applications/force query "select count() from event where ownerid = '$user_id' and startDateTime >= today "
USEREVENTS="$( /applications/force bulk query event "select id, ownerid from event where ownerid = '$user_id' and startDateTime >= today " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s leads
/applications/$USERLEADS > desktop/leads_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/leads_to_transfer.csv
# update the leads
/applications/force bulk update lead desktop/leads_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s accounts
/applications/$USERACCTS > desktop/accounts_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/accounts_to_transfer.csv
# update the accounts
/applications/force bulk update account desktop/accounts_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s contacts
/applications/$USERCONS > desktop/contacts_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/contacts_to_transfer.csv
# update the contacts
/applications/force bulk update contact desktop/contacts_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s won opportunities
/applications/$USERWON > desktop/won_opps_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/won_opps_to_transfer.csv
# update the won opportunities
/applications/force bulk update opportunity desktop/won_opps_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s open tasks
/applications/$USERTASKS > desktop/open_tasks_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/open_tasks_to_transfer.csv
# update the open tasks
/applications/force bulk update task desktop/open_tasks_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s upcoming events
/applications/$USEREVENTS > desktop/upcoming_events_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/upcoming_events_to_transfer.csv
# update the upcoming events
/applications/force bulk update event desktop/upcoming_events_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s open opportunities
/applications/$USEROPPS > desktop/open_opps_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/open_opps_to_transfer.csv
# update the open opportunities
/applications/force bulk update opportunity desktop/open_opps_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s email templates
/applications/$USERTEMPLATES > desktop/email_templates_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/email_templates_to_transfer.csv
# update the upcoming events
/applications/force bulk update emailtemplate desktop/email_templates_to_transfer.csv
#!/bin/bash
# get users old user id
echo -e "enter the user id for the old username: "
read user_id
# get users new user id
echo -e "enter the user id for the new username: "
read new_user_id
say "thanks! just a second, let me get all those records"
# query the rep’s email templates to a csv
echo " number of email templates to be transferred for \"$user_id\": "
¬ "select count() from EmailTemplate where folderid = '$user_id' "
USERTEMPLATES="$( /applications/force bulk query EmailTemplate "select id, folderid from EmailTemplate where folderid = '$user_id' " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s qualifying and qualified leads to a csv
echo " number of leads to be transferred for \"$user_id\": "
/applications/force query "select count() from lead where isconverted = false and ownerid = '$user_id' and (status='qualifying' or status='qualified')"
USERLEADS="$( /applications/force bulk query lead "select id, ownerid from lead where isconverted = false and ownerid = '$user_id' and (status='qualifying' or status='qualified') " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s accounts to a csv
echo " number of accounts to be transferred for \"$user_id\": "
/applications/force query "select count() from account where ownerid = '$user_id' "
USERACCTS="$( /applications/force bulk query account "select id, ownerid from account where ownerid = '$user_id' " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s contacts to a csv
echo " number of contacts to be transferred for \"$user_id\": "
/applications/force query "select count() from contact where ownerid = '$user_id' "
USERCONS="$( /applications/force bulk query contact "select id, ownerid from contact where ownerid = '$user_id' " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s won opportunities for this month to a csv
echo " number of won opportunities to be transferred for \"$user_id\": "
/applications/force query "select count() from opportunity where ownerid = '$user_id' and isclosed = true and closedate = this_month "
USERWON="$( /applications/force bulk query opportunity "select id, ownerid from opportunity where ownerid = '$user_id' and isclosed = true and closedate = this_month " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s open opportunities to a csv
echo " number of open opportunities to be transferred for \"$user_id\": "
/applications/force query "select count() from opportunity where isclosed = false and stagename != 'Closed Lost' and ownerid = '$user_id' "
USEROPPS="$( /applications/force bulk query opportunity "select id, ownerid from opportunity where ownerid = '$user_id' and isclosed = false and stagename != 'Closed Lost' " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s open tasks to a csv
echo " number of open tasks to be transferred for \"$user_id\": "
/applications/force query "select count() from task where ownerid = '$user_id' and isclosed = false "
USERTASKS="$( /applications/force bulk query task "select id, ownerid from task where ownerid = '$user_id' and isclosed = false " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# query the rep’s upcoming events to a csv
echo " number of upcoming events to be transferred for \"$user_id\": "
/applications/force query "select count() from event where ownerid = '$user_id' and startDateTime >= today "
USEREVENTS="$( /applications/force bulk query event "select id, ownerid from event where ownerid = '$user_id' and startDateTime >= today " | grep "force bulk query retrieve" | awk 'END{print}' )"
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s leads
/applications/$USERLEADS > desktop/leads_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/leads_to_transfer.csv
# update the leads
/applications/force bulk update lead desktop/leads_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s accounts
/applications/$USERACCTS > desktop/accounts_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/accounts_to_transfer.csv
# update the accounts
/applications/force bulk update account desktop/accounts_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s contacts
/applications/$USERCONS > desktop/contacts_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/contacts_to_transfer.csv
# update the contacts
/applications/force bulk update contact desktop/contacts_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s won opportunities
/applications/$USERWON > desktop/won_opps_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/won_opps_to_transfer.csv
# update the won opportunities
/applications/force bulk update opportunity desktop/won_opps_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s open tasks
/applications/$USERTASKS > desktop/open_tasks_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/open_tasks_to_transfer.csv
# update the open tasks
/applications/force bulk update task desktop/open_tasks_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s upcoming events
/applications/$USEREVENTS > desktop/upcoming_events_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/upcoming_events_to_transfer.csv
# update the upcoming events
/applications/force bulk update event desktop/upcoming_events_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s open opportunities
/applications/$USEROPPS > desktop/open_opps_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/open_opps_to_transfer.csv
# update the open opportunities
/applications/force bulk update opportunity desktop/open_opps_to_transfer.csv
# Wait 5 seconds for the bulk job to finish
sleep 5s
# update the rep’s email templates
/applications/$USERTEMPLATES > desktop/email_templates_to_transfer.csv
# replace the old user id with the new user id
perl -pi -e s/$user_id/$new_user_id/g desktop/email_templates_to_transfer.csv
# update the upcoming events
/applications/force bulk update emailtemplate desktop/email_templates_to_transfer.csv
@jvolkov
Copy link
Author

jvolkov commented Jul 10, 2017

This is a bash script used to move records from an older username to a new username inside Salesforce.

Based on the old Force.com Heroku CLI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment