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
CushtyCushty 

Java button on Lead List view

Hi,

I have created a custom button in java on the Lead List view and cannot get it to work properly.

As its a button on the list view it first checks you have selected a record, otherwise shows an error and then once records are selected it needs to check that a picklist field is 'MQL' and if so changes the value of a few fields.  If the picklist is anything else other than MQL it displays and error.

I am nearly there but the error on th epicklist shows regardless of the picklist value....

{!REQUIRESCRIPT ("/soap/ajax/24.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")} 
var records = {!GETRECORDIDS($ObjectType.Lead)};

var newRecords = [];

if (records[0] == null) {
alert("Please select at least one row");

} else {

if('{!Lead.Lead_Lifecycle_Stage__c}' != "Marketing Qualified Lead (MQL)") {
alert("You cannot Take Ownership of this lead until it has reached the Marketing Qualified Lead (MQL) stage.\n\n If you would like this lead fast tracked to MQL, please contact Marketing.");

} else {

for (var n=0; n<records.length; n++) {
var l = new sforce.SObject("Lead");l.id = records[n];
l.OwnerId ="{!$User.Id}";
l.Status = "Open";
l.Lead_Lifecycle_Stage__c = "Sales Accepted Lead (SAL)";

newRecords.push(l);
}
result = sforce.connection.update(newRecords);
parent.window.location.reload();
}
}
SandhyaSandhya (Salesforce Developers) 
Hi,

Try using
 

if('{!Lead.Lead_Lifecycle_Stage__c}' != "Marketing Qualified Lead (MQL)") {

IF(!(ISPICKVAL(Lead_Lifecycle_Stage__c,'Marketing Qualified Lead (MQL)')))
Hope this helps you!

If this helps you please mark it as solved.

Thanks and Regards
Sandhya



 
CushtyCushty
Hi,
Its not worked.
I wanted the error to appear if the user selected anythign else apart fomr MQL.
I have now tyed out every option but now its skipping the error entirely.  Now I have

{!REQUIRESCRIPT ("/soap/ajax/24.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")} 
var records = {!GETRECORDIDS($ObjectType.Lead)}; 

var newRecords = []; 

if (records[0] == null) { 
alert("Please select at least one row"); 

} else { 

if({!ISPICKVAL(Lead.Lead_Lifecycle_Stage__c, 'New Lead')} || {!ISPICKVAL(Lead.Lead_Lifecycle_Stage__c, 'Active')} || {!ISPICKVAL(Lead.Lead_Lifecycle_Stage__c, 'Engaged')} || {!ISPICKVAL(Lead.Lead_Lifecycle_Stage__c, 'Industry Influencer')} || {!ISPICKVAL(Lead.Lead_Lifecycle_Stage__c, 'Recycled')} || {!ISPICKVAL(Lead.Lead_Lifecycle_Stage__c, 'Disqualified')}) { 
alert('You cannot Take Ownership of this lead until it has reached the Marketing Qualified Lead (MQL) stage.\n\n If you would like this lead fast tracked to MQL, please contact Marketing.'); 

} else { 


for (var n=0; n<records.length; n++) { 
var l = new sforce.SObject("Lead");l.id = records[n]; 
l.OwnerId ="{!$User.Id}"; 
l.Lead_Lifecycle_Stage__c = "Sales Accepted Lead (SAL)"; 

newRecords.push(l); 

result = sforce.connection.update(newRecords); 
parent.window.location.reload(); 

}

Any idas why the picklist is ignored?