Skip to content

Instantly share code, notes, and snippets.

@swapnilshrikhande
swapnilshrikhande / Generic upsertData
Last active November 2, 2017 14:50
Generic Upsert Data
public static Map<String, String> upsertData(Map<String, String> send) {
// Response payload
//
Map<String, String> resp = new Map<String, String> ();
resp.put('__campaign', send.get('__campaign'));
resp.put('__form', send.get('__form'));
// Build a list of fields in the form
//
String[] formFields = selectFormDataFields(true);
@swapnilshrikhande
swapnilshrikhande / Google Translate Element
Created October 17, 2017 16:15
Google Translate Element
<div id="google_translate_element"><div class="skiptranslate goog-te-gadget" dir="ltr" style=""><div id=":0.targetLanguage" class="goog-te-gadget-simple" style="white-space: nowrap;"><img src="https://www.google.com/images/cleardot.gif" class="goog-te-gadget-icon" alt="" style="background-image: url(&quot;https://translate.googleapis.com/translate_static/img/te_ctrl3.gif&quot;); background-position: -65px 0px;"><span style="vertical-align: middle;"><a aria-haspopup="true" class="goog-te-menu-value" href="javascript:void(0)"><span>Select Language</span><img src="https://www.google.com/images/cleardot.gif" alt="" width="1" height="1"><span style="border-left: 1px solid rgb(187, 187, 187);">​</span><img src="https://www.google.com/images/cleardot.gif" alt="" width="1" height="1"><span aria-hidden="true" style="color: rgb(155, 155, 155);">▼</span></a></span></div></div></div><script type="text/javascript">
function googleTranslateElementInit() {
new google.translate.TranslateElement({pageLanguage: 'en', i
@swapnilshrikhande
swapnilshrikhande / ControllerMethods
Created October 17, 2017 14:49 — forked from anonymous/ControllerMethods
Zip Multiple Files
@RemoteAction
public static List<AttachmentWrapper> getAttachedDocsList(String pParentOpportunityId) {
/*
Set<Id> parentDocIdSet = new Set<Id>();
for(Document__c docObj : opp.Documents__r) {
parentDocIdSet.add(docObj.Linked_Document__c);
}
system.debug('>>> parentDocIdSet: '+parentDocIdSet);
*/
@swapnilshrikhande
swapnilshrikhande / QueryGenerator.cls
Created October 15, 2017 15:11 — forked from anonymous/QueryGenerator.cls
Query Generator From FieldList
// Class which contains useful utility methods required across classes
public class Utils {
public static final String OBJECTNAME = 'RELATIONSHIP_OBJECT';
public static final String FIELDNAME = 'RELATIONSHIP_FIELD';
public static final String QUERY_TEMPLATE = 'SELECT {0} FROM {1} {2}';
public static final String NESTED_QUERY = '({0})';
public static final String COMMA_SEPARATOR = ', ';
public static final String FIELD_ID = 'Id';
@swapnilshrikhande
swapnilshrikhande / RESTErrorHandler.cls
Created September 15, 2017 14:38
Rest error handler
public class RESTErrorHandler {
public static final String RESPONSENULL = 'Response null';
public static final String UNKNOWN_ERROR = 'Unknown error';
public static final String SERVER_ERROR = 'Server side error';
public static final String CLIENT_ERROR = 'Client request error';
public static final String REDIRECTION = 'Redirection';
public static final String SUCCESS = 'Success';
public static final String INFO_RESPONSE = 'Informational response';
@swapnilshrikhande
swapnilshrikhande / SObjectClone.cls
Last active September 7, 2017 07:05
Generic SObject Clone Utility
public with sharing class SObjectClone {
public final Map<String, Id> recordTypeMap;
public Map<String,Map<String,String>> relationshipDetailMap;
public Schema.SObjectType objectType;
public Schema.FieldSet fieldSet;
public Set<String> relationshipNameSet;
public CloneInitializer initializer;
public Id cloneRecordTypeId;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.WebElement;
import com.github.webdriverextensions.junitrunner.WebDriverRunner;
import com.github.webdriverextensions.junitrunner.annotations.*;
import static com.github.webdriverextensions.Bot.*;
import static java.util.concurrent.TimeUnit.SECONDS;
@swapnilshrikhande
swapnilshrikhande / GetRecordTypeId.cls
Created August 31, 2017 06:20
Get Record Type ID By Developer Name
// Returns a map of active, user-available RecordType IDs for a given SObjectType,
// keyed by each RecordType's unique, unchanging DeveloperName
public static Map<String, Id> getRecordTypeMapForObjectGeneric(Schema.SObjectType token) {
// Do we already have a result?
Map<String, Id> mapRecordTypes = rtypesCache.get(token);
// If not, build a map of RecordTypeIds keyed by DeveloperName
if (mapRecordTypes == null) {
mapRecordTypes = new Map<String, Id>();
rtypesCache.put(token,mapRecordTypes);
} else {
@swapnilshrikhande
swapnilshrikhande / OpportunityClone.cls
Last active August 24, 2017 09:08
Generic SOQL Query Generator and other utility methods
public class OpportunityClone {
//get recordtypeids for all opportunity records
static final Map<String, Id> opportunityRecordTypeMap = Utils.getRecordTypeMapForObjectGeneric(Opportunity.SObjectType);
static final Map<String,Map<String,String>> opportunityRelationshipDetailMap = Utils.getRelationshipDetails(Opportunity.SObjectType);
public static final String FILTER_CLAUSE = ' WHERE ID IN :recordIdList';
public static CloneConfig config;
public class CloneConfig {
@swapnilshrikhande
swapnilshrikhande / PdfGenerator.page
Last active January 6, 2020 13:19
Generating and zipping pdf from a visualforce page (salesforce)
<apex:page renderAs="pdf">
PDF Content Goes Here...
</apex:page>