LET'S LEARN TOGETHER. THE BEAUTIFUL THING ABOUT LEARNING IS NOBODY CAN TAKE IT AWAY FROM YOU.

Summer'17 :: Retrieve and Deploy Metadata through Apex


In Salesforce World, Metadata plays a very important role. Metadata types and components are used to represent org specific configuration and customization. Salesforce is having a very good page explaining Metadata. Here is the link - "An Introduction to Force.com Metadata". 

Before Summer'17 release, in order to access Metadata, you need to use the Metadata API, but now Salesforce comes up with Metadata namespace. You can use classes in Metadata namespace to access Metadata components through Apex.

Why do I need to access Metadata?
Salesforce documentation explains it correctly and here are the possible reasons why you may need to access Metadata.

In this post, I am going to explain how you can access and deploy Metadata changes through Apex with an example.

Example -
In my Salesforce Org, I have one Custom Metadata Type named - "Admin Preference" which is -
The values of this Custom Metadata Type are -

Now I will create a simple VisualForce Page which will retrieve this Metadata Values and display them. At the same time from the same page, I will change the values. 

To implement this requirement, I will use the Salesforce Summer'17 New Feature - classes Metadata namespace.

Let's Start -
In order to store the Custom Metadata Values, I will use the below class -

public class MetadataHelper{
    public String name {get;set;}
    public Boolean isEnabled {get;set;}

    public MetadataHelper(String name, Boolean isEnabled){
        this.name = name;
        this.isEnabled = isEnabled;
    }

    public String getFullName(){
        String fullName = 'Admin_Preference__mdt.';
        if(name.equalsIgnoreCase('Process Builder Preference')){
            fullName = fullName + 'Process_Builder_Preference';
        }else if(name.equalsIgnoreCase('Trigger Preference')){
            fullName = fullName + 'Trigger_Preference';
        }else if(name.equalsIgnoreCase('Validation Rule Preference')){
            fullName = fullName + 'Validation_Rule_Preference';
        }else if(name.equalsIgnoreCase('Workflow Preference')){
            fullName = fullName + 'Workflow_Preference';
        }
        return fullName;
    }
 }

How to retrieve the Custom Metadata Types and it's Values: 

To retrieve the Custom MetadataTypes, the command is - Metadata.Operations.retrieve(). This method will retrieve the Metadata synchronously. We need to pass the list of component names and this method will return a list of matching component data (Metadata.Metadata format).

Once you have the list, power is completely in your hand. Trust me!! Really you have all the power you need then. You can iterate through the list and get the each CustomMetadataRecord. Now each CustomMetadataRecord is having CustomMetadataValues which also you can fetch and play around. 
CustomMetadataValues are stored in two fields - the first one is "field" which stores the API name of the field and the second one is "value" which stores the value of that field for that CustomMetadataRecord. Confused??? Don't worry I will give you now a clean picture which helped me to understand and I hope it will help you as well.

To understand how the custom metadata information is stored in Salesforce, consider our Custom Metadata Type mentioned above - Admin Preference. And let's consider one value here - 



So according to the above example - Metadata.Operations.retrieve() will retrieve the CustomMetadataRecord - Process Builder Preference. Now this record is having the label - "Process Builder Preference", which we can get from the label field. The fullName of this record is - "Admin_Preference__mdt.Process_Builder_Preference" which we can get from the method getFullName()
In the above example, this CustomMetadata is having only one value which is stored inside a field of type Metadata.CustomMetadataValue. For that single  Metadata.CustomMetadataValue, the field = 'Enabled__c" and value = true.

So the visual representation of the flow is -


With the above explanation, here comes to code -

How to deploy Custom Metadata Types and it's Values: 
The method Metadata.Operations.enqueueDeployment is used to deploy the changes to the org. The operation is happening in asynchronous mode and that is the reason we need to provide a callback method to handle the success/failure scenarios. To create the callback, we need to implement the interface Metadata.DeployCallback and by doing that we need to put our logic in the method - handleResult.

Below is the CallBack method -

Now to deploy the changes below is the code -

You can find the full code in my Github repository.

With all these changes, below is how the functionality working - 


Limitation - Metadata access in Apex is currently only possible for custom metadata records and page layouts. You can retrieve, create or update custom metadata, but you cannot delete metadata through Apex.


Share:

Summer'17 :: Embed Your Flow in Lightning Experience


In this post, I am going to explain the new Flow features introduced by Salesforce in Summer'17.

Add Flow into Record Detail Pages:
With Summer'17 Salesforce release, now you can add flows into any Lightning Pages. You need to add the Flow component to your Lightning pages. This feature was introduced by Salesforce in Winter'17 release as a beta functionality, and in Summer'17 this is now Generally Available.

In this section, I am going to explain how you can add flow into record details page through Lightning App Builder.

Let's first create a flow which needs a parameter which is basically the record Id. The intention is that when we will add this flow into the record detail page, we will pass the record Id to flow and then flow will fetch necessary information from the record and prepare its own view.
So here is the flow -

Flow Name: Survey Customer
This flow is having one input variable - "recordId" which will store the Salesforce Record Id passed from record detail page.

With this variable, the flow will query the Salesforce Contact Record, fetch Contact's First Name and Last Name and generate the customized Welcome Message. I am not going to show how Flow is configured because the intention of this post is to demonstrate how to use the flow inside Lightning Experience.
Here is the final view of the flow -


Now, will come the fun part. Let's say we wanted to display this message in Contact Detail Page. What we need to do is - Open the contact detail page and then click on the Edit Page option from Top Right.
This will open the Contact Detail page in Lightning App Builder

From the left section, select the Flow Component under Standard and drag it under Activity Section at the button.
Now select the Flow component, and you will see the configuration panel at right next to it. This is the place where you will select your flow and also the parameters you will pass to the flow. See the animation below -
And that's all. Now the contact details page will look like -

Enjoy Flow in Lightning. Please provide your feedback.
Share:

Salesforce Optimizer - Spring 17 New Feature


Salesforce introduced the new feature in Spring'17 - Salesforce Optimizer. This is really a nice tool which will evaluate your implementation in terms of the Salesforce features you are using and then identifies the ways to improve the implementation.

We all know that continuous improvement is very important, but in reality driving that continuous improvement sometimes becomes a challenging task. In my Salesforce experience, I faced the below problems when it comes to improvement -
  • I know I need to do improvement, but where is the time? Where to start from?
  • I really need trustworthy tools and guidance to help me driving the improvement
  • I need to convince business in terms of the importance of improvement.
  • I don't want to go to bed every day with the worry that I may be missing something which might break my implementation tomorrow.
That's quite a lot!! 
But now with Salesforce Optimizer, I have the answer to all of my doubts, questions.

Salesforce Optimizer is available in 
  • Classic and Lightning Experience
  • Professional, Enterprise, Performance, Unlimited and Developer Editions
  • Sandbox and Production Environments.
To access Salesforce Optimizer, you need below permissions -
You can find the documentation here -
Salesforce Optimizer Documentation

You will find the Salesforce Optimizer under Setup | Monitor | Optimizer 

Once you click on the Optimizer, on the next page, you need to Launch Optimizer by clicking on the Launch button.

Salesforce will generate the report and send the report to your email address.

Once you will open the report, you will find the report on the below features -

If the implementation is as per the best practices, you will find -

If the implementation is not as per the best practices and needs improvement, you will find -

I really love this new initiative from Salesforce, though there are many scopes of improvements in terms of items to be covered in the report. It will be really great to have Apex Class, VisualForce Page, Test Class included in the report.

There is a success community where we can provide our feedbacks using #OptimizerReportFeedback.

Please let me know if you are using this new feature and what is your comment on this. 
Wishing you a nice weekend.  

Share:

Salesforce Advanced Administrator Certification Tips

I took Salesforce Advanced Administrator certification exam on 31st Jan'17 and cleared it. In this post, I am going to write down how I approached this certification and my study materials as well.
First, to start you, you need the Salesforce Advanced Administration Certification guide. You can download the same from here. The exam format is -
  • Number of questions: 63
  • Type of questions: Multiple-Choice
  • Passing Score: 65%
  • Time: 90 Minutes
So basically you need to answer ~41 questions correctly. 
Note - You need to clear Salesforce Certified Administration Certification before this certification.

Strategy:
I followed the below strategy by reviewing the certification guide and bucketing the items based on their weightages. This is the formula I followed, topics with more than 10% weightage are my priority items and rest of the items are kind of last minute items to check.

With the above strategy, I came up with the below list -
  • Security and Access
  • Sales Cloud Applications
  • Service Cloud Applications
  • Data Management
  • Change Management
  • Analytics, Reports and Dashboards
  • Process Automation
But definitely, I was not sure whether I can answer all the questions correctly from above lists. So my backup plan was to make myself comfortable with the below items as well -
  • Extending Custom Objects and Applications
  • Auditoring and Monitoring
These two sections are comparatively very easy and easily you can answer all the questions correctly. The only section which I was not sure and didn't put any effort at all was - Content Management. Note - I got 2-3 questions from this section in the actual exam.

Study Material:
I started with Partner Training - Administrator Essentials for Experienced Admin (ADM 211). I will highly recommend you to go through this training if you have access to it. The entire training is very much focused. It is my experience that if you can complete these training, 80% of your preparation is done. This training will not cover the Service Cloud part of the certification. But if you have access to Partner Training, there is another training which you should consider as well - Service Cloud for Admin.

But if you don't have access to the partner training, you can concentrate on the below study materials to understand the concept needed. I am writing them below -
I have mentioned all my study materials at the top. Apart from studying individual concepts, I tried to practice the same in my developer org. Practicing the items in your developer org will help you to understand the concept. Remember - Salesforce Advanced Administrator Certification is all about how much you are comfortable with concepts and have you done implementation before on those concepts? So practicing in your developer org will give you that extra edge for sure.

Finally, I have completed few Mock Exams to understand my readiness. Again, don't trust any of the Mock Exam. Use them to understand which section of the exam you need to put more effort. Repeat this same step multiple times until and unless you get the answer - YES for the question - AM I READY FOR THE EXAM?

Below are few Mock Exams I used -

- Sudipta

Feel free to add your comments and add resources which helped you. 
Share:

Product Schedule in Salesforce

In Sales Cloud, when companies are dealing with Accounts, Contacts, Opportunities and Products, one thing is very obvious who the company will get the money back from the Contacts for the Products sold to them. Are the contact/account going to pay all together in one shot or are they going to pay over the period of times(Equal Installments)? 

Salesforce has the answer to these questions. In Salesforce you can configure how your customer will pay you the money. Based on that configuration, you can run your business reports to track your sales matrices. The way you can configure this in Salesforce is known as Product Schedule. Product Schedule are the payment or delivery cycles for the products which will be either paid over time or delivered over time. 

In Salesforce we have three different types of schedules. 
  • Quantity Schedule: Choose this schedule when you want your products to be delivered over the period of time. Example - Consider your customer bought subscription of one magazine from you for the next 2 years. Now you need to courier the monthly subscription to your customer every month. So in this scenario, you will go for Quantity Schedule.
  • Revenue Schedule: Choose this schedule when you want your customer to be billed over the period of time. Example - Consider you are selling House Insurance to your customer. The total cost is USD 1200 for one year. But you will bill customer on monthly basis i.e. USD 100 per month. In this scenario, you will go for Revenue Schedule.
  • Revenue and Quantity Schedule: Choose this schedule when a product will be delivered over the period of time and you bill your customer also over the time. Example - Consider your customer bought the subscription of one magazine for next 2 years. But this time instead of charging your customer at the beginning, you will charge the customer on monthly basis and also courier the magazine on monthly basis. In this scenario, you will go for Revenue and Quantity Schedule.
Schedule Type:
Schedule Type defines how the Number of Installments is used. There are two types of Schedule Type 
  • Divide: Here the Unit Price is divided by the number of installments.
  • Repeat: Here the Unit Price is multiplied by the number of installments.
Product Schedule can be enabled from Setup > Customize > Products > Product Schedules Settings.

Note - Read this post from Salesforce on Consideration for using Product Schedules.

Default Schedule:
A default schedule is associated with a product for a particular price book. Every time such product is added to the Opportunity, the default schedule is automatically added as well. Even though default schedule is automatically added to the Opportunity, Sales Rep can still change the schedule. 

Let's go for some Use Cases.

Use Case # 1
Company ABCD is selling subscription of their magazine - "Let's Enjoy". This magazine is getting published on monthly basis and cost of each publication is USD 10.00. Company ABCD is having customer who is planning to buy the subscription for next 2 years. Sales Rep of ABCD will now create the opportunity, add the product and product schedule as well.

Implementation:
Assumption: Product "Let's Enjoy" is having no default schedule setup.
Product is configured as shown below -
Now create the opportunity and add the product to the opportunity as shown below -

Let's configure the Product Schedule now as shown below in the below pictures -

So now Quantity Schedule is configured in Salesforce.

Use Case # 2
Company MNOP is selling "House Insurance". Cost of House Insurance is USD 1200 per year. Company wants to bill customer for this insurance on monthly basis. Sales Rep of MNOP will now create the opportunity, add the product and product schedule as well.

Implementation:
Product is configured as shown below -
Now create the opportunity and add the product to the opportunity as shown below -

Let's configure the Product Schedule now as shown below in the below pictures -
So now Revenue Schedule is configured and the total amount i.e. USD 1200 is divided into 12 equal monthly payments i.e. USD 100.00.

Note - If a product is having both default Quantity and Revenue Schedule, then Quantity Schedule is calculated first to determine the total product revenue. Then the Revenue Schedule is applied to the amount. I will explain this in my next Use Case.

Use Case # 3
Company IJKL is selling Medicine Box (Cost is USD 10.00 per box) to hospital BCD. The quantity of Medicine Box is 1000. Company will deliver the boxes over the period of 12 months on monthly basis. Company will send the bill to hospital quarterly over the period of 6 installments. Sales Rep of IJKL will now create the opportunity, add the product and product schedule as well.

Implementation:
Product is configured as shown below -


Now create the opportunity and add the product to the opportunity as shown below -

Default Schedule will be applied and it will be displayed as -

As the above picture says, the quantity is distributed on monthly basis where the revenue is distributed on quarterly basis.

I hope with the above examples, the concept - Product Schedule will be easy for you to understand. Please provide your feedback. Thanks.
Share:

Relationship between Product, Price Book and PricebookEntry


In my previous post, I have explained the basic concepts about Products and PriceBooks. You can read the post here - Products and Price Books in Salesforce.

Now in this post, I am going to explain the relationship between Product, Price Book and PricebookEntry. So let's start with few basics.

Basic:
  • Products are represented by Standard Object - Product2.
  • PriceBooks are represented by Standard Object - Pricebook2
  • Each Pricebook can have zero or more entries. Each of these entries are stored inside the Standard Object - PricebookEntry. Each entry in PricebookEntry defines the cost of the products in a particular currency.
  • These three objects - Product2, Pricebook2 and PricebookEntry will only be available if Product is enabled in the organization.
Data Model:
  • PricebookEntry is the junction object between Product and Price Book.
  • OpportunityLineItem is the junction object between Opportunity and PricebookEntry.

Below is the flow diagram depicting the process to load Products and setup PriceBook through API.


I hope this post will help you to understand the relationships between these objects. Please provide your feedback. Thanks.
Share:

Products and Price Books in Salesforce


Define your Product:
A Product is a service or item that the company sells to the customers. Once you have added the Products, you can set the price of the product per unit based on your business. In Salesforce, Product is a Standard object having standard fields and tabs. You can add your custom fields to customize Product object as per your business requirement. Products can be added to the Opportunity allowing you to have an correct inventory and also make your forecasting accurate.

What is Price Book:
The Price Book will provide the list of products and their prices per unit. You can create multiple price books to maintain different prices for the same product based on your business needs. Salesforce will always provide your a Standard Price Book. The moment you add a Product into Salesforce and set the price of the Product, that Product will go into Standard Price Book. But you can create Custom Price Book as well.

Use case of Custom Price Book:
Let's say, the company "Universal Company" is selling the product - "Desktop Mouse" globally. The company is running it's business from Canada. But company is selling products globally. Now when this company is selling "Desktop Mouse" within Canada, the price is USD 12.00, but when it is selling the same product in Europe, the price is USD 19.00 (due to extra shipping cost), similarly then the same product will be sold in APAC, the price will be USD 20.00. Now to maintain different prices for the same product based on geography, we need to create three different Custom Price Books - Canada Price Book, Europe Price Book and APAC Price Book.

Don't worry, I will provide you the entire step by step configuration in later part of this post. Let's concentrate on the basic concepts and considerations while configuring Products and Price Books in Salesforce.

Important Notes on Creating Products:
  • Permission needed to create Products are "read" and "create" permission on Product object.
  • You can create Products by cloning an existing Product. But if you don't have sharing access in any of the Price Books, then entries for that Price Book and Product combination will not be created. Similarly if you have read-only access on any fields, value of that field will not be carried over to the cloned record.
  • It is recommended to not have more than 2,000,000 products otherwise it may impact the performance.
  • Products always needs an active Price Book so that you can add the product to that Price Book.
  • Product object is having a standard field - Product Currency. This field holds the currency of the product. In a multi currency organization, if the product currency is different from user's currency, then product currency will be converted into user's currency and both the values will be displayed. (Converted amount will be displayed in parentheses).
Sharing Price Books:
  • Admin or user with with "Edit" permission on Price Book can share the same with more users, groups, roles and territories.
  • You can't make it more restrictive.
  • Sharing option will only be available when the OWD of Price Book is either "No Access" or "View Only".
  • Price Book Sharing is not available under Salesforce Lightning Experience(Latest release is Spring'17 when I am writing this blog post). It is available only in Salesforce Classic.
Want to remove Price Books? Need to know below points -
  • You can delete, deactivate or archive Custom Price Books. It is having no impact on other Custom Price Books. These action will impact Opportunity and Quotes.
  • You need to change association with Opportunity or Quotes before removing an associated Price Book.
  • For Standard Price Book, you can deactivate the same, but can't delete or achieve it.
  • You can't delete a Price Book while it's in use on Opportunities or Quotes. Trying to do the same will create a list of Opportunities or Quotes where the Price Book is being used.
  • You can deactivate a Price Book while it is being used in Opportunities or Quotes. Managing Entries is also possible for deactivated Price Books and you can re-activate the same as well.
  • You can archive a Price Book even if it being used in Opportunities or Quotes. Archived or Deleted Price Books can't be recovered.
Want to remove Products from Price Books?
  • You can remove Products from a Price Book as long as that Price Book + Product combination is not being used in any existing Opportunity or Quotes. Removing Products from a Price Book will not impact other Price Books where the same Products are listed as well.
  • If a Product + Price Book combination is being used in any of the existing Opportunity or Quotes and you want to remove the Product from that Price Book, you have three options, which is explained here - 
Important Note - While associating Products with an Opportunity, you need to select the Price Book first. An Opportunity can have Products only from one Price Book.

Use Case:
The company "Universal Company" is selling three products - Mouse, Monitor and Laptop. The price of each Products is different for each Geography. The detail is displayed below -

Implementation -
  • Create three different Products in Salesforce with Standard Price and add them in Standard Price Book as shown below - 
  • Now create three different Price Books and add the products there with the corresponding prices as shown below - 
In my next post, I will explain the relationship between Price Book, Product and PricebookEntry. Please let me know your feedback. Thanks.



Share:

Follow Me

Enter your email address:

Delivered by FeedBurner

Labels

Salesforce (105) Apex (47) admin (27) visualforce (21) ADM (20) dev 501 (19) integration (18) learn salesforce (18) 501 (16) lightning (15) SOAP (13) javascript (13) tutorial (11) Certification. (10) Kitchener Developer Group (8) Certification (7) Trigger (7) security (7) test class (7) unit testing (7) Advanced Admin (6) Advanced Apex (6) Sharing and Visibility (6) design pattern (6) developer (6) report (6) salesforce release (6) service cloud (6) trailhead (6) Lightning Experience (5) New Features (5) SOQL (5) css (5) dashboard (5) debug (5) formula (5) mobile (5) solution management (5) use case (5) JSON (4) Kitchener User Group (4) Lightning Web Component (4) Sales Cloud (4) Salesforce DX (4) Tips (4) WebSphere (4) best practice (4) cast iron (4) component (4) deployment (4) event (4) github (4) html (4) polymer (4) profiles (4) responsive (4) tdd (4) ui (4) Architect (3) Live Chat (3) Online Event (3) Opportunity (3) Performance (3) Products (3) REST (3) Role (3) Salesforce Certification (3) Scratch Org (3) Study Notes. (3) Summer15 (3) Web Technology (3) automation tool (3) dynamic apex (3) license (3) map (3) mapbox (3) release (3) singleton (3) version controlling (3) visual studio code (3) Asynchronous callout (2) Aura Framework (2) Bulkify (2) Community (2) Data Architecture and Management Certification (2) Devops (2) Distributed Version Controlling (2) ES6 (2) Eclipse (2) Einstein (2) Enterprise Territory Management (2) Financial Services Cloud (2) Force.com IDE (2) Governor Limit (2) Groups (2) IBM (2) Implicit Sharing (2) JourneyToCTA (2) Lightning Design System (2) Lightning Feature (2) Live Agent (2) Metadata (2) PD II (2) Price Book (2) SOSL (2) Sharing (2) Spring 15 (2) Summer17 (2) Territory (2) Virtual Event (2) ant (2) basic (2) chatter (2) coding (2) communication (2) configuration (2) console (2) controller (2) documentation (2) dreamforce (2) flow (2) git (2) jquery (2) logging (2) object (2) permission (2) process builder (2) salesforce1 (2) strategy (2) xml (2) Action Plan (1) Action Plan Template (1) Activity Timeline (1) Advanced Currency (1) Agent Productivity (1) Analytics (1) Apex Sharing (1) AppExchange (1) Arrow (1) Article (1) Asynchronous Apex (1) Batch (1) Bots (1) Browser (1) Bulk data load (1) CTA (1) Calendar (1) Canon (1) Case Management (1) Celebration (1) Cheat Sheet (1) Classic (1) Compare (1) Confetti (1) Constructor (1) Contact Center (1) Continuation (1) Continuous Integration (1) Convert (1) Cookie (1) CumulusCI (1) Custom Metadata (1) Custom Object (1) Custom Permission (1) Customer (1) Dated Exchange Rate (1) Decorator Design Pattern (1) Dev Hub (1) Development (1) Diwali (1) EDA (1) ESLint (1) Education Cloud (1) Email (1) FSC (1) Function (1) Future (1) Global Gathering (1) Goals (1) Guest Access (1) Guest Profile (1) Guest User Sharing Rule (1) Guide (1) HEDA (1) Higher Education (1) Household (1) Husky (1) IDE (1) Ideas (1) Improvement (1) KPIs (1) Knowledge Management (1) LWC (1) Large Data Volume (1) LastModifiedDate (1) Manage Currencies (1) Manual Sharing (1) Metrics (1) Multi Currency (1) New (1) New Feature (1) OOPS (1) OWD (1) Omni-Channel (1) Partner (1) Permission Set (1) Person Account (1) Photo (1) Pipeline (1) Platform Developer I (1) Platform Developer II (1) Presentation (1) Prettier (1) Product Schedule (1) Profile (1) Promise (1) Prototype (1) Public Site (1) Query Plan (1) Queueable (1) QuickReference (1) Related records (1) Reports (1) Retrieve (1) Role Hierarchy (1) SAL (1) SFDX (1) Salesfor (1) Salesforce Advisor Link (1) Salesforce Labs (1) Salesforce Optimizer (1) SalesforceDx (1) Schedule (1) Session (1) Sharing Rule (1) Sharing Sets (1) Site (1) Skills (1) Snap-ins (1) Spring 17 (1) Spring 20 (1) Summer14 (1) Summer16 (1) Summer19 (1) Switch (1) SystemModStamp (1) Timeline (1) Unauthorized Access (1) User License (1) Users (1) VS Code (1) Validation Rule (1) Webservice (1) Winter'15 (1) Winter'17 (1) access (1) actionFunction (1) actionPoller (1) actionRegion (1) actionSupport (1) agile (1) app (1) approval process (1) aura (1) awesome (1) backup (1) bitbucket (1) book (1) campaign (1) change set (1) code (1) code coverage (1) csv (1) custom button (1) custom settings (1) customization (1) data loader (1) database (1) delegate Admin (1) describe (1) dom (1) duplicate (1) dynamic (1) equals (1) error (1) field-level security (1) folder (1) ftp (1) generic (1) gift (1) global describe (1) hashcode (1) import wizard (1) jenkins (1) keynote (1) long running requests (1) monitoring (1) mysql (1) page layout (1) personal (1) power of one (1) record type (1) relationship (1) request (1) review (1) sub-tab (1) tab (1) username (1) visual workflow (1) workflow (1)

Popular Posts

Total Subscribers

Total Pageviews

Contact Me

Name

Email *

Message *