Skip to content

Instantly share code, notes, and snippets.

View douglascayers's full-sized avatar

Doug Ayers douglascayers

View GitHub Profile
@douglascayers
douglascayers / jQueryDatePickerComponent.html
Last active November 6, 2017 00:42
Using jQuery UI Date Picker in Lightning Component as of Winter '17 with LockerService activated
<aura:component>
<ltng:require scripts="{!join(',', $Resource.jquery_2_2_4_js, $Resource.jquery_ui_1_12_1 + '/jquery-ui.min.js')}"
afterScriptsLoaded="{!c.afterScriptsLoaded}"/>
<ltng:require styles="{!$Resource.jquery_ui_1_12_1 + '/jquery-ui.min.css'}"/>
<p>
Start Date: <input aura:id="startDate" type="text" onfocus="{!c.initDatePicker}"/>
</p>
@douglascayers
douglascayers / ModalDialog.cmp
Created November 16, 2016 21:57
DEV601: Exercise 5.1 alternative solution to closing modal dialog. Note line 14 in .cmp which wraps the original solution. Controller adds 'slds-hide' class without us needing to define our own *.style resource.
<aura:component>
<aura:attribute name="title" type="String" required="true" />
<aura:attribute name="closeable" type="Boolean" default="true"/>
<aura:attribute name="closeLabel" type="String" default="Close"/>
<aura:attribute name="cancelLabel" type="String" default="Cancel"/>
<aura:attribute name="confirmLabel" type="String" default="OK"/>
<aura:attribute name="onclose" type="Aura.Action" default="{!c.defaultCloseAction}"/>
@douglascayers
douglascayers / controller.js
Last active February 27, 2020 03:56
Lightning Component helper js methods for invoking apex methods
({
someMethod : function( component, event, helper ) {
var helper = this;
helper.callAction( component, 'c.someApexMethod', {
'someParam' : component.get( 'v.someAttribute' )
}).then( $A.getCallback( function( data ) {
@douglascayers
douglascayers / JavaScriptButton.js
Created November 9, 2016 23:08
Salesforce custom JavaScript button example that updates record and displays errors.
{!REQUIRESCRIPT("/soap/ajax/27.0/connection.js")}
try {
var formToUpdate = new sforce.SObject( "Company_Form_Opp__c" );
formToUpdate.id = "{!Company_Form_Opp__c.Id}";
// ... snip ...
@douglascayers
douglascayers / EmailQuickActionDefaultsHandler.java
Created November 4, 2016 20:45
Apex class to auto-default values of Email when using Case Feed Email Composer. Setup | Case | Support Settings
/**
* https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_interface_QuickAction_QuickActionDefaultsHandler.htm
*/
public class EmailQuickActionDefaultsHandler implements QuickAction.QuickActionDefaultsHandler {
public void onInitDefaults( QuickAction.QuickActionDefaults[] actionDefaults ) {
for ( QuickAction.QuickActionDefaults actionDefault : actionDefaults ) {
System.debug( actionDefault );
@douglascayers
douglascayers / VisualforceReportChartsComponent.html
Created August 24, 2016 14:13
Example of embedding analytics:reportChart in visualforce and making when the user clicks the chart that it takes user to the report, not load report nested in the iframe.
<apex:component >
<!--
Visualforce pages added to page layouts are embedded via iframes.
That means the default link behavior of content in the iframe (aka, this page)
loads within that iframe rather than changing the browser's actual address bar.
We want when the users click the report charts that the entire page redirects
to the report chart rather than simply loading the report data in the iframe.
@douglascayers
douglascayers / RedirectPage.html
Last active August 11, 2016 03:33
Visualforce page that uses javascript page redirection. In response to https://success.salesforce.com/0D53A00002oy3pv
<apex:page showHeader="false" showChat="false" sidebar="false" standardStylesheets="false">
<script type="text/javascript">
// URL must be prefixed with http:// or https://
// otherwise it will be considered a relative URL in your Salesforce instance
// e.g. https://<your_instance>.visual.force.com/apex/www.google.com
window.location = 'https://www.google.com';
</script>
</apex:page>
@douglascayers
douglascayers / ApexTestUserUtils.java
Last active June 18, 2016 05:00
Apex Test function for creating new users.
@isTest
private class MyTestClass {
@isTest
static void test_something() {
Profile p = [ SELECT id FROM Profile WHERE name = 'Standard User' ];
User user1, user2;
@douglascayers
douglascayers / LeadConvertedViewController.java
Created June 4, 2016 19:41
Simple Visualforce template for displaying converted lead records. Once a lead is converted the standard detail page is no longer accessible, must use reports or visualforce.
/**
* https://twitter.com/Joy_SH/status/738087166547398656
* https://help.salesforce.com/apex/HTViewSolution?id=000175908&language=en_US
*/
public with sharing class LeadConvertedViewController {
public Lead record { get; private set; }
public LeadConvertedViewController( ApexPages.StandardController stdController ) {
this.record = (Lead) queryRecord( stdController.getId() );
@douglascayers
douglascayers / RedirectApexController.java
Created May 9, 2016 20:58
Removing the CSRF _CONFIRMATIONTOKEN from page request when passing all parameters to next redirect page. This began causing me issues in Summer '16 release: https://success.salesforce.com/issues_view?id=a1p3A000000jknNQAQ
public class RedirectApexController {
public RedirectApexController( ApexPages.StandardController stdController ) {}
public PageReference redirect() {
// ... do some logic to determine where to redirect to ...
PageReference page = new PageReference('/apex/MyPage');
// pass any parameters that came in on request on to the final destination