You need to sign in to do that
Don't have an account?
Emilee Crocker 3
How to change javascript to visualforce
I'm trying to create a visualforce page from the following javascript but I keep getting multiple error messages.
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}
sforce.connection.sessionId = "{!$Api.Session_ID}";
var E = new sforce.SObject("Lead");
E.id = '{!Lead.Id}';
// Replace below with your field.
E.To_Be_Set_Up__c=true;
// Replace below with your field.
E.Status = 'Converted';
// save the change
sforce.connection.update([E]);
//refresh the page
window.location.reload();
{!REQUIRESCRIPT("/soap/ajax/33.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/33.0/apex.js")}
sforce.connection.sessionId = "{!$Api.Session_ID}";
var E = new sforce.SObject("Lead");
E.id = '{!Lead.Id}';
// Replace below with your field.
E.To_Be_Set_Up__c=true;
// Replace below with your field.
E.Status = 'Converted';
// save the change
sforce.connection.update([E]);
//refresh the page
window.location.reload();
All Answers
Can you provide more detail on it.
What kind of errors you are getting.
Thanks,
Aman
In vf page, we have to include js in different way. So try the below code snippet: Kindly let me know if this helps.
Please like the answer and mark it as best if this helps.
Thanks,
Aman
Yes, compiler is correct. sorry, forgot to add <apex:page > in snippet. Please try update one: Thanks,
Aman
Got the error.
Seems you are not passing lead record id in the page url. Kindly pass it like below:
Also update the snippet again to add Lead standard controller like below:
Thanks,
Aman
/window.location.reload();
//window.location.reload();
Can you show me your snippet?
Have you save your changes?
<apex:includeScript value="/soap/ajax/33.0/connection.js"/>
<apex:includeScript value="/soap/ajax/33.0/34.0/apex.js"/>
<script>
sforce.connection.sessionId = "{!$Api.Session_ID}";
var E = new sforce.SObject("Lead");
E.id = '{!Lead.Id}';
// Replace below with your field.
E.To_Be_Set_Up__c=true;
// Replace below with your field.
E.Status = 'Converted';
// save the change
result = sforce.connection.update([E]);
//refresh the page
window.location.reload();
//window.location.reload();
</script>
</apex:page>
Thanks
So you want to redirect to lead detail page once your lead get updated. For that update code like below:
Kindly likes the answers if they helps and Mark answer as best when you have done with the task.
Thanks
Can you try to replace
window.open('/{!Lead. Id}');
with
window.location.href = '{!$Site.BaseUrl}/{!Lead. Id}';
This should work.
Thanks
It's coming up with the error: Unknown property 'LeadStandarController.Site'
The above is exactly what I have typed. I just retyped it all in to see if I made a mistake but it is still coming up with a blank page after clicking the button.