Posts

Showing posts from October, 2014

Use Chrome for Development and Allow Cross-domain Javascript and AJAX

Image
Use Another Instance of Chrome while Retrieving Content or Data from an Ajax Source on a Different Domain

If you are developing an application and calling a data source from another domain, you may encounter trouble when trying to use AJAX to retrieve a JSON data source from a service API for instance.

You may see an error message like the following:

Chrome XMLHttpRequest cannot load [THE_URL_ENDPOINT].  No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access.
- OR -

IE SEC7118: XMLHttpRequest for [THE_URL_ENDPOINT] required Cross Origin Resource Sharing (CORS). 
SEC7119: XMLHttpRequest for [THE_URL_ENDPOINT] required CORS preflight. 
SEC7120: Origin http://localhost:8080 not found in Access-Control-Allow-Origin header. 
SCRIPT7002: XMLHttpRequest: Network Error 0x80070005, Access is denied.



There are many solutions to this such as using JSONP or modifying the header, Access-Control-Allo…

Disabled Save Button on Forms while Saving in Salesforce

Image
How to Disable the Save Button on your Form while the Form is Saving to Prevent Multiple Submissions in a Custom Salesforce Visualforce Page

Salesforce default functionality on forms will disable the save button after the form is submitted to prevent multiple submissions.
The disabled Save button will look like:

When creating your own VisualForce page you can write custom code to mimic this functionality in your forms using just Javascript and modifying the button's CSS styles.




Create Javascript functions to disable and enable the save button

You will need to create 2 Javascript functions that will enable and disable the button by modifying the css and properties of the save button.

I am using jQuery but you can also do this with vanilla Javascript. I am currently using a unique style class attached to the button to look it up for convenience since this page does not get modified very often if ever and also because the element id is used by Salesforce for internal SFDC funct…