Skip to content

Instantly share code, notes, and snippets.

View RatanPaul's full-sized avatar
💭
I may be slow to respond.

Ratan Paul (http://ratanpaul.github.io/) RatanPaul

💭
I may be slow to respond.
View GitHub Profile
@douglascayers
douglascayers / ApexCsvExample.java
Created January 2, 2017 18:58
Apex CSV Example. Note the use of String.escapeCsv() method
String csv = 'Id,Name\n';
for ( List<Account> accts : [ SELECT id, name FROM Account LIMIT 10 ] ) {
for ( Account acct : accts ) {
csv += acct.id + ',' + acct.name.escapeCsv() + '\n';
}
}
ContentVersion file = new ContentVersion(
title = 'accounts.csv',
versionData = Blob.valueOf( csv ),
@wojteklu
wojteklu / clean_code.md
Last active June 2, 2024 16:09
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

String username='';
String pwd='';
HttpRequest request = new HttpRequest();
request.setEndpoint('https://www.salesforce.com/services/Soap/u/32.0');
request.setMethod('POST');
request.setHeader('Content-Type', 'text/xml;charset=UTF-8');
request.setHeader('SOAPAction', '""');
request.setBody('<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/"><Header/><Body><login xmlns="urn:partner.soap.sforce.com"><username>' + userName+ '</username><password>' + pwd+ '</password></login></Body></Envelope>');
Dom.XmlNode resultElmt = (new Http()).send(request).getBodyDocument().getRootElement()
@jsullivanlive
jsullivanlive / EmailLogic.cls
Created February 8, 2016 22:47
Salesforce Email Merge
public class EmailLogic {
public static String renderTemplate(sObject sobj, String template) {
for (String fieldName : fields(sobj.getSObjectType())) {
String key = '{!' + fieldName + '}';
while (template.containsIgnoreCase(key)) {
try {
Integer foundPosition = template.indexOfIgnoreCase(key, 0);
template = template.left(foundPosition) +
String.valueOf(sobj.get(fieldName)) +
@douglascayers
douglascayers / gist:aa2c3d07560e1cde3df6
Created January 31, 2016 08:26
JQuery Autocomplete Plugin styled with Salesforce Lightning Design System (SLDS) in Visualforce
<apex:page >
<!-- good ol' jquery! -->
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script>$j = jQuery.noConflict();</script>
<!-- the infamous SLDS, aka my nemesis -->
<apex:stylesheet value="{!URLFOR($Resource.SLDS0121,'assets/styles/salesforce-lightning-design-system-vf.css')}"/>
<apex:page standardStylesheets="false" showHeader="false" applyHtmlTag="false" docType="html-5.0">
<html xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<head>
<meta charset="UTF-8" />
<title>Hello React</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/0.13.3/JSXTransformer.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<apex:includeScript value="//cdn.rawgit.com/mattwelch/makeDeferredProvider/master/makeDeferredProvider.min.js"/>
<apex:stylesheet value="//cdn.rawgit.com/mailtoharshit/LightingDesignSystem/master/salesforce-lightning-design-system-v0.8.0/assets/styles/salesforce-lightning-design-system-vf.min.css" />
@sjurgis
sjurgis / salesforce-calendar-view.md
Last active February 5, 2018 08:37
FullCalendar calendar view implementation in Salesforce.com

This is an adaptation of Cody Sechelski's Create a Calendar View in Salesforce.com.

The main problem with his implementation was that it wasn't handling more than 2000 records. This was due to a Apex workaround, as it is reserves start and end variables, Cody made a repeat table and parsed that into JavaScript object. My solution creates JSON string in Apex and then uses string function to replace all startString and endString instances. A more sensible solution would involve recreating the object in JavaScript or simply editing the FullCalendar library to look for different variable names.

I have also simplified the code a bit so you can start working towards your personal implementation. As this is using JavaScript remoting, I hope this gives you a framework to work towards more advanced features like editing or optimizing request sizes (executing a request on next month load).

The page

<apex:page showHeader="fals
@jeffdonthemic
jeffdonthemic / CustomAccountLookup.page
Last active January 12, 2021 15:17
Roll Your Own Salesforce "Lookup" Popup Window blog post
<apex:page controller="CustomAccountLookupController"
title="Search"
showHeader="false"
sideBar="false"
tabStyle="Account"
id="pg">
<apex:form >
<apex:outputPanel id="page" layout="block" style="margin:5px;padding:10px;padding-top:2px;">
<apex:tabPanel switchType="client" selectedTab="name1" id="tabbedPanel">
@kmaida
kmaida / dynamicPagRepeatAngular.html
Last active December 13, 2023 14:37
AngularJS - Dynamic pagination on ng-repeat with search/filtering. Use with ui.bootstrap
<!DOCTYPE HTML>
<html lang="en" ng-app="myApp">
<head>
<meta charset="utf-8">
<title>Dynamic Pagination w/ Filtering</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="Kim Maida">
<!-- JS Libraries -->
@henriquez
henriquez / gist:3146782
Created July 19, 2012 21:00
Example Javascript that uses ajax proxy to make request to Chatter API
<apex:page controller="CustomerCommunityController" id="customercommunitycontroller" sidebar="false" showHeader="false" standardStylesheets="false" >
<head>
<title>Acme Customer Support</title>
<meta charset="utf-8" />
<apex:includeScript value="{!$Resource.jquery}"/>
</head>
<script type="text/javascript">