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
Adriana VoyceAdriana Voyce 

Javascript error on working button

Hi! I created a button that is supposed to check a checkbox on an opportunity and open a window which allows a use to download a docoument....

The button works, the checkbox is checked and the window pops up to download, but when I click the button an error appears first and then the window pops up... How do I get rid of this error?

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")} 
var newRecords = []; 
var c = new sforce.SObject("Opportunity"); 
c.id ="{!Opportunity.Id}"; 
c.Voice_Referal__c = true; 
newRecords.push(c); 
result = sforce.connection.update(newRecords); 
window.location.replace('/apex/SDOC__SDCreate1?id={!Opportunity.Id}&Object=Opportunity')();

User-added image
Best Answer chosen by Adriana Voyce
Amit Chaudhary 8Amit Chaudhary 8
Please try window.open
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")} 
var newRecords = []; 
var c = new sforce.SObject("Opportunity"); 
c.id ="{!Opportunity.Id}"; 
c.Voice_Referal__c = true; 
newRecords.push(c); 
result = sforce.connection.update(newRecords); 
window.open('/apex/SDOC__SDCreate1?id={!Opportunity.Id}&Object=Opportunity');

Please check below post for more example on same
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BQRHIA4

Please let us know if this will help you

Thanks,
Amit Chaudhary

All Answers

Amit Chaudhary 8Amit Chaudhary 8
Please try window.open
{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")} 
var newRecords = []; 
var c = new sforce.SObject("Opportunity"); 
c.id ="{!Opportunity.Id}"; 
c.Voice_Referal__c = true; 
newRecords.push(c); 
result = sforce.connection.update(newRecords); 
window.open('/apex/SDOC__SDCreate1?id={!Opportunity.Id}&Object=Opportunity');

Please check below post for more example on same
https://developer.salesforce.com/forums/ForumsMain?id=906F0000000BQRHIA4

Please let us know if this will help you

Thanks,
Amit Chaudhary
This was selected as the best answer
Adriana VoyceAdriana Voyce
Thank you so much @Amit this worked great!