+ Start a Discussion
Karthikeyan ChandranKarthikeyan Chandran 

Opportunity custom List Button error?

Hi,

Here, the related list button should visible only when i choose the values "REQ", "Solution Sale" in the picklist field 'Pre Opportunity Type' and the picklist Approval Status valus is "Approved".

So, I just used the below java script to create a list button and i got an error,

https://developer.salesforce.com/forums/servlet/rtaImage?eid=906F0000000BYUM&feoid=Body&refid=0EMF0000000RD3C (https://developer.salesforce.com/forums/servlet/rtaImage?eid=906F0000000BYUM&feoid=Body&refid=0EMF0000000RD3C

https://developer.salesforce.com/forums/servlet/rtaImage?eid=906F0000000BYUM&feoid=Body&refid=0EMF0000000RD3H (https://developer.salesforce.com/forums/servlet/rtaImage?eid=906F0000000BYUM&feoid=Body&refid=0EMF0000000RD3H)
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 

if('{!Pre_Opportunity_Stage__c.Pre_Opportunity_Type__c}' == 'RFQ','{!Pre_Opportunity_Stage__c.Pre_Opportunity_Type__c}' == 'Solution Sale'){ 
window.open('https://cs50.salesforce.com/006/e?retURL=%{!Account.Id}&accid={!Account.Id}'); 
} 
else{ 
alert('You can not create new oppty'); 
}


In my URL:
https://cs50.salesforce.com/006/e?retURL=%&oppid=

The error message is:

Illegal Request
You have sent us an Illegal URL or an improperly formatted request. 

I don't know what i am missing here. i already post a question link - https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BYUMIA4# 

I need to fix it immediately ASAP.

Can you help me on this?

Thanks & Regards,
Karthikeyan Chandran
 
Best Answer chosen by Karthikeyan Chandran
Alexander TsitsuraAlexander Tsitsura
Try this
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 

if(('{!Pre_Opportunity_Stage__c.Pre_Opportunity_Type__c}' == 'RFQ'||'{!Pre_Opportunity_Stage__c.Pre_Opportunity_Type__c}' == 'Solution Sale') && ('{!Pre_Opportunity_Stage__c.Approval__c}' == 'Approved')){ 
  if ('{!Account.Id}' != '') { 
    window.open('/setup/ui/recordtypeselect.jsp?ent=Opportunity&save_new_url=/006/e&retURL=/{!Account.Id}&opp3={!Account.Name}&opp4={!Account.Name}&opp4_lkid={!Account.Id}'); 
  } else { 
    window.open('/setup/ui/recordtypeselect.jsp?ent=Opportunity&save_new_url=/006/e');
  }
} 
else{ 
  alert('You can not create new oppty'); 
}

 

All Answers

Alexander TsitsuraAlexander Tsitsura
Hi Karthikeyan Chandran

Problem is that, Account field not specified on your record. You can add this condition to your js code.

As a common practice, if your question is answered, please choose 1 best answer. 
But you can give every answer a thumb up if that answer is helpful to you.

Thanks,
Alex
 
Alexander TsitsuraAlexander Tsitsura
Try this code
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 

if('{!Pre_Opportunity_Stage__c.Pre_Opportunity_Type__c}' == 'RFQ','{!Pre_Opportunity_Stage__c.Pre_Opportunity_Type__c}' == 'Solution Sale'){ 
  if ('{!Account.Id}') {
    window.open('https://cs50.salesforce.com/006/e?retURL=%{!Account.Id}&accid={!Account.Id}');
  } else {
    window.open('https://cs50.salesforce.com/006/e');
  }
} 
else{ 
  alert('You can not create new oppty'); 
}

Thanks,
Alex


 
Karthikeyan ChandranKarthikeyan Chandran
Thanks for your suggestion, i used the code you provided but no luck.

Got the same error..
Alexander TsitsuraAlexander Tsitsura
Can you put here your url, after you click on button?
Karthikeyan ChandranKarthikeyan Chandran
This is my url that i got after clicking the list button,

https://cs50.salesforce.com/006/e?retURL=%&oppid=

The screen shot - 

User-added image
Alexander TsitsuraAlexander Tsitsura
Hm, it's very mysterious.

Can you try to replace?
if ('{!Account.Id}') {

on
if ('{!Account.Id}' != '') {

 
Karthikeyan ChandranKarthikeyan Chandran
I tried but, same error again
Alexander TsitsuraAlexander Tsitsura
Hm, can u put here you current code?
Karthikeyan ChandranKarthikeyan Chandran
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 

if('{!Pre_Opportunity_Stage__c.Pre_Opportunity_Type__c}' == 'RFQ','{!Pre_Opportunity_Stage__c.Pre_Opportunity_Type__c}' == 'Solution Sale'){ 
if ('{!Account.Id}' != ' ') { 
window.open('https://cs50.salesforce.com/006/e?retURL=%{!Account.Id}&accid={!Account.Id}'); 
} else { 
window.open('https://cs50.salesforce.com/006/e'); 
} 
} 
else{ 
alert('You can not create new oppty'); 
}
Alexander TsitsuraAlexander Tsitsura
copy&paste
 
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 

if('{!Pre_Opportunity_Stage__c.Pre_Opportunity_Type__c}' == 'RFQ','{!Pre_Opportunity_Stage__c.Pre_Opportunity_Type__c}' == 'Solution Sale'){ 
if ('{!Account.Id}' != '') { 
window.open('https://cs50.salesforce.com/006/e?retURL=%{!Account.Id}&accid={!Account.Id}'); 
} else { 
window.open('https://cs50.salesforce.com/006/e'); 
} 
} 
else{ 
alert('You can not create new oppty'); 
}

 
Alexander TsitsuraAlexander Tsitsura
i changed ['{!Account.Id}'] != 'SPACE' on ['{!Account.Id}' != '']

It's work now, or not?
Karthikeyan ChandranKarthikeyan Chandran
I did copy and paste it in the formula and click save the list button, i tried on list button same error repeated.

No changes!!
Alexander TsitsuraAlexander Tsitsura
maybe something cached?

try to clear you cach(if u using crome press Ctrl + Shift + Del) and check only "Cached images and files" or use another browser.
Karthikeyan ChandranKarthikeyan Chandran
Let me try..
Karthikeyan ChandranKarthikeyan Chandran
Alex,

Thank you so much. It's worked, i can create a new opportunity after i cleared the cache in my browser.

One more clarififation, 

The new record page (Opportunity) is not showing the proior page with list of record types, it's directed to me opportunity detail page. 

How do i direct to new page ti choose which record type the users after they click on the custom list button.

Here the screen shot that i want to direct this page.

User-added image

The currect code redirect me to directly to the opportunity edit page.

User-added image

 
Alexander TsitsuraAlexander Tsitsura
Can you try next link?
/setup/ui/recordtypeselect.jsp?ent=Opportunity&save_new_url=/006/e?accid={!Account.Id}

 
Karthikeyan ChandranKarthikeyan Chandran
I tried after i update with your suggestion but the page result is same, not changed.

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

if(('{!Pre_Opportunity_Stage__c.Pre_Opportunity_Type__c}' == 'RFQ'||'{!Pre_Opportunity_Stage__c.Pre_Opportunity_Type__c}' == 'Solution Sale') && ('{!Pre_Opportunity_Stage__c.Approval__c}' == 'Approved')){ 
if ('{!Account.Id}' != '') { 
window.open('https://cs50.salesforce.com//setup/ui/recordtypeselect.jsp?ent=Opportunity&save_new_url=/006/e?accid={!Account.Id}'); 
} else { 
window.open('https://cs50.salesforce.com/006/e');


else{ 
alert('You can not create new oppty'); 
}
Alexander TsitsuraAlexander Tsitsura
Try this
 
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 

if(('{!Pre_Opportunity_Stage__c.Pre_Opportunity_Type__c}' == 'RFQ'||'{!Pre_Opportunity_Stage__c.Pre_Opportunity_Type__c}' == 'Solution Sale') && ('{!Pre_Opportunity_Stage__c.Approval__c}' == 'Approved')){ 
  if ('{!Account.Id}' != '') { 
    window.open('/setup/ui/recordtypeselect.jsp?ent=Opportunity&save_new_url=/006/e?accid={!Account.Id}'); 
  } else { 
    window.open('/setup/ui/recordtypeselect.jsp?ent=Opportunity&save_new_url=/006/e');
  } 
} 
else{ 
  alert('You can not create new oppty'); 
}

 
Karthikeyan ChandranKarthikeyan Chandran
Nope :( 
Karthikeyan ChandranKarthikeyan Chandran
Not working :( 
Karthikeyan ChandranKarthikeyan Chandran

Any idea Alex?
Alexander TsitsuraAlexander Tsitsura
What not working? Pls, put here link and error message
Karthikeyan ChandranKarthikeyan Chandran
The code redirect me to directly to the opportunity edit page not on the pre select record type page.
Alexander TsitsuraAlexander Tsitsura
Maybe, you need clear cach again?

After click button you need redirected to url, that contains '/setup/ui/recordtypeselect.jsp?ent=Opportunity&save_new_url=/006/e'
Karthikeyan ChandranKarthikeyan Chandran
I cleared the cache again, tried to click on the custom list button and got error now.

User-added image
Alexander TsitsuraAlexander Tsitsura
Problem with js code, can u put here you current code?
Karthikeyan ChandranKarthikeyan Chandran
Here the current code,
 
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 

if(('{!Pre_Opportunity_Stage__c.Pre_Opportunity_Type__c}' == 'RFQ'||'{!Pre_Opportunity_Stage__c.Pre_Opportunity_Type__c}' == 'Solution Sale') && ('{!Pre_Opportunity_Stage__c.Approval__c}' == 'Approved')){ 
  if ('{!Account.Id}' != '') { 
    window.open('/setup/ui/recordtypeselect.jsp?ent=Opportunity&save_new_url=%2F006%2Fe%3F&retURL=/{!Account.Id}&
opp3={!Account.Name} - &
opp4={!Account.Name}&
opp4_lkid={!Account.Id}'); 
  } else { 
    window.open('/setup/ui/recordtypeselect.jsp?ent=Opportunity&save_new_url=%2F006%2Fe%3F&retURL=/{!Account.Id}&
opp3={!Account.Name} - &
opp4={!Account.Name}&
opp4_lkid={!Account.Id}');
  } 
} 
else{ 
  alert('You can not create new oppty'); 
}

 
Alexander TsitsuraAlexander Tsitsura
Try this
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")} 

if(('{!Pre_Opportunity_Stage__c.Pre_Opportunity_Type__c}' == 'RFQ'||'{!Pre_Opportunity_Stage__c.Pre_Opportunity_Type__c}' == 'Solution Sale') && ('{!Pre_Opportunity_Stage__c.Approval__c}' == 'Approved')){ 
  if ('{!Account.Id}' != '') { 
    window.open('/setup/ui/recordtypeselect.jsp?ent=Opportunity&save_new_url=/006/e&retURL=/{!Account.Id}&opp3={!Account.Name}&opp4={!Account.Name}&opp4_lkid={!Account.Id}'); 
  } else { 
    window.open('/setup/ui/recordtypeselect.jsp?ent=Opportunity&save_new_url=/006/e');
  }
} 
else{ 
  alert('You can not create new oppty'); 
}

 
This was selected as the best answer
Karthikeyan ChandranKarthikeyan Chandran
It's works Great Thank you so much Alex!!