I have used the following core script for years -- all I have to do modify the "sqlWHERE" definition in the code when a new situation arises. Believe me, typing "jython
import SQLForce
def _getOwnerId( session, alias ):
return session.select("select id from user where alias='" + alias + "'")[0][0];
if __name__ == '__main__':
session = SQLForce.Session("production")
newOwnerAlias = "newSalesperson"
oldOwnerAlias = 'oldSalesperson"
newOwnerId = _getOwnerId( session, newOwnerAlias )
sqlWHERE = "owner.alias='" + oldOwnerAlias + """'
AND isClosed=false
AND closeDate >= 2012-01-01
"""
updateRecords = []
for record in session.selectRecords( "SELECT id from Opportunity WHERE " + sqlWHERE ):
updateRecords.append( [ record.id, newOwnerId ])
if len(updateRecords) > 0:
print "Time to Update ", len(updateRecords)
session.update( "Opportunity", ["ownerId"], updateRecords )
else:
print "No records modified"
Note: SQLForce is freeware at www.capstorm.com
No comments:
Post a Comment