You need to sign in to do that
Don't have an account?

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();
}
}
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();
}
}
Try using
Hope this helps you!
If this helps you please mark it as solved.
Thanks and Regards
Sandhya
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?