Month: October 2018

Apex Code to Assign Territories to Opportunities

Assigning Territories to Opportunities can be done manually, but there is an option by which you can automate this process. This blog post is all about writing Apex class to automate the Territory assignment to Opportunity record.Before I start explaining the Apex code, let me explain two important objects -Territory2Type: This represents the category of Territories(Territory2). Every territory must have a Territory2Type. The important field within this object is Priority, which is used in Opportunity filter to assign Territory to Opportunity.ObjectTerritory2Association: This represents the association between Territory and Object record, which is Account. This is available only if Enterprise Territory Management is enabled.The Apex code is written here in the Salesforce Developer’s guide. The logic is as follows -If the Opportunity’s Account record is assigned to no Territory, then Opportunity’s territory2Id field will be null.If the Opportunity’s Account record is assigned to 1 Territory, then Opportunity’s territory2Id field will be assigned to same Territory record.If the Opportunity’s Account record is assigned to more than 1 Territories, then Opportunity’s territory2Id field will be assigned to that territory record which is having highest priority.If multiple territories are having the same priority, then Opportunity’s territory2Id field will null.Once you have the apex class written, you can configure the Opportunity Territory assignment filter by going into Setup -> Territory Settings and there providing the apex class name. The screenshot is given below -Few important...

Read More

Getting Started with Salesforce DX

What is Salesforce DX?Salesforce DX is a way to shift your development lifecycle and to manage your source of truth. But don’t consider Salesforce DX is going to do any magic, as a developer/release manager/lead you need to come up with your own strategy to manage your releases, other challenges like code conflict, urgent fix etc.Why we need Salesforce DX?I think the best way to answer this is with some real time scenarios.Recently I was working with one of my customer who was having multiple sandboxes like DEV, SIT, QAT, UAT. A typical scenario. Now every time there was any kind of production issues, development team tried to find out the root cause and also tried to find out if the issue was due to some of the recent releases. But since all sandboxes were having the same code as Production, there was no way to find out previous code base. So in this situation normally developer request for a new sandbox with production code and fix the issue. This type of development is known as “Org Based Development”.But consider if the code was present in some source control repository then developer can easily get the previous code base, compare code between recent releases (basically comparing between master and branches). But does that really solve our problem? Somehow, but not fully. So basically we need to create an org...

Read More

Archives