Streamlining Bitcoin Customer Onboarding with Salesforce Triggers
Block Height: #838351
In today's fast-paced business environment, it's crucial to optimize processes and minimize manual effort. This is even more true within the Bitcoin business ecosystem.
Let's imagine you are a Salesforce Admin/Developer at a full-service Bitcoin Financial Services Company, your company provides many useful products and services for your clients that allow them to seamlessly and efficiently maximize many aspects of their Bitcoin adoption journey.
But first, you need to get them onboarded to your platform! Customer onboarding can be a complicated and a manual process prone to human error and let's be real, just plain slow. Now you, as the hero of your IT landscape, have the opportunity to streamline the customer onboarding experience by using the power of Salesforce triggers!
In this blog post, we'll explore how creating a trigger on the Opportunity object can automate the creation of two records your company might use if they offer strategic planning and execution for customers:
- Stacking Plan - We all have our stacking goals, so this record is created to track and create a detailed plan on how your company will assist in helping your customer reach their Bitcoin Stacking goal.
- Cold Storage Plan - What kind of multi-sig will be used to securely store your customers Bitcoin? 2-of-3? 3-of-5? How about which hardware wallets? Coldcard from Coinkite? Or maybe a Blockstream Jade? This record is an easy way to map out the plan and get everyone on the same page.
Saving time and ensuring a seamless transition for new customers.
Why Triggers Matter and why it is our tool of choice
Salesforce triggers are powerful tools that allow you to automate actions based on specific events or conditions. By utilizing triggers, you can eliminate manual tasks, reduce the risk of human error, and improve overall efficiency. In the context of customer onboarding, triggers can play a vital role in ensuring that the necessary records are created automatically when a new business opportunity is closed.
If you are familiar with other automation tools within Salesforce like Workflow Rules or Flow then you might be wondering, why not just use one of those?
Why you use apex code?
Bottom Line: Because they are cool and we want to show off.
I'm joking...kinda. But no, good question - since this automation scenario requires that we create records and it impacts other objects, that rules-out workflow rules ;). And yes, we probably could accomplish this in Flow, but since this scenario is core to your business you might want to add more complexity and business logic over time that would be better done in Apex.
New Deal has been Closed and Won
Let's get back to your company! when a new business opportunity is successfully closed, it's time to transition the customer to the onboarding and delivery phase. This involves setting up their Stacking Plan and Cold Storage Plan. Manually creating these records for each new customer can be time-consuming and prone to errors. That's where Salesforce triggers come into play.
We got our finger on the Trigger
To automate the creation of Stacking Plan and Cold Storage Plan records, we'll create a trigger on the Opportunity object. The trigger will check the Stage field, and if it is set to 'Closed/Won', it will automatically create two new records related to the Account associated with the Opportunity.
Here's an example of how the trigger code would look:
trigger OpportunityTrigger on Opportunity (after update) {
List<Stacking_Plan__c> stackingPlansToInsert = new List<Stacking_Plan__c>();
List<Cold_Storage_Plan__c> coldStoragePlansToInsert = new List<Cold_Storage_Plan__c>();
for (Opportunity opp : Trigger.new) {
if (opp.StageName == 'Closed/Won' && Trigger.oldMap.get(opp.Id).StageName != 'Closed/Won') {
Stacking_Plan__c stackingPlan = new Stacking_Plan__c();
stackingPlan.Account__c = opp.AccountId;
stackingPlan.Name = opp.Account.Name + ' Stacking Plan';
stackingPlansToInsert.add(stackingPlan);
Cold_Storage_Plan__c coldStoragePlan = new Cold_Storage_Plan__c();
coldStoragePlan.Account__c = opp.AccountId;
coldStoragePlan.Name = opp.Account.Name + ' Cold Storage Plan';
coldStoragePlansToInsert.add(coldStoragePlan);
}
}
if (!stackingPlansToInsert.isEmpty()) {
insert stackingPlansToInsert;
}
if (!coldStoragePlansToInsert.isEmpty()) {
insert coldStoragePlansToInsert;
}
}
In this trigger, we first create two lists to store the Stacking Plan and Cold Storage Plan records that we'll be inserting. We then iterate over the updated Opportunities in the trigger context.
For each Opportunity, we check if the StageName has changed to 'Closed/Won'. If it has, we create a new Stacking Plan record and a new Cold Storage Plan record, populating the Account__c field with the AccountId from the Opportunity. We also set the Name field of each record to include the Account Name for easy identification.
Finally, we insert the newly created Stacking Plan and Cold Storage Plan records using the insert DML statement.
Success! You just created an automation that your Account Executives will thank you for!
But, something needs to be created so that your manager will thank you as well...the test class.
Cool Complete Code Coverage
To ensure the trigger works as expected, it's important to create a test class. Here's an example test class for the OpportunityTrigger:
@isTest
private class OpportunityTriggerTest {
@isTest
static void testOpportunityTrigger() {
// Create test data
Account testAccount = new Account(Name = 'Test Account');
insert testAccount;
Opportunity testOpportunity = new Opportunity(
Name = 'Test Opportunity',
StageName = 'Prospecting',
CloseDate = Date.today(),
AccountId = testAccount.Id
);
insert testOpportunity;
// Update the Opportunity stage to 'Closed/Won'
testOpportunity.StageName = 'Closed/Won';
update testOpportunity;
// Verify that Stacking Plan and Cold Storage Plan records were created
List<Stacking_Plan__c> stackingPlans = [SELECT Id, Account__c, Name FROM Stacking_Plan__c];
List<Cold_Storage_Plan__c> coldStoragePlans = [SELECT Id, Account__c, Name FROM Cold_Storage_Plan__c];
System.assertEquals(1, stackingPlans.size(), 'One Stacking Plan record should be created.');
System.assertEquals(testAccount.Id, stackingPlans[0].Account__c, 'Stacking Plan should be related to the test Account.');
System.assertEquals(1, coldStoragePlans.size(), 'One Cold Storage Plan record should be created.');
System.assertEquals(testAccount.Id, coldStoragePlans[0].Account__c, 'Cold Storage Plan should be related to the test Account.');
}
}
In the test class, we create test data by inserting a test Account and a test Opportunity. We then update the Opportunity's StageName to 'Closed/Won' to trigger the creation of Stacking Plan and Cold Storage Plan records.
Finally, we verify that the expected records were indeed created and related to the test Account using System.assertEquals assertions.
Viola! Now your dev and deployments lead can get your covered trigger to production!
The Bullish Case for Your Trigger
By implementing this Salesforce trigger, your company can reap several benefits:
- Streamlined Onboarding: The trigger automates the creation of essential records, ensuring a smooth transition from closed opportunity to customer onboarding.
- Time Savings: Manual effort is significantly reduced, allowing the team to focus on more value-added tasks.
- Improved Accuracy: Automated record creation eliminates the risk of human error, ensuring accurate and consistent data.
- Enhanced Customer Experience: The streamlined onboarding process leads to a better customer experience, as customers can promptly finalize their Stacking Plan and Cold Storage Plan.
Boom. That's it for this guide. I hope you have found a solution you can take and implement in your org to help your customer onboarding & account management teams with. If so, or if you have any questions or suggestions for my next post, I would love to hear from you! Feel free to shoot me a follow and let me know on Twitter/X @hodltwashington or @hyperbitlabs
Until next time.
HODL T.