You need to sign in to do that
Don't have an account?
Automatically Save Changes on VF Page When Running Function
I want to automatically run a save action when the user clicks
on the "Close Opportunity" button on this visualforce page.
Existing code:
<input class="btn" type="button" title="Close Opportunity" name="close" value=" Close Opportunity " onClick="onClickClose()"/> <apex:commandButton action="{!cancel}" value="Cancel" id="cancelButton"/> <apex:outputText value="" id="status"/>
How can I add this functionality to the existing button? or to the
onClickClose function?
I don't want the save function to send the user back to the record,
but to the location as determined inthe onClickClose function.
Likely a simple answer, but I'm struggling.
Thanks to anyone willing to help!
Resolved on my own.
var new_amount = document.getElementById("{!$Component.f.pb2.pbs2.si5.edit_Amount}"); var won = (wonElement.value == "Yes"); // Close the current opportunity var oppToClose = new sforce.SObject("Opportunity"); oppToClose.Id = "{!Opportunity.Id}"; oppToClose.StageName = reasonElement.value; // format date in a way that can be used by SF var dt = new Array(); dt = new_closedate.value; dt = dt.split('/'); var d = dt[0]; // return day var m = dt[1]; // return month var y = dt[2]; // return year if(d.length = 1) { d = "0" + d; } if(m.length = 1){ m = "0" + m; } oppToClose.CloseDate = y + "-" + d + "-" + m;
All Answers
Have thought about this more.
This page is written mostly in javascript. So, perhaps a better question is:
" How do I call a {!Save} -type function within javascript?"
That way I could include it in the onClickClose() function and it would
allow me to save any changes the user made in input fields.
If anyone could point me to some research materials or other helpful info,
that would be much appreciated.
Resolved on my own.
var new_amount = document.getElementById("{!$Component.f.pb2.pbs2.si5.edit_Amount}"); var won = (wonElement.value == "Yes"); // Close the current opportunity var oppToClose = new sforce.SObject("Opportunity"); oppToClose.Id = "{!Opportunity.Id}"; oppToClose.StageName = reasonElement.value; // format date in a way that can be used by SF var dt = new Array(); dt = new_closedate.value; dt = dt.split('/'); var d = dt[0]; // return day var m = dt[1]; // return month var y = dt[2]; // return year if(d.length = 1) { d = "0" + d; } if(m.length = 1){ m = "0" + m; } oppToClose.CloseDate = y + "-" + d + "-" + m;