Skip to content

Instantly share code, notes, and snippets.

View sriniind19's full-sized avatar

Srinu SFDC sriniind19

View GitHub Profile
@sriniind19
sriniind19 / RemoveWhiteSpace
Created November 14, 2017 09:39
To remove the white spaces from a string
public class RemoveWhiteSpace {
public String remvoeWhiteSpaceFromString(String strVal) {
return strVal.deleteWhitespace();
}
}
@sriniind19
sriniind19 / Fibonacci
Last active October 7, 2020 11:22
Fibonacci Series for a given input
public class Fibonacci {
public String getnerateFibbonaci(Integer num) {
String fibobonaciSeries = 'Fibonacci Series: ';
Integer f1 = 0, f2 = 1, nextNum = 0;
for(Integer i=0;i<num;i++) {
nextNum = f1 + f2;
f1 = f2;
f2 = nextNum;
fibobonaciSeries += ', '+String.valueOf(nextNum);
}
@sriniind19
sriniind19 / LeapYear
Created November 14, 2017 10:16
To identify the year is Lead Year or not
public class LeapYear {
public Boolean isLeapYear(Integer year) {
Boolean isTrue = false;
if ( math.mod(year,400) == 0 || math.mod(year,4) == 0)
isTrue = true;
return isTrue;
}
}
@sriniind19
sriniind19 / SwapNumbers
Created November 14, 2017 10:18
Swapping 2 given numbers
public class SwapNumbers {
public void doNumSwapping(Integer a, Integer b) {
a = a + b;
b = a - b;
a = a- b;
system.debug('a value: '+a);
system.debug('b value: '+b);
}
}
@sriniind19
sriniind19 / DynamicSobjectCreation
Created November 14, 2017 10:23
Creating Sobject or List of Sobjects Dynamically
public class DynamicSobjectCreation {
public static SObject createDynamicObject(String objectApiName) {
return (SObject)Type.forName(objectApiName).newInstance();
}
public static List createDynamicList4object(String objectApiName) {
return (List)Type.forName('List<'+objectApiName+'>').newInstance();
}
/*** Usage ***
List recs = DynamicSobjectCreation.createDynamicList4object('Contact');
SObject rec1 = DynamicSobjectCreation.createDynamicObject('Contact');
@sriniind19
sriniind19 / FieldsValidator
Created November 14, 2017 10:33
Sending an email notification to Admin whenever a field is created or deleted for a custom object
global class FieldsValidator implements Database.Batchable<Sobject> {
global Database.queryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator('select name, fields_info__c, fields_count__c from ObjectsExistingFieldsInfo__c');
}
global void execute(Database.BatchableContext bc, List<SObject> sobjLst) {
String[] types = new String[]{'Account','Contact'};
String emailBody = '';
// Make the describe call
Schema.DescribeSobjectResult[] results = Schema.describeSObjects(types);
Map<String,List<Field>> objFieldsDesMap = new Map<String,List<Field>>();
@sriniind19
sriniind19 / Demo_LightningSortableDatatableContrl
Created December 15, 2017 12:56
To retrieve the list of opportunities in a given sorted order
public class Demo_LightningSortableDatatableContrl {
@AuraEnabled
public static List<Sobject> fetchOpps(String sortField, String sortOrder) {
String query = 'select id, name, stagename, amount from Opportunity';
if(String.isNotBlank(sortField) && String.isNotBlank(sortOrder)) {
query += ' order by '+sortField+' '+sortOrder;
}
return Database.query(query);
}
}
@sriniind19
sriniind19 / Demo_LightningSortableDatatable.cmp
Last active December 18, 2017 13:36
To show the table with sorting option for the columns
<aura:component controller="Demo_LightningSortableDatatableContrl">
<aura:attribute name="opportunities" type="list"/>
<aura:attribute name="sortField" type="String" default="Name"/>
<aura:attribute name="sortOrder" type="String" default="Asc"/>
<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<table class="slds-table slds-table_bordered" role="grid">
<thead>
<tr class="slds-line-height_reset">
<th aria-sort="none" class="slds-is-sortable slds-text-title_caps" aria-label="Name" scope="col">
<a class="slds-th__action slds-text-link_reset" href="javascript:void(0);" role="button" tabindex="-1" onclick="{!c.sortColumn}" id="Name" onmouseover="{!c.arrowOnHover}" onmouseout="{!c.arrowOnOut}">
@sriniind19
sriniind19 / Demo_LightningSortableDatatableController.js
Last active December 18, 2017 13:35
js controller for Demo_LightningSortableDatatable.cmp
({
doInit : function(component, event, helper) {
helper.handleDoInit(component, event);
},
sortColumn : function(component, event, helper) {
var target;
if(event.currentTarget.id)
target = event.currentTarget.id;
component.set("v.sortField",target);
if(component.get("v.sortOrder")) {
@sriniind19
sriniind19 / Demo_LightningSortableDatatableHelper.js
Created December 15, 2017 13:03
helper js for Demo_LightningSortableDatatable
({
handleDoInit : function(cmp, event) {
var action = cmp.get("c.fetchOpps");
action.setParams(
{
sortField : cmp.get("v.sortField"),
sortOrder : cmp.get("v.sortOrder")
}
);