Run Step Group
Breezz also offers running a group as a Step. Let’s say you want to create to reach out to your leads and present to them what you have to offer. Of course we won’t get too much into things like marketing approaches, templates and actual offers. Here we will just make an example that can be improved upon. First of all create trigger on Lead object, just like this one:
1trigger LeadsTrigger on Lead (after delete, after insert, after undelete, after update, before delete, before insert, before update) {
2 forvendi.BreezzApi.TRIGGERS.handle();
3}
Next up, create a class that will accommodate our logic. Here is an example. But what does it do? So first we check if this lead has not already been contacted, then we create a simple SingleEmailMessage, which is not optimal but will be enough for this example, and if email was successfully sent we update the status of the lead to “Prospect - Contacted”.
1public with sharing class LeadEmailProcess extends forvendi.Step{
2
3
4 public LeadEmailProcess() {
5 super(LeadEmailProcess.class.getName());
6 }
7
8
9 public override Boolean initRecordProcessing(Object record, Object optionalOldRecord) {
10 // gathers information from lead object and sends greeting email
11 // in case message was successfull change status to contacted
12 Lead newLead = (Lead) record;
13 if(newLead.Status == 'Prospect - Not Contacted'){
14 if(isNewOrChanged(newLead, (SObject)optionalOldRecord, Lead.Email) && newLead.Email != null){
15 Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
16 mail.toAddresses = new String[] {newLead.Email};
17 mail.subject = 'Hi,' + newLead.LastName + ' check out our catalogue';
18 mail.plainTextBody = 'This is the message body.' ;
19 Messaging.SingleEmailMessage[] mails = new List<Messaging.SingleEmailMessage> {mail};
20
21
22 getContext().addToSend(mails);
23 getContext().addModificationToUpdate(newLead.Id, Lead.Status, 'Prospect - Contacted');
24 }
25 }
26 return false;
27 }
28}
Now create a Breezz Trigger, after update will be just fine, set Create Default Step Group to yes. After successful deployment head to created group and add new custom type Step and add LeadEmailProcess class above to the configuration. Next up we will create another Step. Create a simple class that extends forvendi.Step, which we will use to convert a lead record , for example just like this one here:
1public with sharing class LeadConverter extends forvendi.Step {
2 public LeadConverter() {
3 super(LeadConverter.class.getName());
4 }
5
6
7 public override Boolean initRecordProcessing(Object record, Object optionalOldRecord) {
8 // if condition is met, using addToConverta and class we create account, contact and opportunity
9 // based on lead record information
10 Lead lead = (Lead) record;
11 List<Database.LeadConvert> leadsToConvert = new List<Database.LeadConvert>();
12
13 if (lead.Status == 'Closed - Converted') {
14 Database.LeadConvert lc = new Database.LeadConvert();
15 lc.setLeadId(lead.id);
16 lc.setConvertedStatus('Closed - Converted');
17 leadsToConvert.add(lc);
18 }
19 getContext().addToConvert(leadsToConvert);
20 return false;
21 }
22}
There is no doubt that between first contact and lead conversion there is much work to be done, but here we can skip it to highlight Breezz functionality. Create a Step Group called LeadProcessing which will contain our new quick converter. Go back to the auto generated group connected with Breezz Trigger and create a new Step. Configure it to look something like this.
Now after making sure all our components are active try to create a new lead record save it a try to cause any of these two actions to be executed. First set an email address to your personal email and save. You should have a new email (check out spam folder ), and second should be triggered after manually setting lead status to whichever has its IsConverted set to true.
In this case it’s Closed - converted.