2

OI have a field called qualification score to validate lead before converted when qualification score <=60.

But qualification score is a string it will be like 5%,60% or Something like x%.

So, I need to convert in to an integer and validate.

But I am getting this error:

missing ; before statement

Please let me know where i missed it.

{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}
String ourString = Lead.Qualification_Score__c;
String[] stringCharacters = ourString.split('%');
var child;
if(stringCharacters.length==1)
{
child = stringCharacters[0];
}
if(stringCharacters.length>1)
{
child =stringCharacters[0]+stringCharacters[1];
}
Integer d = Integer.ValueOf(child);
if(d<=60)
{
alert("Lead is not enough to qualify");
}
else{
window.open('https://cs57.salesforce.com/lead/leadconvert.jsp?retURL={!Lead.Id}&id={!Lead.Id}&_CONFIRMATIONTOKEN=VmpFPSxNakF4Tnkwd05DMHhObFF4TlRveE1Eb3hNUzQzTURGYSxoN2xDU05yM1FLVTZRb0x6bVJzaHMzLE4yWTBNVEJt&common.udd.actions.ActionsUtilORIG_URI=%2Flead%2Fleadconvert.jsp');
}
4
  • Is that qualification_score__c is percent field? Commented Apr 13, 2017 at 16:21
  • No it is a string field and we are calculating through apex with our criteria
    – Pavan tej
    Commented Apr 13, 2017 at 16:25
  • Is this JavaScript or Apex...? This isn't quite valid either way.
    – sfdcfox
    Commented Apr 13, 2017 at 16:47
  • Sorry i am new to javascript i thought it works but i dont know where i missed it.
    – Pavan tej
    Commented Apr 13, 2017 at 16:48

3 Answers 3

3

In a JavaScript button, it would be:

var score = parseInt("{!Lead.Qualification_Score__c}");
if(score<60) {
    alert("The score is too low");
} else {
    window.open("{!URLFOR($Action.Lead.Convert, Lead.Id, [id=Lead.Id], true)}");
}

Use parseInt to read the value. Use URLFOR for the correct (domain-agnostic) URL.

2
  • Really you are life saver it works like as expected
    – Pavan tej
    Commented Apr 13, 2017 at 16:54
  • @SantanuBoral JavaScript's parseInt simply reads digits until it finds a non-digit and stops. Feel free to read more on MDN parseInt.
    – sfdcfox
    Commented Apr 13, 2017 at 17:07
0

One You have declared var child inside the for loop and using it outside the loop. So declare the variable before the for loop.

two Since the stringCharacters list will always have the correct value at index 0, you can directly use it instead of looping through it.

var child = stringCharacters[0] ;

Just doing this will serve your purpose instead of a for loop.

1
  • I am getting same error updated my code check once and let me know if i missed anything
    – Pavan tej
    Commented Apr 13, 2017 at 16:41
0

You have mixed up apex with javascript.

There are no such String or Integer declarations in javascript.

Since qualification score is a string it will be like 5%,60% or Something like x%, so you have to trim off the % from end.

{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/24.0/apex.js")}

var ourString = {!VALUE( MID(Lead.Qualification_Score__c, 0, LEN(Lead.Qualification_Score__c)-1))};
if(ourString<=60)
{
    alert("Lead is not enough to qualify a lead");
}
else{
    window.open("{!URLFOR($Action.Lead.Convert, Lead.Id, [id=Lead.Id], true)}");
}

You must log in to answer this question.

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