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
Jim MontgomeryJim Montgomery 

Window.location has undefined ID at end of URL

I am running this script in a VF page. When executed, the url the link goes to has undefined at the end with an error that the URL no longerv exists.

<apex:page standardController="Opportunity">
<script src="/soap/ajax/10.0/connection.js"> </script > <script src="/soap/ajax/10.0/apex.js"> </script >
<script type="text/javascript">
window.onload=init()
function init()
{ var p = new sforce.SObject('Opportunity');
p.id = "{!Opportunity.Id}";
p.Tax_Renewal_SFS_Books_Complete__c = true;
result = sforce.connection.update([p]);
window.location.href = "https://wktaa.my.salesforce.com/"+p.Id; };
</script>
</apex:page>

It performs the field update, just errors out on the re-direct.
I have the same code running on another object and it works fine.
Any ideas?
Etienne Rocheleau 9Etienne Rocheleau 9
Just for reading your question, it looks like
 
p.id !== p.Id

You are redirecting to "url" + [variable], so when variable is undefined then that's what it will print when trying to convert it to a string.
I would suggest you had some validation to make sure p.id or p.Id is not undefined before trying to redirect to that id.