Sunday, May 9, 2021

Record Locking/Unlocking From Apex(without approval process)

 

 By using Apex, we can lock/unlock records without using any approval process. Before writing

 any code in apex, first of all we need to go to setup -> Automation Process Setting-> check

 Enable record locking and unlocking in Apex.

Below is the code snippet for to lock records directly from Apex class:


    customObj__c [] recordList = [SELECT Id from customObj__c WHERE Name
LIKE ‘testName%’];
    // to lock the records
Approval.LockResult[] lockedResultList = Approval.lock(recordList,false);  



Here the lock method of Approval class takes 2 parameters:

   • The set of records need to be locked.

   • Boolean allorNothing, It returns the lock results, including failures if set to false. So it

   supports partial locking.


To check which records successfully got locked as well as the failed records, we 

can iterate overthe list of records below :-


// Iterate to check success & failure records
for(Approval.LockResult lr : lockedResultList) {

if (lr.isSuccess()) {
System.debug('Locked record id –> ' + lr.getId());
} else {
for(Database.Error err : lr.getErrors()) {
System.debug('error –> '+err.getStatusCode() +
': ' + err.getMessage());
}
}
}  



Similar to above process you can also unlock the locked record:


    customObj__c [] recordList = [SELECT Id from customObj__c WHERE Name
LIKE ‘testName%’];
    // to unlock the records
Approval.UnlockResult[] urList = Approval.unlock(recordList,false);  



To see more available features of Approval class, please refer to the link below:


 


Sunday, May 2, 2021

With Sharing & Without Sharing keywords in APEX

 


With Sharing Keyword:  When you want to enforce sharing rules that apply to the 

current user while executing an Apex class, you must use With Sharing keyword for the 

class. Without With Sharing keyword, the class would execute in system context, i.e. the 

sharing rules will not be applied for the current user. So the records that are not suppose to be 

accessed by the current user will be exposed.


The only exceptions to this rule are Apex code that is executed with the 

executeAnonymous call and Connect in Apex. executeAnonymous always executes 

using the full permissions of the current user.

Example:


    public with sharing class sharingClass {
// Code here
}




Without Sharing Keyword:  It ensures that the sharing rules of the current user are 

not enforced.  So why do we have to explicitly define Without Sharing as if you don't 

mention any keyword, it will enforce sharing rules as it will execute in system context? The 

answer is when the class(no sharing is mentioned ) is called from another class that is 

declared using With Sharing then sharing is enforced for the called class. To avoid such 

situation, we can explicitly define Without Sharing so that the class (no sharing is 

mentioned ) will run in system context.

Example:


    public without sharing class nosharing {
// Code here
}



Important things to Remember about Sharing Keywords:

  •   The Sharing settings are applied on the class where the method is defined, not of the
  class where the method is called. For example, if a method is defined in a class with With

 Sharing and the method is called from a class declared with Without Sharing, the method

  executes with sharing rules enforced.

  •   A class isn’t declared as either with or without sharing, the class doesn’t enforce sharing
rules for the current user except when it acquires sharing rules from another class. For 

example, if the class is called by another class that has with sharing keyword, then sharing is

 enforced for the called class. 

  •    Both inner classes and outer classes can be declared as With Sharing. The sharing 
  setting applies to all code contained in the class, including initialization code, constructors,

  and methods but Inner classes do not inherit the sharing setting from their container class.

  •  A class can inherit sharing setting from a parent class when one class extends or 
implements another.


Monday, March 9, 2020

Salesforce Platform Developer 1 Certification Maintenance WI20 Solutions


Please visit trailhead to know what's new in Winter 20 and maintain your Salesforce Administrator Certification by Completing the quiz in first section and a simple hands on for the final section.

For the first part, please find the quiz solution below:

1. When including a Visualforce page component in a Lightning Page using Lightning App Builder, which action hides the default label for the Visualforce page?

   Toggle the Label flag to Off
   Deselect the Show Label option
   Clear the Description field for the component
   Visualforce label are hidden by default when using Lightning App Builder

2. A developer needs to make changes to a custom field and associated Apex classes and triggers. How can the developer quickly determine which Apex classes and triggers use the field

   Run a report on the custom field
   Use the new ApexSettings metadata field
   Access the System Overview information from Setup
   On the custom field's detail page, click Where is this used?

3. A developer is preparing to install a managed package that will create several new custom objects. What should the developer do to understand how many objects can be created prior to reaching the allowed limit for the org?

   Run a report to show the number of active custom objects in the org
   Select Custom Objects from the dropdown menu in Schema Builder to see the number of custom objects
   Look at the number of custom objects and custom settings in the System Overview information
   Determine the difference between 2500, the maximum number of custom objects and the number of custom objects that currently exists in the org.

4. Which ApexSettings metadata field enables serial execution of Apex tests?

   enableGaplessTest
   enableSerialApexTesting
   enableParallelApexTesing
   enableDisableParallelApexTesting

5. With the Winter '20 release, which type of callout is now excluded from the concurrent long-running request limit?

   SOQL
   Apex triggers
   API calls to an Apex class
   Apex code that sends an HTTP request


2nd Part : Creating Custom Tabs for Lightning Web Components :

copy this package installation link and install it in your trailhead playground. After installation, lightning web component myComponent will be automatically available in the org. After that just create a custom tab Words for myComponent.


Salesforce Administrator Certification Maintenance WI20 Solutions


Please visit trailhead to know what's new in Winter 20 and maintain your Salesforce Administrator Certification by Completing the quiz in first section and a simple hands on for the final section.

For the first part, please find the quiz solution below:

1. What can an Administrator use to determine different levels of team member access to an Account?

   Visualforce pages
   Export account teams
   Account team hierarchy
   Report on account teams

2. An Administrator needs to automatically add account team members to an account. What tool can the Administrator use to meet this requirement?

   Global Actions
   Einstein Next Best Action
   Process Builder
   Lightning Web Components

3. What access does the Team Member Access button show when selected?

   Maximum access
   Global access
   Controlled by parent access
   Default access

4. Where would an Administrator go to customize the opportunity contact roles?

   Setup > Object Manager > Contact
   Setup > Object Manager > Opportunity Contact Role
   Setup > Object Manager > Opportunity
   Setup > User > Roles

5. Where can an Administrator find a sender signature field?

   Page layouts
   Formula field
   Variable tags
   Merge field picker

6. How many approval processes can be active in one org?

   300
   500
   1,000
   2,000

7. Which reference type is available when an Administrator uses the "Where is this used?" button on a field?

   Formula field
   Email template (Lightning)
   Report filter
   URL link


2nd Part : Record a Compliance Categorization Related to a Field’s Data :

For this, you need to do a simple configuration by going to Setup and selecting Object Manager.
In the Object Manager, find the object that you want to edit, and select Fields & Relationships from the sidebar. Select the field that you want to apply compliance categorization values to, and click Edit. For Compliance Categorization, add or remove the available values, and click Save.
















Friday, December 20, 2019

Sample package.xml Manifest Files used for ANT tool

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">

  <!--ApexClass-->(Represents an Apex page)
    <types>
    <members>Utilities</members>
    <name>ApexClass</name>
    </types>

 <!--ApexPage-->(Represents a Visualforce page)
    <types>
    <members>Unauthorized</members>
    <name>ApexPage</name>
    </types>

 <!--ApexComponent-->(Represents a Visualforce component)
    <types>
    <members>Order_Acknowledgement_Email</members>
    <name>ApexComponent</name>
    </types>

 <!--ApexTrigger-->(Represents an Apex trigger)
    <types>
    <members>User_Trigger</members>
    <name>ApexTrigger</name>
    </types>

  <!--ApexTestSuite-->(Represents a suite of Apex test classes to include in a test run)
    <types>
    <members>All_Test_Suite</members>
    <name>ApexTestSuite</name>
    </types>

  <!--AppMenu-->(Represents the app menu or the Salesforce mobile navigation menu)
    <types>
    <members>AppSwitcher</members>
    <name>AppMenu</name>
    </types> 

  <!--ApprovalProcess-->(Represents the metadata associated with an Approval Process)
    <types>
    <members>Program__c.ProgramApproval</members>
    <name>ApprovalProcess</name>
    </types>

  <!--AssignmentRule-->(Represents specific assignment rules)
    <types>
    <members>Lead.ProgramAssignment</members>
    <name>AssignmentRule</name>
    </types>

  <!--AssignmentRules-->(Represents all assignment rules in an object)
    <types>
    <members>Lead</members>
    <name>AssignmentRules</name>
    </types>

 <!--AutoResponseRule-->(Represents specific auto-response rules)
    <types>
    <members>Lead.ProgramLeadAutoresponse</members>
    <name>AutoResponseRule</name>
    </types>

  <!--AutoResponseRules-->(Represents all auto-response rules in an object)
    <types>
    <members>Lead</members>
    <name>AutoResponseRules</name>
    </types>

  <!--AuraDefinitionBundle-->(Represents an Aura definition bundle)
    <types>
    <members>ContactDetails</members>
    <name>AuraDefinitionBundle</name>
    </types>

  <!--AuthProvider-->Represents an authentication provider (auth provider). An auth provider         lets users log in to your Salesforce org from an external service provider, such as Facebook, Google,     or  GitHub)
    <types>
    <members>UI_API_Auth_Provider</members>
    <name>AuthProvider</name>
    </types>

 <!--BusinessProcess-->(The BusinessProcess metadata type enables you to display different                picklist values for users based on their profile)
    <types>
    <members>Opportunity.Sales Process - Partner</members>
    <name>BusinessProcess</name>
    </types>

 <!--BrandingSet-->(Represents the definition of a set of branding properties for a community, as        defined in the Branding Panel in Community Builder)
    <types>
    <members>customer_satisfaction_survey</members>
    <name>BrandingSet</name>
    </types>

 <!--CompactLayout-->(Represents the metadata associated with a compact layout)
    <types>
    <members>Project__c.SiliconProjectContactLayout</members>
    <name>CompactLayout</name>
    </types>

 <!--CustomTab-->(Represents Custom Object tab, Web tab and Visualforce tab)
    <types>
    <members>Program__c</members>
    <name>CustomTab</name>
    </types>

<!--ConnectedApp-->(Represents a connected app configuration)
    <types>
    <members>Tata_Sales_ConnectedApp</members>
    <name>ConnectedApp</name>
    </types>

<!--CustomSite-->(Represents a Salesforce site. Create public websites and applications that are directly integrated with your Salesforce organization, but don't require users to log in with a username and password)
    <types>
    <members>Partner_Registration</members>
    <name>CustomSite</name>
    </types>

<!--CustomPermission-->(Represents a custom link defined in a home page component)
    <types>
    <members>SBQQ__HideGlobalHeader</members>
    <name>CustomPermission</name>
    </types>

<!--CustomPageWebLink-->(Represents a custom link defined in a home page component)
    <types>
    <members>ConfigureQuoteQuickly</members>
    <name>CustomPageWebLink</name>
    </types>

<!--CustomObject-->(Represents salesforce standard & custom object)
    <types>
    <members>Program__c</members>
    <name>CustomObject</name>
    </types>

<!--CustomObjectTranslation-->(This metadata type allows you to translate custom objects for a variety of languages)
    <types>
    <members>WorkType-zh_TW</members>
    <name>CustomObjectTranslation</name>
    </types>

<!--CustomNotificationType-->(Represents the metadata associated with a custom notification type. Custom notification types allow you to send a custom desktop or mobile notification via a process or invocable API call)
    <types>
    <members>Lead_Approve_Notification</members>
    <name>CustomNotificationType</name>
    </types>

<!--CustomMetadata-->(Represents a record of a custom metadata type)
    <types>
    <members>SME_Variable.Partner_Manager_Name</members>
    <name>CustomMetadata</name>
    </types>

<!--CustomLabels-->(The CustomLabels metadata type allows you to create custom labels that can be localized for use in different languages, countries, and currencies)
    <types>
    <members>*</members>
    <name>CustomLabels</name>
    </types>

<!--CustomLabel-->(For individual custom label)
    <types>
    <members>quoteManual</members>
    <name>CustomLabel</name>
    </types>

<!--CustomField-->(Represents the metadata associated with a field)
    <types>
    <members>Account.Product_Family__c</members>
    <name>CustomField</name>
    </types>

<!--ContentAsset-->(Represents the metadata for creating an asset file. Asset files enable a Salesforce file to be used for org setup and configuration purposes)
    <types>
    <members>generic_company_logo</members>
    <name>ContentAsset</name>
    </types>

<!--CaseSubjectParticle-->(Represents the Social Business Rules custom format for the Case Subject field on cases created from inbound social posts)
    <types>
    <members>SCSCaseSubjectParticle1</members>
    <name>CaseSubjectParticle</name>
    </types>


<!--CampaignInfluenceModel-->(Represents a campaign influence model used by Customizable Campaign Influence)
    <types>
    <members>primaryModel</members>
    <name>CampaignInfluenceModel</name>
    </types>
  

  <!--CustomApplication-->(Represents a custom or standard application)
    <types>
    <members>MicrosoftSalesApp</members>
    <name>CustomApplication</name>
    </types>

<!--DuplicateRule-->(Represents a rule that specifies how duplicate records in an object are detected)
    <types>
    <members>Contact.Standard_Contact_duplicate_rule</members>
    <name>DuplicateRule</name>
    </types>


<!--Document-->(Represents a Document. All documents must be in a document folder, such as  samplefolder/testdocument)
    <types>
    <members>CPQ_Product_Images/HPMouse.png</members>
    <name>Document</name>
    </types>

<!--DelegateGroup-->(Represents a group of users who have the same administrative privileges)
    <types>
    <members>CustomerCommunity</members>
    <name>DelegateGroup</name>
    </types>

<!--DataCategoryGroup-->(Represents a data category group)
    <types>
    <members>Servers_Storage</members>
    <name>DataCategoryGroup</name>
    </types>

<!--Dashboard-->(Represents a dashboard)
    <types>
    <members>Servers_Storage</members>
    <name>Dashboard</name>
    </types>


<!--EscalationRules-->(Represents case escalation rules to escalate cases automatically if they are not resolved within a certain period of time)
    <types>
    <members>Case</members>
    <name>EscalationRules</name>
    </types>


<!--EscalationRule-->(Represents specific case escalation rules to escalate cases automatically if they are not resolved within a certain period of time)
    <types>
    <members>Case.Case Escalation Rules</members>
    <name>EscalationRule</name>
    </types>

<!--EntitlementTemplate-->(Represents an entitlement template. Entitlement templates are predefined terms of customer support that you can quickly add to products)
    <types>
    <members>Software Support Plan</members>
    <name>EntitlementTemplate</name>
    </types>

<!--EntitlementProcess-->(Represents the settings for an entitlement process)
    <types>
    <members>Software Support Plan</members>
    <name>EntitlementProcess</name>
    </types>

<!--EmailTemplate-->(Represents an email template)
    <types>
    <members>Support_Email_Templates/SUPPORTSelfServiceResetPassword</members>
    <name>EmailTemplate</name>
    </types>

<!--EmailServicesFunction-->(Represents an email service)
    <types>
    <members>Support_Email_Templates/SUPPORTSelfServiceResetPassword</members>
    <name>EmailServicesFunction</name>
    </types>

<!--FlowDefinition-->(Represents the flow definition’s description and active flow version number)
    <types>
    <members>satisfaction_survey</members>
    <name>FlowDefinition</name>
    </types>

<!--Flow-->(Represents the metadata associated with a flow)
    <types>
    <members>satisfaction_survey</members>
    <name>Flow</name>
    </types>

<!--FlexiPage-->(Represents the metadata associated with a Lightning page)
    <types>
    <members>Territory_Record_Page</members>
    <name>FlexiPage</name>
    </types>


<!--FieldSet-->(Represents a field set. A field set is a grouping of fields)
    <types>
    <members>Account.Emergency_Account_Fields</members>
    <name>FieldSet</name>
    </types>


<!--Group-->(Represents a set of public groups, which can have users, roles, and other groups)
    <types>
    <members>Credit_Check_Group</members>
    <name>Group</name>
    </types>

<!--GlobalValueSet-->(Represents a set of public groups, which can have users, roles, and other groups)
    <types>
    <members>SubscriptionPricing</members>
    <name>GlobalValueSet</name>
    </types>

<!--HomePageLayout-->(Represents the metadata associated with a home page layout)
    <types>
    <members>Channel Manager Home Page</members>
    <name>HomePageLayout</name>
    </types>

<!--HomePageComponent-->(Represents the metadata associated with a home page layout)
    <types>
   <members>Channel Manager Home Page</members>
    <name>HomePageComponent</name>
    </types>

<!--InstalledPackage-->(Represents a package to be installed or uninstalled)
    <types>
    <members>SocialService</members>
    <name>InstalledPackage</name>
    </types>

<!--ListView-->(ListView allows you to see a filtered list of records)
    <types>
    <members>Account.My_Accounts</members>
    <name>ListView</name>
    </types>

<!--Layout-->(Represents the metadata associated with a page layout)
    <types>
    <members>Account.Site Accounts</members>
    <name>Layout</name>
    </types>


<!--MatchingRules-->(Represents a matching rule that is used to identify duplicate records)
    <types>
    <members>Account</members>
    <name>MatchingRules</name>
    </types>


<!--NamedCredential-->(Represents a named credential, which specifies the URL of a callout endpoint and its required authentication parameters in one definition)
    <types>
    <members>UI_API_Named_Credential</members>
    <name>NamedCredential</name>
    </types>

<!--NetworkBranding-->(Represents the branding and color scheme applied to a Community)
    <types>
    <members>Company_Partner_Community</members>
    <name>NetworkBranding</name>
    </types>

<!--Network-->(Represents a Community)
    <types>
   <members>My Company Partner Community</members>
    <name>Network</name>
    </types>

<!--Profile-->(Represents a user profile)
    <types>
   <members>CRM_Channel_Manager</members>
    <name>Profile</name>
    </types> 

<!--PermissionSet-->(Represents a set of permissions that's used to grant additional access to one or more users without changing their profile or reassigning profiles)
    <types>
   <members>Article_Access</members>
    <name>PermissionSet</name>
    </types>

<!--QuickAction-->(Represents a specified create or update quick action for an object that then becomes available in the Chatter publisher)
    <types>
    <members>PF_Product__c.PF_New_Epic</members>
    <name>QuickAction</name>
    </types>

<!--Queue-->(Represents a holding area for items before they are processed)
    <types>
   <members>Partner_Referral_Lead_Queue</members>
    <name>Profile</name>
    </types>

<!--Role-->(Represents a Role in your Organization)
    <types>
    <members>Security</members>
    <name>Role</name>
    </types>

<!--ReportType-->(Represents the metadata associated with a custom report type)
    <types>
    <members>User_with_Opportunity</members>
    <name>ReportType</name>
    </types>

<!--Report-->(Represents the metadata associated with a Custom Report Type)
    <types>
    <members>PartnerUserFolder/Projects_By_Approval_Status_hS5</members>
    <name>Report</name>
    </types>

<!--RemoteSiteSetting-->(Represents a Remote Site Setting)
    <types>
    <members>Emerson_Sandbox</members>
    <name>RemoteSiteSetting</name>
    </types>

<!--RecordType-->(Represents a Record Type)
    <types>
    <members>Account.Account_site</members>
    <name>RecordType</name>
    </types>

<!--StaticResource-->(Represents a static resource)
    <types>
    <members>YUILibrary</members>
    <name>StaticResource</name>
    </types>

<!--Settings-->(Represents the organization settings related to a feature)
    <types>
    <members>Security</members>
    <name>Settings</name>
    </types>

 <!--SharingRules-->(Represents the base container for sharing rules)
    <types>
    <members>Account</members>
    <name>SharingRules</name>
    </types>

 <!--SharingCriteriaRule-->(Represents Criteria based sharing rules)
    <types>
    <members>Account.Share_Partner_Accounts</members>
    <name>SharingCriteriaRule</name>
    </types>

 <!--SharingOwnerRule-->(Represents Ownership based sharing rules)
    <types>
    <members>Order.Read_All_Orders_Internally</members>
    <name>SharingOwnerRule</name>
    </types>

 <!--SharingReason-->(Represents an Apex sharing reason, which is used to indicate why  sharing was implemented for a custom object)
    <types>
    <members>Order.Read_All_Orders_Internally</members>
    <name>SharingReason</name>
    </types>

 <!--SharingSet-->(Represents a Sharing set)
    <types>
    <members>Partner_Access_to_Accounts</members>
    <name>SharingSet</name>
    </types>

 <!--SiteDotCom-->(Represents a site for deployment)
    <types>
    <members>My_Company_Customer_Service_C</members>
    <name>SiteDotCom</name>
    </types>

 <!--SiteDotCom-->(Represents a site for deployment)
    <types>
    <members>My_Company_Customer_Service_C</members>
    <name>SiteDotCom</name>
    </types>

 <!--ValidationRule-->(Represents a validation rule)
    <types>
    <members>Program__c.Territory_Name_is_empty</members>
    <name>ValidationRule</name>
    </types>

 <!--Workflow-->(Represents the metadata associated with a workflow rule)
    <types>
    <members>Account</members>
    <name>Workflow</name>
    </types>

 <!--WorkflowAlert-->(Represents an email alert associated with a workflow rule)
    <types>
    <members>Case.SME_25_discount_Email_Alert</members>
    <name>WorkflowAlert</name>
    </types>

<!--WorkflowFieldUpdate-->(Represents a Workflow field update)
    <types>
    <members>Address__c.Update_The_Name_Field</members>
    <name>WorkflowFieldUpdate</name>
    </types>

<!--WorkflowRule-->(Represents a Workflow field update)
    <types>
    <members>Address__c.Update The Address Name</members>
    <name>WorkflowRule</name>
    </types>

 <!--WorkflowTask-->(Represents an assigned workflow task)
    <types>
    <members>Address__c.Update The Address Name</members>
    <name>WorkflowTask</name>
    </types>


  <version>45.0</version>
</Package>