Dependency Injection part 2

Patterns
Dependency Injection We have seen that we can utilize the Apex Type class to give us some kind of "dynamic processing", well, not quite yet. It's true that we can simplify things now but there are a couple of components in our structure that are still missing. So far we have one interface and two classes that are implementing our interface. Now we are going to add the dynamic part that makes dependency injection so powerful.  All we want is to supply our code with the correct class based on the user that is executing the apex transaction. We want this to be dynamic and we want one line of code to make that decision for us. Should I go 'right', should I go 'left'... we need to control de 'cross-road' and…
Read More

Dependency Injection

Patterns
Dependency Injection If you search for Dependency Injection you will find out that it has been around for quite some time. It is basically a technique on software development that allow us to remove any explicit dependencies as part of an apex transaction. In simple words we can say that this technique allows to "feed" our code with a particular class/es "dynamically".  I like to see it as some kind of "cross road" in which either way can be taken based on a particular logic. We can control the "dynamic" part with Custom Settings or Custom Metadata. This is an important piece of our puzzle because it is the one telling our code where it needs to go next.Which "road" to take from the "cross road"... Scenario We are going to take a…
Read More

Delete LWC with Developer Console

Center Blog
Delete LWC with Developer Console This a simple way to query your LWCs and delete them if you have to, with all their consequences. If you are sure that there is not harm by doing it, you can just search for the LWC you want to delete using the Developer Console. There are some situations in which you could delete a LWC for a particular reason. I had once a situation in which I was trying to create a Lightning Component with the name: AccountMap And I got an error that I was not sure, initially, the reason why... The reason was that I had a LWC with the same name and that was not allowing me to create a LC. I renamed the LWC to AccountMapLWC hopping that this…
Read More
Access SObjects names dynamically from a List<SObject>

Access SObjects names dynamically from a List

Apex
Access SObjects names dynamically from a List A simple way to do this is by using getSObjectType().getDescribe().getName(); You can run that piece of code in your developer console. [code lang="php"] /********************************************************************** * * Access SObjects names dynamically from a List ************************************************************************/ List<SObject> objects = new List<SObject>(); Account account = new Account(Name = 'AccountSObject'); Contact contact = new Contact(LastName = 'ContactSObject'); objects.add(account); objects.add(contact); System.debug(objects.size()); for(SObject sObjectNames : objects) { String sObjName = sObjectNames.getSObjectType().getDescribe().getName(); System.debug(sObjName); } /* * */ [/code]
Read More
Creating a LWC Bitcoin Currency Converter

Creating a LWC Bitcoin Currency Converter

LWC
Creating a LWC Bitcoin Currency Converter We are going to add a Lightning Web Component that will be part of the Home page of our Salesforce environment. This LWC will make a callout to get currencies updates. Ideally you want to perhaps use a Quick Action or some other mechanism to stop making unnecessary callouts if you are not going to use the converter. For the sake of this tutorial we are just going to think that we have unlimited callouts and we don't really care if we make a callout out every time we open our Home page... uh-huh! We will be creating something like this:  We are going to look to several things that will allow us to give a feel or style to this component using very…
Read More
Populating an inner List in a Map

Populating an inner List in a Map

Apex
Populating a inner List in a Map collection A simple way to populate a list that inside a map collection could be done like this.You can run that piece of code in your developer console. [code lang="php"] /********************************************************************** * * Populating a List inside a Map collection * ************************************************************************/ List<Account> acclist = [SELECT Id, Name, (SELECT Id, lastName FROM Contacts) FROM Account LIMIT 50]; // This map will be contain the list of contacts as values and the // account ids as key. Map<Id,List<Contact>> accConMap = new Map<Id,List<Contact>(); for(account acc : acclist) { List<Contact> innerList = new List<Contact>(); for(contact c: acc.contacts) innerList.add(c); accConMap.put(acc.id, innerList); } // accConMap.put(acc.Id, innerList) will insert key and values to our map // [/code] As you can see it is quite simple.All you need to do…
Read More
Aborting Apex Jobs

Aborting Apex Jobs

Apex
Aborting Apex Jobs THere is a way to abort Apex Jobs that can be easily acomplish from the developer console. If you open an anonymous window in your developer console you can use the following SOQL. [code lang="html"] /*************************************************************************** * * Running this SOQL in an anonymous window will get information about all * active apex jobs in your org. * ****************************************************************************/ List&amp;amp;amp;lt;CronTrigger&amp;amp;amp;gt; crontList = [SELECT CreatedById, CreatedDate, CronExpression, CronJobDetailId, EndTime,Id, LastModifiedById,NextFireTime, OwnerId, PreviousFireTime, StartTime, State, TimesTriggered FROM CronTrigger]; // // [/code] CronTrigger "Contains schedule information for a scheduled job". Get the Id of the job you want to abort and execute this line on an anonymous window. [code lang="html"] // This line will abort the first entry on the crontList. // You need to make sure you have the…
Read More
From Picklist to SelectOption

From Picklist to SelectOption

Center Blog
From Picklist to SelectOption There are occasions in which you want to build an user interface that will not save records and it just interacts with the user input data. Something like a search engine or a currency converter app. In some cases, it is better to use SelectionOption than Picklist in your app. We can easily do this by using the Schema system class. As we know the Schema class "Contains methods for obtaining schema describe information".In this class, we can see how to pass all the values from a picklist to a List of SelectionOption. [code lang="php"] /********************************************************************** * * From Picklist to SelectionOption * ************************************************************************/ public without sharing class ConverterSupportClass { public List<SelectOption> CurrencyOptionsOne {get;set;} public List<SelectOption> CurrencyOptionsTwo {get;set;} static void ourMethod(){ // Getting all values from…
Read More
Triggers – Send email after deleting a record.

Triggers – Send email after deleting a record.

Trigger
Triggers - Send email after record deletion. There are occasions in which you want to notify a person or a group of people when a record/s has been deleted. To accomplish this you can write a trigger that will send an email to those that need to be informed about this action. We will write a trigger here that will do exactly that, it will send an email to one email address if a record gets deleted. We are not going to write the full logic in the trigger's body. We are going to build a helper class to take care of the execution of our logic and we are going to invoke this helper class from all class. So let's start by writing out ONE AND ONLY trigger for…
Read More