├── ApexTransactionExample ├── CaseManager ├── README.md ├── TaskUtility ├── TaskUtilityTest ├── TemperatureConvertor ├── TemperatureConvertorTest ├── UpdateContactAddInfo ├── UpdateContactAddress ├── WinningStageTrigger ├── changeProductCode ├── oppoNe └── paginationExample /ApexTransactionExample: -------------------------------------------------------------------------------- 1 | public class ApexTransactionExample { 2 | public static void insertLeadAndAccount(String accName,String LeadName,String LeadCompany) 3 | { 4 | Account a=new Account(Name=accName); 5 | insert a; 6 | Lead l1=new Lead(LastName=LeadName,Company=LeadCompany); 7 | insert l1; 8 | Lead l2=new Lead(LastName=LeadName,Company='MyTutorialRack'); 9 | insert l2; 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /CaseManager: -------------------------------------------------------------------------------- 1 | @RestResource(urlMapping='/Cases/*') 2 | global with sharing class CaseManager { 3 | @HttpGet 4 | global static Case getCaseById(){ 5 | RestRequest request=RestContext.request; 6 | String caseId= request.requestURI.substring(request.requestURI.lastIndexOf('/')+1); 7 | Case result= [Select CaseNumber,Subject,Status,Origin,Priority From Case where Id=:caseId]; 8 | return result; 9 | } 10 | 11 | @HttpPost 12 | global static Id createCase(String subj,String sta,String ori,String pri) 13 | { 14 | Case thisCase=new Case(Subject=subj,Status=sta,Origin=ori,Priority=pri); 15 | insert thisCase; 16 | return thisCase.Id; 17 | } 18 | 19 | @HttpDelete 20 | global static void deleteCase() 21 | { 22 | RestRequest request=RestContext.request; 23 | String caseId= request.requestURI.substring(request.requestURI.lastIndexOf('/')+1); 24 | Case thisCase=[Select Id from Case where id=:caseId]; 25 | delete thisCase; 26 | } 27 | 28 | @HttpPut 29 | global static ID upsertCase(String sub,String sta,String ori,String pri,String id) 30 | { 31 | Case thisCase=new Case(Id=id,Subject=sub,status=sta,origin=ori,priority=pri); 32 | upsert thisCase; 33 | return thisCase.Id; 34 | } 35 | 36 | @HttpPatch 37 | global static ID updateCaseFields() 38 | { 39 | RestRequest request=RestContext.request; 40 | String caseId= request.requestURI.substring(request.requestURI.lastIndexOf('/')+1); 41 | Case thisCase=[select Id from case where Id=:caseId]; 42 | Map params= ( Map)JSON.deserializeUntyped(request.requestBody.toString()); 43 | for(String fieldName:params.keySet()) 44 | { 45 | thisCase.put(fieldName,params.get(fieldName)); 46 | } 47 | update thisCase; 48 | return thisCase.Id; 49 | } 50 | 51 | 52 | 53 | 54 | } 55 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SalesforceInterviewMyTutorialRack 2 | -------------------------------------------------------------------------------- /TaskUtility: -------------------------------------------------------------------------------- 1 | public class TaskUtility 2 | { 3 | public static String getTaskPriority(String leadCountry) 4 | { 5 | if(String.isBlank(leadCountry)||leadCountry.length()>2) 6 | { 7 | return null; 8 | 9 | } 10 | String taskPriority; 11 | if(leadCountry=='US') 12 | { 13 | taskPriority='High'; 14 | 15 | } 16 | else 17 | { 18 | taskPriority='Normal'; 19 | } 20 | return taskPriority; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /TaskUtilityTest: -------------------------------------------------------------------------------- 1 | @isTest 2 | public class TaskUtilityTest 3 | { 4 | @isTest static void testGetTaskPriority() 5 | { 6 | String priority=TaskUtility.getTaskPriority('AU'); 7 | System.assertEquals('Normal', priority); 8 | } 9 | @isTest static void testTaskHighPriority() 10 | { 11 | String priority=TaskUtility.getTaskPriority('US'); 12 | System.assertEquals('High', priority); 13 | } 14 | @isTest static void testTaskPriorityInvalid() 15 | { 16 | String priority=TaskUtility.getTaskPriority('idfdf'); 17 | System.assertEquals(null, priority); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /TemperatureConvertor: -------------------------------------------------------------------------------- 1 | public class TemperatureConvertor 2 | { 3 | public static Decimal FahrenheitToCelsius(Decimal fh) 4 | { 5 | Decimal cs=(fh-32)*5/9; 6 | System.debug('temperature in Celsius='+cs.setScale(2)); 7 | return cs.setScale(2); 8 | } 9 | 10 | 11 | } 12 | -------------------------------------------------------------------------------- /TemperatureConvertorTest: -------------------------------------------------------------------------------- 1 | @isTest 2 | public class TemperatureConvertorTest { 3 | 4 | @isTest static void testWarmTemp() 5 | { 6 | Decimal celsius=TemperatureConvertor.FahrenheitToCelsius(70); 7 | System.assertEquals(21.11, celsius); 8 | } 9 | 10 | @isTest static void testFreezingPoint() 11 | { 12 | Decimal celsius=TemperatureConvertor.FahrenheitToCelsius(32); 13 | System.assertEquals(0,celsius); 14 | } 15 | 16 | @isTest static void testBoilingPoint() 17 | { 18 | Decimal celsius=TemperatureConvertor.FahrenheitToCelsius(212); 19 | System.assertEquals(100,celsius,'Boiling point temperature is not expected '); 20 | 21 | } 22 | 23 | @isTest static void testNegativeTemp() 24 | { 25 | Decimal celsius=TemperatureConvertor.FahrenheitToCelsius(-10); 26 | System.assertEquals(-23.33,celsius); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /UpdateContactAddInfo: -------------------------------------------------------------------------------- 1 | global class UpdateContactAddInfo implements Database.Batchable 2 | { 3 | global Database.QueryLocator start(Database.BatchableContext bc) 4 | { 5 | return Database.getQueryLocator( 6 | 'SELECT ID, BillingStreet, BillingCity, BillingState, ' + 7 | 'BillingPostalCode, (SELECT ID, MailingStreet, MailingCity, ' + 8 | 'MailingState, MailingPostalCode FROM Contacts) FROM Account ' + 9 | 'Where BillingState = \'TX\'' 10 | ); 11 | } 12 | global void execute(Database.BatchableContext bc,List scope) 13 | { 14 | List contacts=new List(); 15 | for(Account account:scope) 16 | { 17 | for(Contact contact:account.contacts) 18 | { 19 | contact.MailingStreet=account.BillingStreet; 20 | contact.MailingCity=account.BillingCity; 21 | contact.MailingState=account.BillingState; 22 | contact.MailingPostalCode=account.BillingPostalCode; 23 | contacts.add(contact); 24 | 25 | } 26 | } 27 | update contacts; 28 | 29 | } 30 | global void finish(Database.BatchableContext bc) 31 | { 32 | 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /UpdateContactAddress: -------------------------------------------------------------------------------- 1 | global class UpdateContactAddress implements Database.Batchable{ 2 | 3 | global Database.QueryLocator start(Database.BatchableContext bc) 4 | { 5 | return Database.getQueryLocator( 6 | 'SELECT ID,BillingStreet,BillingCity,BillingState,'+ 7 | 'BillingPostalCode,(Select id,MailingStreet,MailingCIty,'+ 8 | 'MillingState,MailingPostalCode from Contacts) From Account'+ 9 | 'Where BillingState=\'CA\'' 10 | ); 11 | 12 | 13 | } 14 | global void execute(Database.BatchableContext bc,List scope) 15 | { 16 | List contacts=new List(); 17 | for(Account account:scope){ 18 | for(Contact contact: account.contacts) 19 | { 20 | contact.MailingStreet=account.BillingStreet; 21 | contact.MailingCity=account.BillingCity; 22 | contact.MailingState=account.BillingState; 23 | contact.MailingPostalCode=account.BillingPostalCode; 24 | contacts.add(contact); 25 | } 26 | } 27 | update contacts; 28 | } 29 | global void finish(Database.BatchableContext bc) 30 | { 31 | 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /WinningStageTrigger: -------------------------------------------------------------------------------- 1 | trigger WinningStageTrigger on Opportunity (before Update) 2 | { 3 | for(Opportunity opp:Trigger.new) 4 | { 5 | Opportunity oldOpp=Trigger.OldMap.get(opp.Id); 6 | Boolean oldOppIsWon=oldOpp.StageName.equals('Closed Won'); 7 | Boolean newOppisWon= opp.StageName.equals('Closed Won'); 8 | if(!oldOppIsWon && newOppisWon) 9 | { 10 | opp.Is_Value_Correct__c=true; 11 | } 12 | 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /changeProductCode: -------------------------------------------------------------------------------- 1 | trigger changeProductCode on Product2 (before insert) { 2 | List productList=trigger.new;//newer version of the records 3 | for(product2 pro:productList) 4 | { 5 | if(pro.productCode!=null && pro.productCode!='') 6 | { 7 | pro.productCode='XYZ-'+pro.productCode; 8 | } 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /oppoNe: -------------------------------------------------------------------------------- 1 | public class oppoNe { 2 | 3 | public oppoNe(ApexPages.StandardSetController controller) { 4 | controller.setPageSize(10); 5 | } 6 | 7 | } 8 | -------------------------------------------------------------------------------- /paginationExample: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | {!opp.Name} 7 | 8 | 9 | 10 | 11 | FIRST 12 | NEXT 13 | PREVIOUS 14 | LAST 15 | 16 | 17 | 18 | 19 | 20 | --------------------------------------------------------------------------------