Saturday, June 15, 2019

Automate Record Creation

Unit : Automate Record Creation

👉Install the unmanaged package for the schema and stubs for Apex classes and triggers. 
👉Rename cases and products to match the HowWeRoll schema, and assign all profiles to the custom HowWeRoll page layouts for those objects. 
👉Use the included package content to automatically create a Routine Maintenance request every time a maintenance request of type Repair or Routine Maintenance is updated to Closed.
👉Follow the specifications and naming conventions outlined in the business requirements.
#Apex Trigger
 trigger MaintenanceRequest on Case (after update) {  
   MaintenanceRequestHelper.updateWorkOrders();  
 }
#Apex Class
 public class MaintenanceRequestHelper {  
     public static void updateWorkOrders(){  
     Map<Id, Case> mantnceReqToEvaluate = new Map<Id, Case>();  
     for(Case mantnceReq : (List<Case>)Trigger.new){  
       if((mantnceReq.Type.contains('Repair') || mantnceReq.Type.contains('Routine Maintenance')) && mantnceReq.Status == 'Closed'){  
         mantnceReqToEvaluate.put(mantnceReq.Id,mantnceReq);  
       }  
     }  
         Map<Id, decimal> mapOfProdIdWithMaintenanceCycle = getMapOfProdIdWithMaintenanceCycle();  
         List<Case> lstOfMaintenanceRoutines = getListOfMaintenanceRoutineList(mantnceReqToEvaluate, mapOfProdIdWithMaintenanceCycle);  
     System.debug('lstOfMaintenanceRoutines :::::::: '+lstOfMaintenanceRoutines);  
     if(lstOfMaintenanceRoutines != null && lstOfMaintenanceRoutines.size() > 0)  
       INSERT lstOfMaintenanceRoutines;  
   }  
     private static Map<Id, decimal> getMapOfProdIdWithMaintenanceCycle(){  
     Map<Id,decimal> mapOfProdIdWithMaintenanceCycle = new Map<Id, decimal>();  
     for(Product2 prod : [SELECT Id, Maintenance_Cycle__c from Product2]){  
       mapOfProdIdWithMaintenanceCycle.put(prod.Id, prod.Maintenance_Cycle__c);  
     }  
         return mapOfProdIdWithMaintenanceCycle;  
   }  
   private static List<Case> getListOfMaintenanceRoutineList(Map<Id, Case> mantnceReqToEvaluate, Map<Id, decimal> mapOfProdIdWithMaintenanceCycle){  
     List<Case> lstOfMaintenanceRoutines = new List<Case>();  
       for(Case maintenance : mantnceReqToEvaluate.values()){  
       Case maintenanceNewIns = new Case();  
       maintenanceNewIns.Vehicle__c = maintenance.Vehicle__c;  
       maintenanceNewIns.Equipment__c = maintenance.Equipment__c;  
       maintenanceNewIns.Type = 'Routine Maintenance';  
       maintenanceNewIns.Subject = 'Your Routine Maintenance Schedule';  
       maintenanceNewIns.Date_Reported__c = Date.today();  
       maintenanceNewIns.Date_Due__c = getDueDate(maintenance, mapOfProdIdWithMaintenanceCycle);  
       maintenanceNewIns.Status = 'New';  
       maintenanceNewIns.Origin = 'Phone';  
       lstOfMaintenanceRoutines.add(maintenanceNewIns);  
     }  
     return lstOfMaintenanceRoutines;    
   }  
   private static Date getDueDate(Case maintenance, Map<Id, decimal> mapOfProdIdWithMaintenanceCycle){  
     Date dt = null;  
     if (mapOfProdIdWithMaintenanceCycle.get(maintenance.Equipment__c) != null) {  
       dt = Date.today().addDays(Integer.valueOf(mapOfProdIdWithMaintenanceCycle.get(maintenance.Equipment__c)));  
     }  
     return dt;  
   }  
 }  

Monday, April 29, 2019

Platform Developer I Certification Maintenance (Spring '19)

Unit : Platform Developer I Certification Maintenance (Spring '19)

UNIT : Learn What’s New for Platform Developers in Spring ’19:-

1. Which Apex interface can be implemented to allow My Domain users to log in with something other than their username and password?
A. Auth.AuthToken

B. Auth.VerificationMethod
C. Auth.LoginDiscoveryHandler
D. Auth.MyDomainLoginDiscoveryHandler

2. With Spring '19, which method returns a list of OrgLimit instances used to investigate limits and their names, current value, and maximum value?
A. getAll() from the System.OrgLimit Class
B. getAll() from the System.OrgLimits Class
C. getInstances() from the System.OrgLimit Class
D. getInstances() from the System.OrgLimits Class

3. With Spring '19, which properties of an unhandled Apex exception are available in Event Monitoring log files?
A. Static variable state and stack trace
B. Exception type, name, and static variable state
C. Stack trace, user's location, and exception type
D. Exception message, exception type name, and stack trace

4. Which field of the SandboxInfo object is a reference to the ID of the SandboxInfo that served as the source org for a cloned sandbox?
A. SourceId
B. TemplateId
C. SandboxName
D. SandboxInfoId

5. You created a custom metadata type to handle your company's warranty policy. The custom metadata type's label is WarrantyRule. For it, you created a custom field labeled Warranty and a metadata record labeled Gold. What is the correct syntax to reference the value stored in the Gold metadata record?
A. $WarrantyRule.Gold.Warranty__c
B. $WarrantyRule__mdt.Gold.Warranty
C. $CustomMetadata.WarrantyRule.Gold.Warranty
D. $CustomMetadata.WarrantyRule__mdt.Gold.Warranty__c

Get Ready for the Hands-on Challenge:-


In the hands-on challenge below, you’ll have an opportunity to work with these new security settings and use the new WITH SECURITY_ENFORCED clause in SOQL queries run from Apex to simplify your code. But before we get started, a bit of setup is required. 


Our business goal is to ensure that only system administrators have access to sensitive customer information, and that other users cannot invoke our APIs that handle sensitive data. To ensure that our code is generally safe, we need to make runtime checks of field- and object-level security. As developers, we need to specifically ensure our code respects admin-defined security constraints.

Launch the org you’ll use for the hands-on challenge, then do the following.

Create a new custom field on the Contact object to establish a field that contains sensitive information about the secret keys of our customers.
Field Label: Secret Key
Type: Text
Field Name: Secret_Key
 @RestResource(urlMapping='/secureApexRest')  
 global with sharing class SecureApexRest {  
   @HttpGet  
   global static Contact doGet(){  
     Id recordId = RestContext.request.params.get('id');  
     Contact result;  
     List<Contact> results = [SELECT id, Name, Secret_Key__c FROM Contact WHERE Id = :recordId WITH SECURITY_ENFORCED];  
     if (!results.isEmpty()) {  
        result = results[0];  
      }  
      else{  
       throw new QueryException('You don\'t have access to all contact fields required to use this API');  
     }  
     return result;  
   }  
    public class QueryException extends Exception{}  
 }  

Sunday, April 28, 2019

Platform App Builder Certification Maintenance (Spring '19)

Unit : Platform App Builder Certification Maintenance (Spring '19)

UNIT : Learn What's New For App Builders:-

1. Which permission does an app builder need to access the Flow Builder?
A. Flow Manager
B. Author Apex
C. Manage Flow
D. Lightning Experience User

2. Where can an app builder change the layout of a Lightning page?
A. Page Layout
B. Properties
C. Page Navigator
D. App Options

3. An account team is no longer needed. What action can the account owner take to remove the entire team?
A. Create a custom action.
B. Use Transfer Account Team.
C. Remove all members manually.
D. Use Remove All Members.

4. Which language can an app builder use to build Lightning web components?
A. CSS
B. HTML
C. JQuery
D. Visualforce

5. Which relative set of date/time fields can an app builder specify in a macro when it is run?
A. Now, Time, Date
B. Today, DateTime, Date
C. Time, Date, DateTime
D. DateTime, Time, Today

UNIT : Get Hands-on with Customized Home Pages and Components:-

Now you can make your Lightning pages more dynamic by configuring home page components.
You've been given a requirement to make the Sales app home page specific for the Sales team. Build out a custom Lightning home page for the Sales app.
👉Launch a new Trailhead Playground
If you see an error when attempting to launch the playground, wait a few minutes and try again. It could take up to 15 minutes for the Playground to load.
👉Create a new Lightning page:
Page type: Home Page
Label: Sales Home Page
Template: Standard Home Page
👉Add the following components to the page:
Rich Text
Chatter Feed
Assistant
Today's Events
Today's Tasks
👉In the Rich Text component:
Add the text: Welcome!
Set font to: Salesforce Sans
👉On the Rich Text component, add a filter to set component visibility:
Field: Permissions > Standard Permission > Lightning Experience User
Operator: Equal
Value: True
👉Save and activate the page for all users.

👉Assign the page as the org default.

Administrator Certification Maintenance (Spring '19)

Unit : Administrator Certification Maintenance (Spring '19)

UNIT : Learn What's New in Spring '19:-

1. On which set of objects can an administrator customise the Stage Setup Flow?
A. Leads and cases
B. Leads and opportunities
C. Account and contacts
D. Campaigns and campaign members

2. How many blocks are available in joined reports?
A. 2
B. 3
C. 5
D. 8

3. An account team is no longer needed. How can the account owner remove the entire team?
A. Create a custom action
B. Use Transfer Account Team
C. Create a Delete Team process builder
D. Use Remove All Members

4. Which set of actions can an administrator take with subtab options in Console?
A. Refresh, customize, promote
B. Promote, publish, close
C. Promote, refresh, delete
D. Refresh, customize, publish

5. For which object can an administrator grant data sharing rules within workflows?
A. Tasks
B. Opportunities
C. Products
D. Contracts

6. Which relative date/time can an administrator specify in a macro when it is run?
A. Months from now
B. Years from today
C. Hours from now
D. Minutes from today

UNIT : Get Hands-on with Lightning Pages:-
Don’t like the layout of a Lightning page? Did your business needs change? Now with a few clicks, you can swap a Lightning page’s template.
You've been given a requirement to change the Account Record Page Lightning template.
👉Launch a new Trailhead Playground
If you see an error when attempting to launch the playground, wait a few minutes and try again. It could take up to 15 minutes for the Playground to load.
👉Create a new Lightning page:
To create a Lightning Page, Follow below Steps:-
Step 1 : Setup - Quick Findbox - Search for Lightning App Builder
Step 2 : Click on New 
Type: Record Page
Label: Account Management
Object: Account
Template: click Clone Salesforce Default Page, and then select Account Record Page Default
Click Finish

👉Change the Page Template to Header, Subheader, Left Sidebar
Leave template mapping as is and click Done

👉Add the following standard components to your page:-
Topics
Recent Items
👉Save and Activate; assign page as the Org Default

Saturday, February 23, 2019

Asynchronous Apex

Asynchronous Processing Basics

1. What is a key benefits of asynchronous processing?
A. Higher governor and execution limits
B. Unlimited number of external callouts
C. Override organization-wide sharing defaults
D. Enabling turbo mode for transactional processing
2. Batch Apex is typically the best type of asynchronous processing when you want to:
A. Make a callout to a web service when a user updates a record.
B. Schedule a task to run on a weekly basis.
C. Update all records in your org.
D. Send a rickroll email to a contact

Use Future Methods

Create an Apex class that uses the @future annotation to update Account records.
Create an Apex class with a method using the @future annotation that accepts a List of Account IDs and updates a custom field on the Account object with the number of contacts associated to the Account. Write unit tests that achieve 100% code coverage for the class.
 public class AccountProcessor {  
   @future  
   public static void countContacts(Set<Id> conId)  
   {  
     List<Account> accList = [SELECT ID, Name, Number_Of_Contacts__c, (SELECT ID From Contacts)FROM Account WHERE ID IN :conId];  
     for(Account acc : accList)  
     {  
       List<Contact> conList = acc.Contacts;  
       acc.Number_Of_Contacts__c = conList.Size();  
     }  
     update accList;  
   }  
 }  
Test Class :-
 @isTest  
 public class AccountProcessorTest {  
      public static testMethod void createAccount()  
   {  
     Account acc = New Account();  
     acc.Name = 'Test-Account';  
     Insert acc;  
     Contact con = New Contact();  
     con.FirstName = 'Test-FirstName-Contact';  
     con.LastName = 'Test-LastName-Contact';  
     con.AccountId = acc.Id;  
     Insert con;  
     Set<Id> accId = new Set<Id>();  
     accId.add(acc.Id);  
     Test.startTest();  
          AccountProcessor.countContacts(accId);  
     Test.stopTest();  
     Account accList = [SELECT Number_of_Contacts__c FROM Account where id = : acc.Id LIMIT 1];  
     System.assertEquals(accList.Number_of_Contacts__c, 1);  
   }  
 }  

Use Batch Apex

Create an Apex class that uses Batch Apex to update Lead records.
Create an Apex class that implements the Database.Batchable interface to update all Lead records in the org with a specific LeadSource. Write unit tests that achieve 100% code coverage for the class.
 global class LeadProcessor implements  Database.Batchable<Sobject>   
 {  
   global Database.QueryLocator start(Database.BatchableContext bc)   
   {  
     return Database.getQueryLocator([Select LeadSource From Lead ]);  
   }  
   global void execute(Database.BatchableContext bc, List<Lead> scope)  
   {  
       for (Lead Leads : scope)   
       {  
         Leads.LeadSource = 'Dreamforce';  
       }  
     update scope;  
   }    
   global void finish(Database.BatchableContext bc){  }    
 }  
Test Class :-
 @isTest   
 public class LeadProcessorTest   
 {  
   static testMethod void testMethod1()   
   {  
     List<Lead> lstLead = new List<Lead>();  
     for(Integer i=0 ;i <200;i++)  
     {  
       Lead led = new Lead();  
       led.FirstName ='FirstName';  
       led.LastName ='LastName'+i;  
       led.Company ='demo'+i;  
       lstLead.add(led);  
     }  
     insert lstLead;  
     Test.startTest();  
       LeadProcessor obj = new LeadProcessor();  
       DataBase.executeBatch(obj);   
     Test.stopTest();  
   }  
 }  

Control Processes with Queueable Apex

Create an Queueable Apex class that inserts Contacts for Accounts.
Create a Queueable Apex class that inserts the same Contact for each Account for a specific state. Write unit tests that achieve 100% code coverage for the class.
 public class AddPrimaryContact implements Queueable {  
   public Contact con;  
   public String state;  
      public AddPrimaryContact(Contact con, String state)  
   {  
     this.con = con;  
     this.state = state;  
   }  
   public void execute(QueueableContext qc)  
   {  
     List<Account> accList = [SELECT Id, Name, BillingState FROM Account WHERE Account.BillingState =: this.state Limit 200];  
     List<Contact> newContact = new List<Contact>();  
     for(Account acc : accList)  
     {  
       Contact con = new Contact();  
       con = this.con.clone(false, false, false, false);  
       con.AccountId = acc.Id;  
       newContact.add(con);  
     }  
     insert newContact;  
   }  
 }  
Test Class :-
 @isTest  
 public class AddPrimaryContactTest {  
 @testSetup  
 static void setup() {  
      List<Account> insertAccount = new List<Account>();  
      for(integer i=0; i<=100; i++) {  
      if(i <=50) {  
      insertAccount.add(new Account(Name='Acc'+i, BillingState = 'NY'));  
      }   
     else {  
           insertAccount.add(new Account(Name='Acc'+i, BillingState = 'CA'));  
           }  
      }  
      insert insertAccount;  
      }  
 static testMethod void testAddPrimaryContact() {  
   Contact con = new Contact(LastName = 'LastName');  
   AddPrimaryContact addPC = new AddPrimaryContact(con, 'CA');  
   Test.startTest();  
   system.enqueueJob(addPC);  
   Test.stopTest();  
      system.assertEquals(50, [SELECT count() FROM Contact]);  
      }  
 }  

Schedule Jobs Using Apex Scheduler

Create an Apex class that uses Scheduled Apex to update Lead records.
Create an Apex class that implements the Schedulable interface to update Lead records with a specific LeadSource. Write unit tests that achieve 100% code coverage for the class. This is very similar to what you did for Batch Apex.
 global class DailyLeadProcessor implements Schedulable{  
   global void execute(SchedulableContext sc){  
     List<Lead> lstOfLead = [SELECT Id FROM Lead WHERE LeadSource = null LIMIT 200];  
     List<Lead> lstOfUpdatedLead = new List<Lead>();  
     if(!lstOfLead.isEmpty()){  
       for(Lead ld : lstOfLead){  
         ld.LeadSource = 'Dreamforce';  
         lstOfUpdatedLead.add(ld);  
       }  
       UPDATE lstOfUpdatedLead;  
     }      
   }  
 }  
Test Class :-
 @isTest  
 private class DailyLeadProcessorTest{  
   @testSetup  
   static void setup(){  
     List<Lead> listOfLead = new List<Lead>();  
     for(Integer i = 1; i <= 200; i++){  
       Lead ld = new Lead(Company = 'Comp' + i ,LastName = 'LN'+i, Status = 'Working - Contacted');  
       listOfLead.add(ld);  
     }  
     Insert listOfLead;  
   }  
   static testmethod void testDailyLeadProcessorScheduledJob(){  
     String sch = '0 5 12 * * ?';  
     Test.startTest();  
     String jobId = System.schedule('ScheduledApexTest', sch, new DailyLeadProcessor());  
     List<Lead> listOfLead = [SELECT Id FROM Lead WHERE LeadSource = null LIMIT 200];  
     System.assertEquals(200, listOfLead.size());  
     Test.stopTest();  
   }  
 }  

Monitor Asynchronous Apex

1. What type of jobs do not show up in the Apex Flex Queue.
A. Future Method Jobs
B. Batch Apex Jobs
C. Queueable Apex Jobs
D. Scheduled Apex Jobs
2. Which statement is true regarding the Flex Queue.
A. You can submit up to 200 batch jobs for execution.
B. Jobs are processed first-in first-out.
C. Jobs can only be scheduled during Taco Tuesdays.
D. Jobs are executed depending upon user license

Sunday, January 6, 2019

Salesforce Trailhead : Platform App Builder Certification Maintenance (Winter '19)

Unit : Platform App Builder Certification Maintenance (Winter '19)


UNIT : Learn What’s New for App Builders

1. Which behavior is true when using the 'Deploy processes and flows as active' feature?
A. Apex tests must cover 75% of all active Processes and autolaunched Flows.
B. Pre-existing Processes and autolaunched Flows are marked as Inactive.
C. The Change Set must include a Permission Set that enables the 'deploy processes and flows as active' feature.
D. The Change Set must include a Permission Set that activates the Processes and Flows.
2. How should an App Builder ensure that Users are able to see Survey responses?
A. Subscribe Users to a Survey with Responses report.
B. Schedule a nightly Apex job to compile Survey statistics.
C. Grant Users See All Data on the Survey object.
D. Grant access to the Survey object then direct users to the Survey Invitations related list.

3. How can a user share the contents of a Salesforce Folder with customers in Lightning?
A. Create a Content Pack.
B. Create a public link to a Shared Folder.
C. Create a ZIP file containing multiple Files.
D. Create a Public Knowledge Base.

4. How can an App Builder configure a Guided Action to be mandatory on a record?
A. Mark the Guided Action Component as Required on the record page.
B. Create a Validation Rule for the record on which the Guided Action is run.
C. Set the Is Mandatory field in a Process that launches the Flow.
D. Set the Is Mandatory Flow public variable in the Flow.

UNIT : Get Hands-on with Lightning Pages

TASK : Create a Lightning app with a filtered standard component

You've been given a requirement to create a new app with a filtered display of leads on a standard list view component, based on user permissions.
To get started:
If needed, complete the Lightning App Builder module to learn more about creating Lightning pages.
👉Create a new Lightning app page:
Page Type: App Page
Label: App Filtered View
Layout: One Column
👉Add the following standard components to your page:
Chatter Feed
List View
👉Configure the List View standard component as follows:
Object: Lead
Filter: All Open Leads
Number of Records to Display: 10
👉Add a filter to set component visibility for the List View standard component to users with specific permissions:
Field: Permissions ↦Standard Permissions ↦Manage Leads
Operator: Equal
Value: True
👉Activate the page for all users.
👉Add the page to the Sales app.

Steps To Follow :-
Step 1 : Click on Setup, In Quick find box search for Lightning App Builder.
Step 2 : Click on NEW
Step 3 : Select APP Page, Click on Next
Label : App Filtered View, Click on Next ↦ select One Column Layout ↦ Finish.
Step 4 : 👉Add the following standard components to your page:
Chatter Feed
List View
Step 5 : Configure the List View standard component as follows:
Object: Lead
Filter: All Open Leads
Number of Records to Display: 10
Step 6 : 👉Add a filter to set component visibility for the List View standard component to users with specific permissions:

Field: Permissions ↦Standard Permissions ↦Manage Leads
Operator: Equal
Value: True

Step 7 : Save & Activate
Step 8 : 👉Activate the page for all users.

Step 9 : 👉Add the page to the Sales app.