Category: Apex

Restrict Uploading Files In Salesforce

While working in Salesforce, we sometimes come up with the requirements where we need to build some sort of validation to restrict uploading files with specific extensions or in other words, allow only approved file types/extensions. This is very important because uploading executing or javascript code can bring potention security concerns by exposing internal data to outside world.

So allowing only certain type of files for upload is a very common requirement. In this blog post, I am sharing couple of solutions with pros and cons to implement this requirement.

Read More

10 Apex Programming Best Practices

Apex is a strongly-typed, object-oriented programming language that allows developers to execute flow and transaction control statements on the Lightning Platform. It is a key component of the Lightning Platform and allows developers to build robust business logic and integrations. There are a number of best practices that Apex developers should follow to ensure their code is efficient, maintainable, and scalable. Below are ten tips for writing high-quality Apex code. You can read – Lightning Web Component Best Practices Salesforce Flow Best Practices 10 Apex Programming Best Practices Use of "sObject" Data Type Use the “sObject” data type when...

Read More

How to Convert Leads to a Person and Business Account at the Same Time | Spring 21 New Feature

 If in your Salesforce Implementation, you are dealing with both individual and group accounts, then with the release of Spring 21, now you can link your converted leads into both individual and group accounts with the new LeadConvert Methods.Note This feature is only available in Enterprise, Performance, and Unlimted Editions.VideoIf you prefer video, here is the youtube video MethodsThe new LeadConvert methods will allow you to link converted leads into a business and person account instead of a contact. Below are the methods available -getRelatedPersonAccountId() – Gets the Id of an existing person account to convert the lead into.setRelatedPersonAccountId(String personAccountId) – Sets the Id of an existing person accoung to convert the lead into.getRelatedPersonAccountRecord() – Gets the entity record of a new person account to convert the lead into.setRelatedPersonAccountRecord(Entity relatedPersonAccountRecord) – Sets the entity record of a new person account to convert the lead into.LeadConvertResult class holds the result of the lead conversion.Example 1The below example uses the existing personAccountId to convert the lead into. After the execution of this method, lead with id leadId will be converted into both business account with id businessAccountId and person account with id personAccountId.public static void convertLeadWithExistingPersonAccount(String leadId,     String businessAccountId, String personAccountId, String opportunityId) { Database.LeadConvert lc = new Database.LeadConvert(); lc.setLeadId(leadId); lc.setAccountId(businessAccountId); //New Method to use the existing person account id to convert the lead into. lc.setRelatedPersonAccountId(personAccountId); lc.setOpportunityId(opportunityId); lc.setSendNotificationEmail(false); LeadStatus convertStatus = [SELECT                   ...

Read More

Top Apex Features From Spring 21

Spring 21 is bringing a couple of Apex features that can be definitely helpful. This post will cover a few of my favorite Apex features from Spring 21.You can find all my Spring 21 release posts here.Feature #1With Spring 21, we can fetch the entire custom metadata records or a single record from the custom metadata. So no more SOQL query to fetch custom metadata records. Here is the video where I have explained the feature. With getAll() method, now we can get the entire custom metadata records. Here is the small code snippetpublic static void fetchAllMetadata() {    Map<String, Country__mdt> allCountries = Country__mdt.getAll();    System.Debug(‘allCountries Size: ‘ + allCountries.size());    for(String countrName : allCountries.keySet()){        System.Debug(‘Country Name: ‘ + countryName + ‘ Capital: ‘             + allCountries.get(countrName).Capital__c);    }}With getInstance( recordId ),  getInstance( qualifiedApiName ), getInstance( developerName ) method, now we can get the single custom metadata record. Here is the small code snippetpublic static void fetchCapital(String countryName) {    Country__mdt singleCountry = Country__mdt.getInstance(countryName);    System.Debug(‘Country Name: ‘ + countryName + ‘ Capital: ‘         + singleCountry?.Capital__c);}Feature #2With Spring 21, we can now convert 18-character Id to 15-character Id. Here is the video where I have explained the feature. With to15() method, now we can get the 15-character Id of the corresponding 18-character Id. Here is the small code snippet.public static void convertId(String id_18) {    ID test18 = id_18;    System.Debug(’15 Digit ID: ‘...

Read More
Loading

Earlier Posts

  • 2024 (28)
  • 2023 (47)
  • 2022 (25)
  • 2021 (35)
  • 2020 (41)
  • 2019 (13)
  • 2018 (16)
  • 2017 (14)
  • 2016 (18)
  • 2015 (74)
  • 2014 (20)