Skip to content

Instantly share code, notes, and snippets.

View zokito's full-sized avatar

Zoran Zunko zokito

  • H.D.B.-Soft
  • Croatia
View GitHub Profile
@zokito
zokito / streamingNotifications.html
Created May 7, 2019 17:50 — forked from abhinavguptas/streamingNotifications.html
Force.com Streaming API Chrome Desktop Notifications
<apex:page sidebar="false" tabStyle="Account">
<apex:includeScript value="{!URLFOR($Resource.comet, 'cometd.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.comet, 'jquery-1.5.1.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.comet, 'jquery.cometd.js')}"/>
<apex:includeScript value="{!URLFOR($Resource.comet, 'json2.js')}"/>
<style type="text/css">
#chatterNotificationPanel {
display: none;
}
@zokito
zokito / ExampleRemoteSiteSettingDeploy.page.xml
Created September 10, 2018 09:05
JavaScript Remote Site Setting deployment
<apex:page>
<c:RemoteSiteSetting>
<!--
! Need to hit Salesforce APIs from inside Visualforce or Apex?
!
! Put those features here. If the Remote Site Setting is
! present, your components will be rendered normally.
!
! If the Remote Site Setting is absent, instead the page
@zokito
zokito / gist:75ee630dd531ffce8085b278bf092312
Created August 11, 2016 22:36 — forked from boxfoot/getDependentPicklists.cls (2017 approach)
Handle cases where one dependent option can be used for multiple controlling options
/**
* getDependentPicklistOptions
* by Benj Kamm, 2012
* (inspired by http://iwritecrappycode.wordpress.com/2012/02/23/dependent-picklists-in-salesforce-without-metadata-api-or-visualforce/)
* CC BY-SA 3.0 (http://creativecommons.org/licenses/by-sa/3.0/us/)
*
* Build an Object in which keys are valid options for the controlling field
* and values are lists of valid options for the dependent field.
*
* Method: dependent PickListEntry.validFor provides a base64 encoded

Custom Page Message Framework

This framework gives you a way to exert control over style when providing confirm/info/error/warn messages to your users in Visualforce pages, because let's face it: the default styles are not that pretty/easy to bring into line with a Client's style, particularly when being used in a Portal (I haven't personally worked on any clients using Communities yet, so can't comment on the aesthetics there!).

This framework is pretty simple and self-contained, including 100% test coverage for each class. The only things you need to bring to the party are Bootstrap css and js, and some very minor alterations to your controller and page files, which can be easily done with a quick find/replace or two.

Dependencies

Bootstrap css file : Optional, but strongly recommended unless you need to roll your own style
Bootstrap js file : Optional, but required if you want your messages to be dismissable
public static Map<String, String> ISO3166_1_Alpha2_CountryToCode = new Map<String,String> {
'AFGHANISTAN'=>'AF',
'ÅLAND ISLANDS'=>'AX',
'ALBANIA'=>'AL',
'ALGERIA'=>'DZ',
'AMERICAN SAMOA'=>'AS',
'ANDORRA'=>'AD',
'ANGOLA'=>'AO',
'ANGUILLA'=>'AI',
'ANTARCTICA'=>'AQ',
<apex:dataTable value="{!accounts}" var="account" id="theTable">
<apex:facet name="caption">table caption</apex:facet>
<apex:facet name="header">table header</apex:facet>
<apex:facet name="footer">table footer</apex:facet>
<apex:column>
<apex:facet name="header">Name</apex:facet>
<apex:facet name="footer">column footer</apex:facet>
<apex:outputText value="{!account.name}"/>
</apex:column>
<apex:column>
<apex:page controller="MyJSController">
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script type="text/javascript">
$(function() {
global class RemoteController {
@RemoteAction
global static String test0Str(){
return '0 arguments';
}
@RemoteAction
global static String test1Str(String str){
return str;
When looping through a set of Salesforce.com SObjects from a VisualForce page, you may want to test whether the SObject has any children without wrapping the SObjects in a wrapper class. Here's how:
Controller:
Create a property in the controller that is a map of the parent IDs and Boolean flag.
public Map<Id, Boolean> hasChildren {
get {
if (this.hasChildren == null) {
for (Parent__c parent : [select id, (select id from children__r) from parent__c]) {
if (parent.children__r.size() > 0) {
@zokito
zokito / page message
Last active December 26, 2015 07:29
apex page add message
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.INFO,''));
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,''));
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.ERROR,''));
ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,''));