Skip to content

Instantly share code, notes, and snippets.

View msrivastav13's full-sized avatar
🎯
Focusing

Mohith Shrivastava msrivastav13

🎯
Focusing
View GitHub Profile
@msrivastav13
msrivastav13 / ApexMetadataUtility
Last active April 9, 2017 01:00
Metadata Wrapper over apex metadata
public with sharing class ApexMetadataUtility {
/**
* Call apex controller method fetch metadata
* @param
* @return void
*/
@AuraEnabled
public static list<SobjectMetadataWrapper> getSobjectMetadata(String[] sobjectarray){
list<SobjectMetadataWrapper> lstsobjectMetadata = new list<SobjectMetadataWrapper>();
@msrivastav13
msrivastav13 / StandardDeviationComputation
Created March 21, 2017 00:38
Simple apex Utility to calculate Standard Deviation
public with sharing class StandardDeviationComputation {
public static decimal getStandardDeviation(Integer precision){
AggregateResult[] groupedResults = [SELECT COUNT(Id),SUM(DistanceSquare__c) FROM Survey__c GROUP BY Standard_Deviation__c ];
decimal sumOfDistanceSquare = (decimal)groupedResults[0].get('expr1');
integer count = (integer)groupedResults[0].get('expr0');
if(count > 0){
return system.Math.sqrt(sumOfDistanceSquare/count).setScale(precision);//Scale is kept at 3 currently
}else{
return 0;
}
@msrivastav13
msrivastav13 / ContactList.Controller
Last active November 21, 2016 04:51
Fetching Contacts Via Lightning Component
({
fetchContactList : function(component, event, helper) {
var action = component.get("c.getContacts");
action.setCallback(this, function(response) {
var state = response.getState();
if (component.isValid() && state === "SUCCESS") {
component.set("v.contacts", response.getReturnValue());
}
});
$A.enqueueAction(action);
public with sharing class AccountTest{
@AuraEnabled
public static list<AccountWrapper> getlstacc(){
list<AccountWrapper> lstWrapper = new list<AccountWrapper>();
for(Account acc :[Select Id , Name , NumberofLocations__c from Account order by NumberofLocations__c limit 10]){
AccountWrapper accWrap = new AccountWrapper();
accWrap.Name = acc.Name;
accWrap.noOfLocations = integer.valueof(acc.NumberofLocations__c);
lstWrapper.add(accWrap);
@msrivastav13
msrivastav13 / AccountTest.cls
Last active August 14, 2016 05:07
Simple class to fetch data from SFDC Account Table
public with sharing class AccountTest{
@AuraEnabled
public static list<Account> getlstacc(){
return [Select Id , Name , NumberofLocations__c from Account order by NumberofLocations__c limit 10];
}
}
@msrivastav13
msrivastav13 / DataWrapper.cls
Last active August 3, 2016 21:04
LeadHeat Map Controller
public with sharing class DataWrapper {
public integer zoomLevel {get;set;}
public decimal scale {get;set;}
public string title {get;set;}
public decimal latitude {get;set;}
public decimal longitude {get;set;}
public string url {get;set;}
public DataWrapper (integer zoomLevel,decimal scale,
@msrivastav13
msrivastav13 / TopicNavigationHelper.js
Created March 31, 2016 00:54
This shows how to work through navigation and encode the Topic Search String
if (component.isValid() && state === "SUCCESS") {
for (i = 0; i < response.getReturnValue().length; i++) {
var topic = {};
topic = { 'sobjectType': 'Topic','Name': '' ,'Id' :'','Label' :''};
topic.Name = encodeURIComponent(response.getReturnValue()[i].Name);
topic.Label = response.getReturnValue()[i].Name;
topic.Id = response.getReturnValue()[i].Id;
topicslst.push(topic);
}
console.log('TOPICS..'+topicslst);
@msrivastav13
msrivastav13 / home.ejs
Created March 29, 2016 17:19
Home page for our app with lightning Out
<!DOCTYPE html>
<html lang="en">
<head>
<% include ../partials/ldOut %>
</head>
<body class="slds">
<header>
</header>
<main>
<div >
@msrivastav13
msrivastav13 / app.js
Created March 29, 2016 17:09
A app.js file for the node process
ar nforce = require('nforce');
var express = require('express');
var port = process.env.PORT || 3000;
var org = nforce.createConnection({
clientId: '3MVG9uudbyLbNPZMk0vYn7ICarLW4qV5bLdL.KqYws.i1.oN99y14Skth6utXg0nwCuPpSMtr9lB7HIOx6M65',
clientSecret: '6326007125179395206',
redirectUri: 'https://protected-fortress-46904.herokuapp.com/oauth/_callback',
apiVersion: 'v34.0', // optional, defaults to current salesforce API version
environment: 'production', // optional, salesforce 'sandbox' or 'production', production default
@msrivastav13
msrivastav13 / ContactSupport.cmp
Last active March 24, 2016 21:14
Lightning Component For Contact Support Button
<aura:component implements="forceCommunity:availableForAllPageTypes">
<aura:attribute name="supportURL" type="string" default="/s/contactsupport"/>
<ui:button aura:id="button" buttonTitle="Contact Support" label="Contact Support" press="{!c.navigate}" class="uiButton forceCommunityAskCommunity"/>
</aura:component>