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
cldavecldave 

Please help me with Button code

Hi trying to make button called "transfer" on lead that will do 2 actions.

 

1- In field called Transfer rep: for current user;s name to be inputed there

2.in field called Transfer's date: input today's date

 

 

could anyone please help with that?

 

 

 

Thank you in advance

 

 

Best Answer chosen by Admin (Salesforce Developers) 
ReidCReidC

I did this.  Where you called transfer rep, I called it User__c.  Make sure you specify execute javascript yada yada.

 

{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")}

var updateRecord = new Array(); 
var myquery = "SELECT Id FROM Lead WHERE Id = '{!Lead.Id}' limit 1";

result = sforce.connection.query(myquery);
records = result.getArray("records");

if(records[0])
{
    var update_Lead = records[0];
    update_Lead.User__c = "{!$User.Id}"; 
    update_Lead.Transfer_Date__c = sforce.internal.dateTimeToString(new Date());
    updateRecord.push(update_Lead);
}

result = sforce.connection.update(updateRecord);
parent.location.href = parent.location.href;

 

All Answers

ReidCReidC

I did this.  Where you called transfer rep, I called it User__c.  Make sure you specify execute javascript yada yada.

 

{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")}

var updateRecord = new Array(); 
var myquery = "SELECT Id FROM Lead WHERE Id = '{!Lead.Id}' limit 1";

result = sforce.connection.query(myquery);
records = result.getArray("records");

if(records[0])
{
    var update_Lead = records[0];
    update_Lead.User__c = "{!$User.Id}"; 
    update_Lead.Transfer_Date__c = sforce.internal.dateTimeToString(new Date());
    updateRecord.push(update_Lead);
}

result = sforce.connection.update(updateRecord);
parent.location.href = parent.location.href;

 

This was selected as the best answer
Shivanath DevnarayananShivanath Devnarayanan
ReidC's Code should work fine for the requirement.
cldavecldave

Thank you very much for your help :)

 

Quick question , the returned "User name " come out as User's ID , any simple way for it to return the name of user instead?

 

or would i have to create another field and a workflow action?

 

 

Thanks