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
RatherGeekyRatherGeeky 

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!


 

Best Answer chosen by Admin (Salesforce Developers) 
RatherGeekyRatherGeeky

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;

 


 

Message Edited by J Baze on 05-14-2009 04:20 PM

All Answers

RatherGeekyRatherGeeky

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.

Message Edited by J Baze on 05-12-2009 09:18 AM
RatherGeekyRatherGeeky

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;

 


 

Message Edited by J Baze on 05-14-2009 04:20 PM
This was selected as the best answer