Generate Random Password on Button Click in Salesforce



On Click Button Generate Password

Button Code

//Connection
{!REQUIRESCRIPT("/soap/ajax/37.0/connection.js")} 
var p = new sforce.SObject("Contact"); 
p.id = "{!Contact.Id}"; 

if(confirm('Are you sure you want to generate a new password for this Contact?')==true){ 
var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; 
var string_length = 8; 
var randomstring = ''; 

//random password generate logic
for(var i=0; i<string_length; i++){ 
var rnum = Math.floor(Math.random() * chars.length); 
randomstring += chars.substring(rnum,rnum+1); 

//assign random generated password
p.Password__c = randomstring; 
//Update contact
result = sforce.connection.update([p]); 
//reload page
location.reload(true);

Thanks Cheers! Lets Share your feedback.

0 comments:

Post a Comment