I tried to write javascript custom convert lead button with validation. Everything is working as expected but in the last two cases, after converting the client, the user is redirected to the newly created account and users who use the console must return to it.

The question is how to convert the code below to recognize whether the action takes place in the console and opens a new tab or as before.

I can also assume that the action always takes place in the console. How should it look like in this case?


var Check = '{!JSENCODE(Lead.To_check__c)}';
var Date = '{!JSENCODE(TEXT(Lead.date_time_of_established_contact__c))}';
var Place = '{!JSENCODE(Lead.place_of_established_contact__c)}';
var Purpose = '{!JSENCODE(Lead.Purpose_of_the_meeting__c)}';

if(Check == 'Yes' && Date == '')
{alert('Field1 is empty');}

if(Check == 'Yes' && Place == '')
{alert('Field2 is empty');}

if(Check == 'Yes' && Purpose == '')
{alert('Field3 is empty');}

if(Check == 'No')
{window.parent.location.href="lead/leadconvert.jsp? retURL=%2F"+'{!Lead.Id}'+"&id="+'{!Lead.Id}';}

if(Check == 'Yes' && Place != '' && Date != '' && Purpose != '')

1 Answer 1


You can easily check it with sforce.console.isInConsole().

For more reference, check this link: https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_isinconsole.htm

Also, if you want to "play" with console tabs, check this out: https://developer.salesforce.com/docs/atlas.en-us.api_console.meta/api_console/sforce_api_console_openprimarytab.htm

  • Thanks, Second option works with : {sforce.console.openPrimaryTab(null,'/lead/leadconvert.jsp?retURL=%2F{!Lead.Id}&id={!Lead.Id}',true);}
    – Jacob K
    Commented Apr 24, 2018 at 10:17

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .