Skip to content

Instantly share code, notes, and snippets.

View mannharleen's full-sized avatar
👽

Harleen Mann mannharleen

👽
View GitHub Profile
@mannharleen
mannharleen / AccountManager.cls
Last active November 24, 2022 10:00
Salesforce trailhead - Apex-Integration-Services-Apex-Web-Services
@RestResource(urlMapping='/Accounts/*/contacts')
global with sharing class AccountManager {
@HttpGet
global static account getAccount() {
RestRequest request = RestContext.request;
String accountId = request.requestURI.substring(request.requestURI.lastIndexOf('/')-18,
@mannharleen
mannharleen / ocrv1
Created October 31, 2016 14:46
Use RESTfull webservice from ocrwebservice.com to get a document scanned and converted into text
public class ocrv1 {
//read file contents, sent to http://www.ocrwebservice.com/api/restguide and get ocr response
public static void func1() {
StaticResource sr = [SELECT Id, name, Body FROM StaticResource where name = 'Simple_Survey_Intro' LIMIT 1];
String b64String = EncodingUtil.base64Encode(sr.Body);
String hexString = EncodingUtil.convertToHex(sr.Body);
system.debug('\n b64= '+b64String +'\n hex= '+hexString);
Http http = new Http();
@mannharleen
mannharleen / AccountProcessor.cls
Created October 31, 2016 15:32
Salesforce trailhead - Asynchronous Apex Using Future Methods
public class AccountProcessor {
@future
public static void countContacts(List<Id> accountId_lst) {
Map<Id,Integer> account_cno = new Map<Id,Integer>();
List<account> account_lst_all = new List<account>([select id, (select id from contacts) from account]);
for(account a:account_lst_all) {
account_cno.put(a.id,a.contacts.size()); //populate the map
@mannharleen
mannharleen / AnimalLocator.cls
Created October 31, 2016 15:36
Salesforce trailhead - Apex-Integration-Services-Apex-REST-Callouts
public class AnimalLocator {
public class cls_animal {
public Integer id;
public String name;
public String eats;
public String says;
}
public class JSONOutput{
public cls_animal animal;
@mannharleen
mannharleen / oauthv2
Last active April 4, 2020 17:52
Access Uber API from Salesforce: Contains complete OAuth framework programmed.
<apex:page controller="oauthv2Controller">
<apex:form >
<apex:actionFunction name="getInfo" action="{!info}" />
<apex:commandButton value="Get info" action="{!info}"/> <br/>
</apex:form>
<script>
@mannharleen
mannharleen / batchclass1.cls
Created November 1, 2016 03:00
Batch class with test to update all accounts in the org. Uses database.getquerylocator();
global class batchclass1 implements Database.Batchable<sobject>,Database.Stateful {
global integer count = 0;
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator('select id,name from account');
}
global void execute(Database.BatchableContext bc,List<account> acc_lst) {
List<account> acc_update_lst = new List<account>();
for(account a: acc_lst) {
@mannharleen
mannharleen / LeadProcessor.cls
Created November 1, 2016 04:12
Salesforce trailhead - Asynchronous Apex Using Batch Apex: The code creates a batch class to update lead object
global class LeadProcessor implements Database.Batchable<sObject> {
global Integer count = 0;
global Database.QueryLocator start (Database.BatchableContext bc) {
return Database.getQueryLocator('Select Id, LeadSource from lead');
}
global void execute (Database.BatchableContext bc,List<Lead> l_lst) {
List<lead> l_lst_new = new List<lead>();
for(lead l : l_lst) {
@mannharleen
mannharleen / importDataFromCSV
Last active November 7, 2018 16:14
Wrapper class and CSV file upload
<apex:page controller="importDataFromCSVController_mann">
<apex:form >
<apex:pagemessages />
<apex:pageBlock >
<apex:pageBlockSection columns="4">
<apex:inputFile value="{!csvFileBody}" filename="{!csvAsString}"/>
<apex:commandButton value="Import Account" action="{!importCSVFile}"/>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock >
@mannharleen
mannharleen / AddPrimaryContact.cls
Created November 2, 2016 15:46
Salesforce trailhead - Asynchronous Apex Controlling Processes with Queueable Apex
public class AddPrimaryContact implements Queueable {
public contact c;
public String state;
public AddPrimaryContact(Contact c, String state) {
this.c = c;
this.state = state;
}
public void execute(QueueableContext qc) {
@mannharleen
mannharleen / DailyLeadProcessor.cls
Created November 3, 2016 15:00
Salesforce trailhead - Asynchronous Apex Scheduling Jobs Using the Apex Scheduler
public class DailyLeadProcessor implements schedulable{
public void execute(schedulableContext sc) {
List<lead> l_lst_new = new List<lead>();
List<lead> l_lst = new List<lead>([select id, leadsource from lead where leadsource = null]);
for(lead l : l_lst) {
l.leadsource = 'Dreamforce';
l_lst_new.add(l);
}
update l_lst_new;