Salesforce.com Archives - Justin Silver https://www.justinsilver.com/tag/salesforce-com/ Technology, Travel, and Pictures Tue, 19 Apr 2016 18:24:59 +0000 en-US hourly 1 https://wordpress.org/?v=6.0.1 https://www.justinsilver.com/wp-content/uploads/2013/06/cropped-apple-touch-icon-160x160.png Salesforce.com Archives - Justin Silver https://www.justinsilver.com/tag/salesforce-com/ 32 32 Use jQuery + Plugins with Visualforce Pages https://www.justinsilver.com/technology/salesforce/use-jquery-plugins-visualforce-pages/?utm_source=rss&utm_medium=rss&utm_campaign=use-jquery-plugins-visualforce-pages https://www.justinsilver.com/technology/salesforce/use-jquery-plugins-visualforce-pages/#respond Sun, 09 Nov 2014 11:31:25 +0000 http://justinsilver.com/?p=3820 The jQuery library makes it much easier to create cross-browser functionality on any web page, and Salesforce Visualforce pages are no exception. Going one step further and include jQuery plugins in your pages as...

The post Use jQuery + Plugins with Visualforce Pages appeared first on Justin Silver.

]]>
AmpedSense.OptimizeAdSpot('AP'); AmpedSense.OptimizeAdSpot('IL'); AmpedSense.OptimizeAdSpot('IR');

The jQuery library makes it much easier to create cross-browser functionality on any web page, and Salesforce Visualforce pages are no exception. Going one step further and include jQuery plugins in your pages as well for even more functionality and sparkles. But what do you do when you want to use a more recent version of jQuery, and your plugin is being reported as an undefined function in the console? To the rescue comes jQuery.noConflict(true);.

First you will want to upload both jQuery and your plugin as Static Resources, or from a CDN if you prefer. For our purposes we will assume they are Static Resources called jQuery and jQueryPlugin. As soon as the javascript sources is includes – jQuery first followed by plugins – we need to make a call to noConflict() to free up the $ resources. Using jQuery as an alias is easy and logical.

Next we want to tell our code to run after the DOM of the page has loaded, so we wrap our code inside a function that is called by jQuery.ready(). A neat trick here is to pass jQuery back into the callback function as $, so your code will know the version of jQuery you loaded and it’s attached plugins as the standard $.

<!-- include static resources -->
<apex:includeScript value="{!$Resource.jQuery}" />
<apex:includeScript value="{!$Resource.jQueryPlugin}" />
<script type="text/javascript">
// Alias to jQuery and free $
jQuery = $.noConflict(true);

// Call jQuery.ready(), and alias jQuery back to $ by passing as an argument
jQuery(document).ready(function($){
	// use $.plugin()
	$('#container').plugin();

	// attach events to DOM elements
	$('.button').on('click', function(){
		alert('clicked!');
	});
});
</script>

The post Use jQuery + Plugins with Visualforce Pages appeared first on Justin Silver.

]]>
https://www.justinsilver.com/technology/salesforce/use-jquery-plugins-visualforce-pages/feed/ 0
Loggly.com Logging with Salesforce.com Apex https://www.justinsilver.com/technology/salesforce/loggly-com-logging-salesforce-com-apex/?utm_source=rss&utm_medium=rss&utm_campaign=loggly-com-logging-salesforce-com-apex https://www.justinsilver.com/technology/salesforce/loggly-com-logging-salesforce-com-apex/#respond Fri, 14 Feb 2014 01:26:21 +0000 http://justin.ag/?p=3173 If you want to send log messages to Loggly.com you will need to implement their HTTP API interface. All that is required to send data to this interface is an HTTP POST to a...

The post Loggly.com Logging with Salesforce.com Apex appeared first on Justin Silver.

]]>
AmpedSense.OptimizeAdSpot('AP'); AmpedSense.OptimizeAdSpot('IL'); AmpedSense.OptimizeAdSpot('IR');

If you want to send log messages to Loggly.com you will need to implement their HTTP API interface. All that is required to send data to this interface is an HTTP POST to a url containing your API token with the log message in the body. Tags can be applied either in the URL after your token or using theĀ X-LOGGLY-TAG. Setting the Content-Type header is also required with value of text/plain.

Worth noting that you should keep your Apex Limits in mind in regards to number of callouts and possibly implement a different scheme depending on your volume. Don’t forget to add “https://logs-01.loggly.com” to your Salesforce.com>Setup>Security Controls>Remote Site Settings.

Apex Class LogglyService.cls

This class uses theĀ @future (callout=true) annotation to make an HTTP POST to Loggly.com

public abstract class LogglyService {

    // Use a future method to make a callout
    @future (callout=true)
    public static void log(String data, String[] tags) {
        // this should come from config somewhere
    	final String api_key = 'GET YOUR API KEY FROM SOMEWHERE';

        // objects to make the request
        HttpRequest request = new HttpRequest();
        HttpResponse response = new HttpResponse();
        Http http = new Http();

        // setup the request
        request.setEndpoint('https://logs-01.loggly.com/inputs/'+api_key);
        request.setMethod('POST');
        request.setHeader('Content-Type', 'text/plain');

        // add tags in the header
        request.setHeader('X-LOGGLY-TAG', String.join(tags, ','));

        // put the log message in the body
        request.setBody(data);

        try {
            // send the request to Loggly
            response = http.send(request);
        } catch(System.CalloutException e) {
            System.debug('Loggly error: ' + e);
        }

        System.debug(response.toString());
    }
}

Anonymous Apex Logging

Post a sample message to Loggly.com using this anonymous apex.

List<String> tags = new List<String>{'testTag'};
LogglyService.log('Test Log Message', tags);

The post Loggly.com Logging with Salesforce.com Apex appeared first on Justin Silver.

]]>
https://www.justinsilver.com/technology/salesforce/loggly-com-logging-salesforce-com-apex/feed/ 0