S-Control Tips, Tricks and Gotchas
JavaScript- The OTHER white meat.
ISSUE: The JavaScript embedded on my SF page is not functioning at all
- Make sure you've included all necessary script tags in the html <head> group at the start of the page. For SalesForce, these look like:
<script src="/soap/ajax/11.0/connection.js" type="text/javascript"></script>
<script src="/soap/ajax/11.0/apex.js" type="text/javascript"></script>
ISSUE: I Want to Override the 'New' Button to Insert Data into a Field
- You can drop static or variable data into fields when the user clicks the new button for any type of object
- newURL will store the entire URL string. ($Action.Object.New, null, null, true) where object is the object whose button you are overriding.
- cancelURL is the objects front door address, this can be found in the browser bar when that object is selected, or can be identified using the schema browser in the Force.com Eclipse IDE
- '&lea3' is the field name that you want your data inserted into, in this case, lea3 is the id value for the lead "Company" field. Here we're inserting the static string 'Students'.
- If we don't want a static string, we can insert variable account data. {!Contact.Name} would insert the Name value for the most recently accessed contact into the "Company" field.
<script>
var newUrl = '{!URLFOR($Action.Lead.New , null, null, true)}';
var cancelUrl = '&cancelURL=/';
cancelUrl += '00Q/e';
newUrl += '&lea3=Students';
newUrl += cancelURL;
newURL += '&retURL=$Request.retURL';
window.parent.location.href = newURL;
</script>
