+ Start a Discussion
Robert Robinson 48Robert Robinson 48 

A puzzler with Java Script buttons after a sandbox refresh

We have a set of JavaScript buttons which are designed to generate new opportunities when a user clicks a button from a related list on an account. These buttons were working as planned yesterday. Overnight, we refreshed our full UAT sandbox from production. This morning, when I try to generate a new opportunity in the sandbox, Salesforce opens up a new page and tries to log in to production. The process then errors out, as the system is trying to create an opportunity in the wrong environment. When you take the ID generated in production, then apply it back to the sandbox, a new opportunity is then created. I have reviewed the JavaScript button, and I see no references to the production org.

Here is one of the JavaScript buttons:
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")} {!REQUIRESCRIPT("/soap/ajax/31.0/apex.js")} var opportunity = new sforce.SObject('Opportunity'); opportunity.Name = 'Do Not Delete'; opportunity.AccountId = '{!Account.Id}'; opportunity.RecordTypeId = '{!$Setup.Opportunity_Record_Type_Ids__c.Standard_Services__c}'; opportunity.StageName = 'Qualification'; var closeDate = new Date('{!TODAY()}'); closeDate.setMonth(closeDate.getMonth()+6); opportunity.CloseDate = closeDate; var result = sforce.connection.create([opportunity]); if(result[0].success == 'true'){ var serverPrefix = '{!$Setup.Server_Prefix__c.Server_Prefix__c}'; var oppId = result[0].id; parent.window.location.href = 'https://' + serverPrefix + '.salesforce.com/' + oppId; } else{ alert('Record creation failed - please notify system administrator'); }

The Standard Services Opportunity Record ID is in Custom Settings. The Record IDs point to Record types within UAT
Best Answer chosen by Robert Robinson 48
Andrew GAndrew G
Hi Robert

The Custom settings would need to be investigated by the sound of it.

your line var serverPrefix = '{!$Setup.Server_Prefix__c.Server_Prefix__c}';  points to the possible source of your issue.

Regards
Andrew

 

All Answers

Andrew GAndrew G
Hi Robert

The Custom settings would need to be investigated by the sound of it.

your line var serverPrefix = '{!$Setup.Server_Prefix__c.Server_Prefix__c}';  points to the possible source of your issue.

Regards
Andrew

 
This was selected as the best answer
Robert Robinson 48Robert Robinson 48
You were in the right neighborhood. The Consultants used the "Server Prefix" to identify the environment which the JavaScript button needed to use. I located the Server Prefix Action in Custom Settings; of course, when the refresh was performed, the production setting was copied over to the sandbox. Once this was changed, all of the related JavaScript buttons worked perfectly.