Record Triggered Flows with Real Time Scenarios

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone my name is srikant today we are going to learn record trigger flows with some real-time scenarios by end of this video you will be able to understand what is record trigger flow why and when to use record trigger pros and we'll also see how different is with epic stickers as the names are matching even the functionality does match with record trigger flow and apex triggers and along the way we'll see some real-time scenarios to have a better understanding first things first you would have seen this image somewhere in instagram or in facebook right this image exactly represents the current situation salesforce so if you see we already have automation tools like workflow process builder and pros right still salesforce is more focusing on flows leaving behind workflows and process builders at this moment also at this point or with this current release flows is already far behind workflows and process builder because flows has multiple features still salesforce is improvising more and more and leaving behind workflows and process filters to keep it simple lamp flows as quickly as possible coming to flows flow is really a powerful tool which is having multiple capabilities that is the reason you are seeing five different types of flows each of the type will be having different abilities for example screenflow can create user interface which none of the other types cannot create in the same way record trigger flow can be called whenever a record is inserted updated or deleted which is not possible with any other type of flaw i already made a video which covers both screen flow and auto launch flow you can access that video by clicking on the information icon on the right top or i will also add video link in the description you can check that if you have any queries so if you people want me to do video on scheduled trigger flow or platform event flow comment it down so that i will do it accordingly so now today's hero which is record trigger flow will try to understand what it is in the first place record trigger flows will be configured whenever a record is inserted updated or deleted so in these three scenarios if you wanted to do some actions like updating on record or updating any other objects records or sending emails or sending custom notifications creating records etc etc so if you want to do all these actions whenever record is inserted updated or deleted then we need to go ahead with record trigger flow wait wait wait this is something workflows and process builder does right then why this record triggered flow has been introduced first things first process builders cannot do any actions whenever record is deleted we have the other differences also let's see that now if we see here we can configure record trigger flow to perform some actions in the below events before insert after the insert before the update after the update and before delete also so if you see whenever we create process builder or workflow it will ask after the record is created or updated which means process builder or workflow will work only on the after events which means after insert after the insert if you want to perform some actions you can choose process builder and workflow in the same way for after update also if you want to perform some actions you can do with process filter and workflow but with flows you can perform any action in all these events which are before insert after insert before update after update and before delete there are some actions which can be performed in both before insert and after insert in those cases there is a chance that before insert would be the ideal solution in this case flows are really helpful to optimize our performance didn't get it it's fine we will be seeing these scenarios in the coming slides there i will explain it more clearly before going to the scenarios we need to understand behind the scenes what will happen whenever a record is inserted or updated now as a user whenever you create a record or update the record and update the field values and click on save it will not directly insert or update into the database salesforce will make a wall tool before it inserts or updates data into salesforce additionally it will make another world tour after the insert or updating is done on that butler record you don't believe me let me show that to you this is the world tour i am talking about so whenever you provide values in create form and then click on save it will not directly go into the database instead it will go to the flow first and then it will go to the effects trigger and then after it goes to database it will again go to fx trigger and then workflow and then to process builder and finally it will execute flow again which is in after insert so when i have explained the events in flow i told before insert after insert right so these are those insert events so before the insert event and after the insert event before and update events will be shown whenever you update it so that is something which i will show in a different flowchart so in here the sequence is something which i am not defined this is something which salesforce in their official page whenever you wanted to perform some action automatically on insert you can put your logic in any of these six blocks however workflows is something which is outdated now don't use it at this point of time and process builder is something which you need to do it for existing processes and flow is something which you need to use it more often and if flow is also not able to do some complex scenarios then you need to go for apex trigger now we have before insert and after insert right as i said you can put your logic anywhere in these six blocks whether you write you can also you can also leave it empty so already blows are there you can write your logic or not already triggers are there you can write your logic or if it's your wish based on the requirement whether you write it or not salesforce will definitely check all the blocks to see if you have written any logic and executes them if there is any so this is how the flowchart works whenever you insert it as we understood this is the order of execution whenever you insert a record we need to understand what are the tools that are under before events and what are the tools that come under after the events as the name suggests anything that happens before the database installation will be under before event and anything that come under of database insertion will come under after events now the question is whenever a requirement comes how do we know whether we need to use before even components or after even components let us discuss about before events and after events so whenever user clicks on insert so it will go to database where you are passing this before block we should use this before block to pre-populate any field on the same record with this we will actually save an extra dml operation i will explain you how we are saving extra dml operation here let's assume your friend wants to correct something so she needs to travel from her house to career office however your house is in between her house and career office so definitely she needs to go through your house now you want to send courier also as she's anyhow going through your house you will give your package to her so that she will take your package and her package and goes to courier office so by this way you're actually saving yourself traveling to the career office right taking this analogy let's do a comparison here so so your friend who is taking your package is similar to the person who is clicking on uh save by entering so and so values so the package here what that your friend is holding is the values whatever the user clicked on providing the values and then click on save now uh the courier office is something your database now this house your house would be before block so whatever you want to pre-populate is something which is which needs to compare it as your package so on clicking on save it goes through the before block which means your friend goes through your house and in the people block if you keep repopulating logic which means your package so your friend will take it to you in the same way salesforce will take the existing data that user has provided and along with the pre-populating logic that you provided in the before block and it will be sent to database like both of your couriers will be reached to courier office in this way you can save yourself a dml operation by putting your logic in the before block we need to use after even block when you want to update any other object records let's say when an account is inserted and if you want to update contact records related contact records use after insert block something like you can use after insert flow after insert epic trigger and you can also use workflows process builders and if you want to send some emails or calling some external web services you can use after insert block or after update block and also whenever you want to use certain system fields which are last modified by last modified date record id created date created by all these things will be available after the insertion or updation happens so if you want to do or if you want to perform some actions on this particular fields then also you need to go for after event clock so a simple thumb rule is if you want to pre-populate any field on the same record go with before event in any other case go to after events as simple as that hope this is clear with this we can come to a conclusion and we'll create the thumb rule here so if we need to update or pre-populate any field or fields on the same record which trigger the flow then we need to go with before flow event it can be before insert or before update in any other condition jump to after flow events which is insert or update any other condition in sense updating of any other objects record sending of email sending of custom notifications creation of records deletion of records etc etc etc remember this thumb rule it will be very handy in our coming scenarios hi everyone i have a problem here while inserting an account if user provides billing address and doesn't provide shipping address update shipping address automatically with the billing address how to achieve this this is very much possible with salesforce loss with record trigger flow and before insert event okay guys this is brand new so people who want to learn do along with me and another good thing is we are using standard objects for all these scenarios basically what cuba is asking is whenever account is getting created let's say test account and then if we scroll down we have billing address and shipping address if billing address is populated with all the values with billing city billing state and zip code and support and country and then if you click on save and if shipping address is not provided then all the values of the billing address has to be copied over to shipping address accordingly so if i click on save that should be copied over however this is not a static functionality so this is something which we need to build we can easily do with salesforce flow that doing before insert trigger let us see how we can create flows in salesforce so click on setup and in setup search for flows and under process automation click on close it will take us to the close home screen in this floor's home screen we need to click on new flow which will take us to the close filter here we need to select the type of flow so we have five different types of rows however we need to select record trigger flow so we need to select record trigger flow why because whenever a record is created or updated or deleted if you want to perform some action then you need to select record trigger pro so in our scenario we need to update our shipping address based on billing address when our account is created right so that's the reason we need to select record trigger flow and then click on next now always select auto layout so that all your elements will be auto arranged now it will ask us to select the object so our object is account and now if you see it will ask when this should happen whenever record is created updated created or updated both or deleted so in this current scenario we'll just select a record is created and then we'll go ahead so at this point of time don't select any conditions all the records which gets inserted should come into this flow okay so really don't want set conditions if you want to set conditions you can give some conditions as such now we need to select whether it is past field updates or actions and related records don't worry this is something like this is before the record event and this is after the record event as simple as that the names were a little uh updated like this but this is basically before and this is after so before we need to select whenever you want to update fields on the same record then you need to select beforehand in any other conditions like sending of email updating in other other object records or creating new records then you need to select after the event in this scenario we need to update shipping address based on the billing address on the same record so that's the reason we will select this password updates or before insert and then click on done now that we have configured the start element which means basically we are telling flow that whenever account is inserted just before the insert fast field updates is nothing but before just before the insert do some actions what is that action so we will click on plus so what we need to do we need to assign billing address to shipping address assigning is something like assignment so click on assign so now we need to give some label here update oh we can display populate shipping address with billing address and now we need to set the variables now we need to update the shipping address of the record from the billing address of that record right so we will get that record let's see that user enters some data in the form like account name date etc and click on save that data will go to before insert flow so in the before insert flow that data so far that user has entered will be saved in dollar record so this is standard feature that salesforce queue so if you want to access that value you can just access with dollar record dot billing city or billing address accordingly so let's say you wanted to like in the previous scenario if you wanted to update shipping address with the billing address this is how you would do dollar record or shipping address is equal to dollar record or billing address so the billing address that's already typed by user will be copied over to shipping address same with the required shipping cities equal to billing city it's same for any other fields if you want to access any of the field of that record that user has entered you can you can access by using dollar record and once it is done it will directly go to db and that dollar record as the dollar record will be sent to date database and that will be inserted accordingly now that we have understood record variable holds the value that user has entered so from user interface whatever you enter it will come into record variable and sits in flow so it will be available in flow so we need to search for that so if you see in the variable we have the record so click on record and it will show all the fields so we need to select shipping address here so shipping address we cannot directly give here because this is a compound variable or compound field so when i say compound fill it is mixed of other fields shipping city shipping country shipping state street and core all all of these five fields combined they call the shipping so that's the reason we cannot directly use shipping address then how we need to do so then we need to sell each of the fields directly so shipping street so we need to select record or shipping street and it has to be assigned with again the same record which will be available in close global variable is record so record is something which is standard standard uh field or standard variable close which you will get the value from user interface so click on record again so what is the value that we need to give as this is shipping address in the left side we need to provide billing street billing straight billing straight and big so shipping street equals billing street like any programming language whatever value you see in the right will get assigned the left side shipping street equals to billing state which means billing street value will get copied over to shipping street so in the same way we need to read for other five fields also so same thing record and then find shipping now we'll search for city and same drill record here we need to search for billing city to attack next so we have five variables or five fields so commonly we call it as a shipping address which is a compound fee so shipping address equals billing address building street will be copied out of shipping street billing city to shipping city billing country to shipping country billing state to shipping state billings it too but shipping site and click on that so we have we can do multiple assignments in this single assignment it's some single assignment uh element itself so click on that so the first trigger says on account whenever it's in cells just before the insert populate shipping address with billing address in the way which we just should just shown here okay click on done and then save give some name here but give some generic name not very specific to what we have done so account trigger flow so the reason why i have given generic time in the sense so whenever so whenever a new requirements comes you need to update this before trigger or before insert trigger again then then whatever title you give here it will not be justified with the actual functionality so you can add your functionalities here so populate shipping address with billing address okay so whenever a new functionality comes just update here with the new function whatever you have added so in this in this way whenever a new person comes and sees your flow they will understand what are the functionalities of them the same because one flow can accommodate multiple functionalities it's all it's not only for single single assignments okay so i'll just keep it here and then click on save one last click on activate and as it is activated with this is time to just test it out so we have accounts page click on new and give a new account test account one and scroll down give some billing addresses building mattress click street the city okay and billing country and click on save so our expectation is whatever value we type here will be copied out to shipping address click on save if there is any issue it wouldn't get saved if there is an issue with your flow so click on details so you see billing address is copied or to shipping address and vola as per this scenario we have added our populate shipping address with billing address logic in flow before instead so on clicking on save this will be considered curve and next it will be called apex trigger which will be empty and then we'll go to database it inserts but will not commit and then it will again go to a page trigger and then the workflows and then to process builder and then through flow opt insert and then it will commit our record now come second thumbnail so whenever a requirement is given to you check this scenario and see if it is possible with all these three workflow process builder and flow if it is possible with all of them then go with flow because workflow is outdated process builder as per salesforce process builder has to be used for the all existing processes which we already created right in your previous requirement sensor only those you need to update your process builders don't create new process filter for any new requirements so for those you need to go with flow so if it is possible with three of them if yes then go with flow so within that flow itself you have before and after events right so within the flow if you want to decelerate between before and after then follow previous tumble which is if you want to pre-populate any field on the same requirement then choose before flow or after flow so this is based on requirement check the requirement and if it is possible with all these three choose flow within that flow itself if we want to choose whether it is before and after check if it needs to be preproporting any field on the same record if yes go with before flow as simple as that okay scenario number two whenever a case is created send an email to case owner with a deadline to resolve it okay this can be done in record trigger flow with after insert event now we'll create a new flow here so click on new flow and here whenever as per the requirement whenever case gets created we want to send an email so record trigger flow is something which will be called whenever a record is created updated or deleted so select this record workflow and click on next i will always select auto layout because it will arrange the elements properly here we need to select the object so in this case the object name is case because whenever case is created then some action has to happen so here i will select a record i mean air code is created which is selected so i will keep it as is and the object is case and here i really don't want to put entry conditions entry conditions in the sense whatever object that comes into that got created that gets created will come into this flow if i don't put communications if i put conditions something like whenever a case is created and the case source is something like email only then it comes to the logic then you need to give a condition saying that k source is equal to email or phone etc but in this case i really don't want to put any connection why because i wanted to have all the requests that gets created to come into this flow so i will scroll down and if you see we have two options fast field updates and actions and related records in other words before inserting the record after inserting the record so you remember the thumb rule right so if you are updating any other fields in the same record then you need to go for before update or password updates but in this case we are not really doing that right we wanted to send email and salesforce also made things easier right so update any record and perform any actions like sending a female so our action has to be also sending an email so i'll click on this and i'll say content yeah just one point before clicking on done so you see there is a checkbox this checkbox will be there only in after events so this basically means it will create another thread which will make the transaction which we do it next to run asynchronously so you need to do mostly this when you are calling web services because you really don't know what what would be the result and how much you need to wait for that right so that's the reason whenever you are calling web services from flows you just need to make a check this checkbox so that that transaction will run asynchronously so in this case we really don't want that so i will leave it as is and click on done so now now that we have configured start element it says case object whenever it is created do some action what action sending of email that is something which we need to do it by clicking on this plus and we need to select send email action so we do not have any send email action it will have it under action interaction element so click on action and search for send email or else you can also click email it should be there somewhere here you can have existing email alert to be selected here or you can also do the same thing which i have done you can directly send send email if we select the send email we can directly create that text body and subject etcetera etcetera here itself so sending i will also make send email to case owner and body so we need to prepare body here so body is basically text right it's an email template kind of thing so we need to create a resource which will have a template kind of thing so click on new in resource and in resource type i can select text template so i will just make it as sample case template and in here body i will give the text so hi a new case has been created and assigned to you i will give case number here directly so as whenever a record gets created that record value will be there in flow in record variable dollar record variable just search for that so record it with case and then click on it and then sorry and then we need to find case number so we have added this case number this will be shown once email get into that person so and along with that we'll add some witty text take as much as time you want to resolve this issue however complete it by evodi today yes we know that you have completed five seasons web series in a single weekend so please don't complain that dead line used to short regards she can't sorry salesforce i think this would do right and click on done so we have a sample body we need to have a sample subject however you can create a new resource with a simple text but this is a simple text right i will just create it as you have a new case but if you want to add case number in the subject also you need to create new resource type and in that text you can mention uh case number like i mentioned in body okay like record dot case number now in the email addresses i will just uh get the case owner comma separated so just click here and then again okay so another details will be there and record again and then i will select created by our owner email done so we have the owner email id here and then i think rest of it should be fine i'll click on done so we have our flow ready and it is ready to get tested but before that we need to save it right so click on save flow number two after insert and it can be case send email to case owner so i i know you need to give some generic names but i'm just keeping like that okay or else whatever it is just keep it here and then click on save and activate so we have our flow activated we just need to test it now so we'll quickly test it go to home and then search for cases object so we have our cases tab opened and now i will click on new so we'll create quickly create a case status new case origin to phone and then i think that should be it our subject is some subject test case subject i think that should do yeah i click on save so the case owner is me so i should be receiving an email so case got saved let me check if i got email now if you see the email we got the email we have a new case however we got the case number also but however we have this html tags right so we have done a small mistake while we are creating that even template so let us go back and update it the flow so go to flow builder and if you open this email alert again click on edit tl element and if we scroll down so this is something which we need to enable reach text formatted body so we just need to include it and now we need to give saying that it's true so we have global variable call true which is flow variable just click on true and then global constant are true which is basically enabling the rich text format and then click on done save as save and activate it so we just enable that fixed text area i mean reach text format and then we'll go back here and we'll quickly clone it clone i'll just say the subject and then click on save now we should be getting we should be getting a new case see we got a new case saying that you have a new case report from we'll just see click look safe hi and your case has been created and assigned to uk with case number this is the case number right two nine see this is how you can send emails from salesforce you can create your own email templates within the flow itself or you can also have existing you can also use your existing email alerts very simple right now with this scenario we have added our send email logic in flow after insert but this flow is related to case because when our case is created we wanted to send an email so on case insert we have a different flow which is this and we have added our send email case the previous one is on account so that is a different flow on insert okay so that's the reason it had uh populating shipping address here and this is empty and here this is case instead flow that's the reason we are having here and this is empty okay okay another scenario if an opportunity revenue value changed more than ten thousand dollars compared to the previous value add a comment in the description field mentioning revenue changed more than ten thousand dollars okay this can also be done with record trigger flow but with before update event let's see that how let's understand what is the requirement here is so as cubi has mentioned when the opportunity revenue is changed which means this should apply for all the existing records not for the new records because when the revenue is changed and the change is greater than ten thousand dollars then something should happen so you see the revenue so we'll take one of the revenues will will take the amount so basically when i was here revenue will take amount value so the current value is 2 lakh 35 000 right so but if the value is more than 10 000 so let's make it as 20 so let's make it as one back so earlier it was to like 35 000 now it is just one lakh now if this change happens then the description field should have the comment saying that uh the change has happened but then the value is more than ten thousand so i'm clicking on save so now there will not be any change but whenever the change happens the description has to update like that so let's see how we can do that we'll go to close home page and click on new flow here as this is on update whenever values gets update that something should happen so click on record trigger flow click on next and auto layout again and in the flow builder the object name is opportunity now because an opportunity whenever the amount or revenue changes this should happen so as as the requirement says whenever the revenue changes which means it's all for the existing records so that's the reason we need to select update because only existing existing opportunities we can update right so we have selected the update i really don't want to keep any entry conditions here i will leave it like that now we have two options again pass field updates actions and related contacts which is before event after event now the thing is as per the requirement whenever the amount changes it should up it should add a comment in description which we need which means we need to add or pre-populate the description field on the same record so as per the thumbnail if we are updating the same records fields we need to select before event or password update so click on that and then click on done now we are saying in opportunity object before the record gets updated we want to check whether what is the previous value and what is the current value and define the difference if the difference is more than 10 000 then we need to add the comment so first thing is we need to check the difference right and also we need to check whether it is greater than 1000 or not so to check a condition we need to add a decision box click on decision now check if current revenue current amount value is greater than 1000 10 000 than previous amount value so this is the ap no so we need to find if yes so we need to write conditions right now to find what is the previous value and old value salesforce have some variables whenever user updates a record it will go to database and before it goes to database it will go to flow before update block after hits the database it will again call flow after update so whenever it is there in before update or after update block flow holds the given data in dollar record so whatever data that they have given or change it will be there in dollar record however if you want to see what are the previous values then those values will be there in dollar record prayer let's say in the name field the value change from shrikant to shrikant one shrikhand value will be there in player dot name and srikanth 1 will be there in dollar record dot name so this is how you can compare the previous value and the current value and then see if there is a change and based on that you can perform your logics in this scenario we are just checking if the value of comments field has been changed so this is how you would check if dollar recorder comments not equal to dollar record player dot comments basically if it has been changed then you can send a mail or you can add that particular value to some new record as logs so this is how you can leverage standard sales force flow variables these are flow variables that are given by standard sales for as a standard sales force features now that we have understood the previous values will be stored in record prayer and the current values will be stored in record variable we will see how we can compare it so we will just search for record we see record and record prayer so record and record prior record we will be available in before after insert also record primary will be available only in before and after update now we'll click on record and we need to search for amount field so amount greater than now it should be this amount should be greater than previous records ammo so prior and then ammo but if you see this is among greater than previous recording mode but we need to see if it is greater than 10 000 right so for that we need to create a formula so click on new resource and then formula should be a number so we'll click on and then we need to create a formula because formula should calculate previous value plus ten thousand dollars so formula and then previous value previous amount value plus ten thousand right now in the data type will give number and the resource record prior and then it should be m1 field and we need to add 10 000 and then click on them now if you see amount value greater than that variable that variable will be having previous value plus 10 000 then we need to update the comment update the description field then we need to update the description okay now click on that so now if yes what should happen we just need to update the description right so what we need to do it's just a simple assignment so assign or add comments and description field so i will just add a comment description field so description field will be available record and then find the description and then add and then give some text okay i will just give text as revenue changed more than ten thousand dollars and then done so this is how we have done so first thing is if the opportunity is getting updated before it gets updated we'll check whether the current value is current amount value is greater than the previous amount value if yes then add the comments saying that revenue is more than ten thousand dollars as simple as that so we'll click on save and then we need to give a flow three before insert trigger and add comments if current amount is greater than previous amount plus 10 000 and then save and then activate now it is time to test so quickly go here and then we can see the existing record itself so currently it is one like dollar straight we just need to make a difference of uh more than ten thousand and we'll see whether it is affecting or not so instead of one end of the one lakh i will make it as online fifty thousand currently the description field is empty and if i click on save you see revenue change more than ten thousand dollars will do a negative test so instead of uh just ten thousand i will only update five thousand so one like fifty thousand i will make it as one lakh fifty five thousand so we just updated only five thousand now it should not it should not have any value in the description now okay after i save it so click on save see no description now again if i will change it to another 2075 and then click on save see the value has changed so see very easy if you see i updated the value to another twenty thousand which means ninety five thousand now and click on save already the value is when you change more than ten thousand if i click on save will get one more revenue change more than ten thousand the reason is it is appending so in the flow when i have assigned or added that comment i have added the operator add so which means it will append the existing description field value if i click equals every time i add a new value change then it will just reassign or like it will get overridden so when you change more than ten thousand dollars will be appeared only once whenever even though you change multiple times also it will be appeared only once overriding one one and all every time okay so in this flowchart we have seen update an opportunity should create a comment in the description field right so that's the reason we need to have a new part which is update path so even in the previous scenarios we'll have we will be having the update pass however as all of them are empty we left it like that so whenever opportunity is updated we will have these blocks so we have full of flow types right which flow events right before insert event after insert event before update even after update event so whenever opportunity is entered inserted it will be following this path and whenever our opportunity is updated it will follow this path so as per the scenario we have added our logic in this flow update so when user clicks on save it will come here and updates this logic and then add the comment in the description field and it will go to the apex trigger before update and then as it is empty it will go to database and updates the record and then again it will come to apex trigger after update and then the workflow and to press builder and to flow after plate and then it will commit its changes every object will be having this kind of similar flowchart on insert update and we also will be having delete also oh god another scenario this guy is literally a mathematics book always full of problems okay let's see this whenever account rating changes from hot to cold delete all opportunities associated with that account yeah this can be done with record trigger flow by using after update event so as the requirement clearly says whenever the rating changes from hot to cold which means it's already created so it's an existing account so if the rating changes from hot to cold so it should be already hot and if it changes too cold then all the related opportunities has to be deleted so currently let's say take this account as an example currently we do not have any opportunities let us create few opportunities before we create flow uh give some of our cheater name as test opportunity and then closed it with so and so and stage with prospecting yeah i think that should do and click on save so we'll do the same again and click on i will create another opportunity test of two and then close date with some values and stage with prospecting and then save so now that this account is having two opportunities and currency rating is hot so if it changes too cold below two opportunities has to be deleted okay so let us create flow first so we go to close home screen and then click on new which will take us to flow builder so whenever it changes whenever the rating updates or the record changes we need to delete those opportunities so we need to choose the quarterly flow why because it is on record update so click on this and next and select auto layout now it will ask the object so we'll make it as account and then it should be on update right so this is on update we want all the records to come in here so we don't want to give any conditions here now here we need to select pass field updates or action self-related records which means before it's before update or after update but if you see we want to delete records of another object whenever account update happens then we need to delete another object request which means a different action so we need to select actions and related records and then click on tap now it basically says whenever account is updated after the account is updated we need to do set an option but we need to give a condition saying that the rating has been changed from hot to cold right so that means we need to have a decision box here again like in the previous scenario so we will click here and then scroll down create a decision box check if rating changed to gold from hot then if yes is one of our outcome then here we can give the condition so we have the record and record prior values right so record current rating and record prior rating so record rating so we have record rating so which will make it as equals to record so current account rating is called and the previous rating is hot so previous rating rating previous records rating i mean previous value rating is not it is both all men all conditions are met so if yes so if the outcome uses which means if current rating is called and previous rating is hot then this condition says yes okay and then click on done now if you see check if the rating change from cold from hot if yes which is our condition where we have given two conditions if the current rating is scored and previous rating is hot then we need to delete those records how to delete the recursive flow so if we click on plus and if we scroll down you already have seen action you have seen assignment you have seen decision we haven't seen loop yet correction sort etc but we haven't seen this data so here we have delete records option so we'll select delete records and then delete related opportunities this ops ops and then we need to find the record collection right so we will specify the condition on a specific object to get those records okay so we will select this to find the object source give the opportunity object name here and now it will ask the condition so what is the condition opportunity will be having account id field right so search for account id field so opportunities account id field should be equals to current account record id there is id id id yeah so this basically says current record is accounted current account record id matching opportunities related options which means it will it this particular query or this particular deletion will bring up all the opportunities all the opportunities which are having account id match with the current records account identity and then click on done do you think it is completed yes it is so in delete we just mentioned select all the opportunities which are related to the current account id and as the operation itself is delete selection it will delete those records automatically because we have selected delete action itself we just told what are the records that it needs to delete now we have done with our flow click on save and then blow for after update delete related opportunities on account rating changed change the mod code okay and then click on save now activate now if we go back to the sub account and then now if we change this rating from hot to cold these opportunities has to be deleted so click on this and then hot to code and then click on save the expectation is opportunities got deleted see now we'll do the negative testing also first we'll make it to heart first click on save meanwhile we will add one more opportunity test of one or two and then and then close it to so and so and then save so we'll just have one opportunity and we'll see if it is getting deleted if we make it too cold from hot instead of changing from hot to cold i will change it to hot to wow and then if i click on save this should that opportunity should not get deleted because our condition is if if it changes from hot to cold only then this opportunity should be deleted even if it from warm to cold it will not get deluded it should not get deleted because the condition is if the previous value is hot and the current value is called only then that should get deleted so i will again change it to hot and then save and it should not get deleted now the rating is hot and now if we change it to gold only then it should get deleted see so this is how you can play with record player and record values and in this scenario you learned how to use delete action as per the scenario we have deleted the opportunities whenever account rating field changed okay now we have added that logic in flow after update so this entire flowchart is on account object so however as per the scenario we already done populating shipping address with billing addressing flow before insert on account object itself as we have done on account object itself it is appearing here and we have done scenario 4 on account object itself that's the reason it is appearing here for scenario one we have done on flow before insert on account object itself scenario four we have done on flow after update on account object itself that's the reason you are seeing both of them let's say when our account inserts this will follow this path and we'll see if the shipping at the same time it will update it accordingly and then inserts the database and if you update any account it checks if the account rating is changed and it will delete the opportunities if the rating is equal to code so that's that is how the flow charts will be there for each of the object so scenario one is on account object scenario t is on case object scenario three is on opportunity object scenario four is on account object again that's the reason you are seeing uh two scenarios blended in one flowchart okay scenario number five whenever account is created or updated if the rating is hot create opportunity with the same name as account so we have a writing field in account so whenever the rating is hot whether it is created or updated then we need to create an opportunity same as account so we can do this with record trigger flow but we need to use two events one is after insert and after you update so if you have observed the flow screen we have combo event elsewhere let's look into that so as per the scenario we need to create opportunity whenever accounts rating the rating field is hot whether it is created or when it is getting updated let's see how we can create such kind of flow click on new flow here and in this new flow we need to select record trigger flow why because whenever account is getting created are updated and the rating value is hot then we need to create an opportunity so this obviously fits our purpose so record trigger flow and then click on next and select auto layout and in here it will ask the object name now we need to select account and if you see the events we need to select the third option which is whenever a record is or account record is created or updated we need to follow the process or follow the next process which is creation of opportunity and now if you remember the other condition it's also said is account rating is hot so we need to allow only the records which are having reading is equal to hot so we will give the same condition so all the conditions are met and then we will give rating and then we need to select equals and the condition is hot so rating equals heart on account whenever it is created or offered updated then we need to do we need to create an opportunity so as we remember the thumb rule if we want to update any field on the same record then we need to choose this any other condition we need to go ahead with actions and related records so this is something which we need to select now and then click on done now we have this configuration where it says if account is getting created or updated with a condition called rating is equal to heart then we need to do following action what is that following action so click on plus and now we need to create a new record so this is the action that we need to perform create records so here we need to give a label create opportunity so opportunity when we create an opportunity it will have multiple uh mandatory fields let's see let's see what are they we have opportunity name close date and stage okay so total three mandate fields so we just need to give those mandate fields in this uh create record section so how many records to create so we need to create only one how to set the record field values so we can have so we need to set use separate values we need to select the below option because we can we can assign we can give the values directly so the object is opportunity so now it will set it will ask what are the fields that you want to populate so we have three fields that are meant so we need to provide three field values so first thing is opportunity name or name so our opportunity name should be same name as account name account name will be stored in record right so a flows will store the account recording record variable so record dot name done now we need to have the closed it so close it so we'll give current dates i will give some hardcoded text so month so if you see this is the format will give some random values so 11 slash 30 slash 2022 okay and then we will add one more field which is stage and we should be using prospecting and then click on done so we have our configuration of our flow ready so on account insertion or application if the rating is hot we are creating an opportunity with those three values account name is populated with opportunity name and close date we have given some hard coded and finally this stage we have kept it as prospecting as default value so let us click on save and give this is flow number five camera trunk and then this is on after insert update trigger create opportunity on account rating i said and then click on save and activate this and let us check it out so we'll close this one and click on account so yeah one more thing we left it so we have created the opportunity but it has to be associated with the same account right so i think that is something which we need to do so click on edit and we need to add one more field which is account id because this opportunity has to be associated with the same account right so the account id will be stored in record so because this is the record dot id id and click on done click on save as save activate now if we test this out whenever we create an account with rating hot it should create the opportunity as well immediately so test account below five okay and then rating i will give it as hot and then if i scroll down and then click on save opportunity see opportunity is also created with closed it with the hardcoded value that we have given and that the name is same as account mc account name and opportunity name is same let's do a negative testing by uh by creating a new opportunity without giving reading assault okay so rating is not given here so click on save it should not create an opportunity see opportunity is empty now we also need to test how it is working with existing records so this is a test account if we see the rating it is called and we have no opportunities so if we make it too hard it should create it should create an opportunity currently we don't have any opportunity as we are changing it to hot it should create it has created and let's say i do any other update rating is already there i will do an update now there is some expected unexpected thing that will happen now so even we have it's already there and opportunity is already created because we have changed it to hot area now i am doing another update which is not rating which is not a rating field if i click on save still it will create another opportunity which is not the expected result right so this update whenever rating whenever the rating field itself is updated opportunities has to be created not every time we do some update and then it will get created right so the reason is here we go back here and then scroll here it says the condition itself says whenever update happens on this account it will check whether the rating is hot or not and it will create it will not check whether it has been changed from some other value to uh hot so that is the extra condition that we need to add so click on add condition again here and then rating and you also need to check if it is changed to true which means if the rating if the rating is changed and the rating is hot only then only then you need to follow the action which is creation of opportunities earlier as this condition is not there it is it is creating whenever someone updates it will come to this flow and it checks whether the rating is hot and then it will immediately create now we have added one more condition saying that if rating is changed and the rating value is hot only then we need to have the new opportunity created so click on then and then click on save as save and activate so now we have our flow i will go back here and then test it out so currently we already have this we'll go to the previous operation account so this is the account right currently opportunity is created so currently the value is hot so if we give the phone number which is another update that we are just doing it's not only phone it's any other field that we update with the previous condition it would have created an opportunity but now as we have added that extra condition is change is equal to true now it will not create the opportunity now i click on save so it will still have the same one record got it so this is how you can you can use after insert and update combo in a single flow with this scenario you have also learned how to use create action also okay coming to next scenario whenever a lost opportunity is getting deleted send a notification how to achieve it so we can send notifications from process builder right so we can also do with flows also so but we need to do it whenever the last opportunity is deleted so this can be done with before delete even from record trigger flow we cannot do this with process builder or workflow because salesforce will never call process builder or workflow whenever there is a deletion happens as per the scenario we need to set notification whenever opportunity is deleted however from flows if you want to send notifications you need to create notification types custom notification types so search for custom notifications custom notifications see under notification builder you should be seeing custom notifications so remember this path so click on custom notifications now click on new to create a notification type give any name i will just give flow sample notification you need to provide supporting channels at least one supporting channel so here i will just select desktop and then click on save so this step is easy so this is how you will create a notification type now we will go to the flow and we'll see how we can create before delete flow and send notification from it so we know the drill click on close from here and it will take us to the home screen offloads and click on new flow here we also here we need to select record trigger flow why because whenever a deletion happens on opportunity we need to send a notification so i'm clicking here and then click on next and auto layout and we need to select the object so the object name is opportunity and the trigger timing or the trigger event is delete a trigger is deleted whenever opportunity is deleted then we need to do we need to send a notification so we have only before delete action here so before the delete itself we are trying to send a notification now we also need to put one more condition here because it's not simple opportunity opportunity which is lost lost in the sense there is a stage field which should be in closed lot status so just search for stage field on the opportunity and it should be equals to closed lost which means an opportunity which is getting deleted with the status of close lost then go ahead with this process now click on done now that we have configured the start element now we need to send a notification we can send notification by using this action okay click on action now we need to find custom notification here so something like notification see send custom notification now we'll just given some name as send notification to we will send it to opportunity owner so whenever opportunity is getting deleted which is of closed status we need to send it to opportunity owner so opportunity owner and then uh give the api now if we see there are uh four mandatory values notification body it's just a simple text directory we can say uh an opportunity is deleted something like that and even in the title also oops and opportunity is deleted and in recipient diaries we need to provide to whom it needs to go so recipient id is as it says ids it is basically plural so number of users it's not it will not accept single user id here so we need to prepare that variable where it will have the opportunity id name even though it is a list we at least need to add one of the user there which is our opportunity on the right now if you see the custom notification id custom notification id is nothing but the custom notification that we have created just before so i'll just go back here custom notification yeah and this is the notification id which we need to get it and then put it here so we cannot directly get that value here so we need to query that object so this is basically custom notification itself is a object salesforce object so we need to query this object to find the id by using this name and then we will update that id here and recipient ids we need to create a list and then add our opportunity id name here so before this adding of new action we need to do couple of steps first get this custom notification object record and then i will see how we need to go later so click on plus and we need to query that custom notification so we can query the records by using this get records element so click on get records element then we can say get custom notification type and an ap name object name is custom notification type okay and then we need to provide the condition what is the condition condition should be the ap name which we also call it test developer name should be equal to flow sample notification because at this point of time we only have one but we might be having many in future so we just need to get uh that apn by developer name equals the value flow sample notification this is the developer name of both the same then it will pull this record and then we will get that record only the first record i think that should be fine and then click on so now we should be getting that record and then we have that in some way some of the list so we'll get that where you see a record single variable has been created custom notification type from get custom notification type okay from here whatever you got the record it will be stored in this record single variable okay now if that value whatever we have selected there if we made it as all records if there are multiple records then it will be a list instead of record single variable it will be record multiple variables which means number of records basically a list currently we are getting only one record here so for clear right now we need to have a list variable which is used for recipient ids in the notification so that is something which we are going to do now so click on this and then click on assignment and the assignment assign opportunity owner to a list variable for recipient id of custom notification so we have custom when we are trying to create a custom notification action we have a recipient id variable that is a mandatory field right for that we need to create a list variable so that is what here it is so here we will create a new resource which which will be a simple variable and the data type type name is end depend ids and the data type should be text and it should allow multiple values so basically we are creating a variable called recipient ids and currently the list is empty now we need to add one of the value which is our opportunity our opportunity record will be there in record variable right so even before delete will be having record variable so whatever record that got that is getting deleted will be there in this record variable so record variable owner id then so recipient id will be having only one id which is opportunity id you also you can also add one more id if you want something like the same recipient ids add and you can add one more uh variable may be created by something like that or last modified by created by okay or if you want to send to account owner so this is a opportunity right if you want to send it to account owner we can search for that also all right so if you see whatever opportunity that you're deleting that opportunity owner id will be in this event id and that opportunities account owner id is also in the recipient idp now the idea is that custom notification has to be shown in both these users notification box now click on it so we added those users into the sequence id now we have our final step where we need to add our custom action which is sending custom notification custom notification see this is the one send notification to opportunity owner and account owner and then type if you see this is the type which we got it from get that get records variable so here we click on that that variable will be stored in this record single variable this is the variable that salesforce automatically created by by using the get records action click on that and we should be so this particular record is having all the fields of the custom notification we are interested in only the id field of it idp so this is the custom notification id which is this notification id now we need to create notification body which will just create by we can directly give something like opportunity is deleted or we can also create a formula something like that so click on resource you can either create text template or i can you can just create single line formula so formula sample notification body and then in text and data type should be text and formula so we'll just get the opportunity name which is which will get it in record and name and we will give something like so to add that match field we call this as much fields and to add some text over there we just need to use place operator here opportunity is deleted and then click on save are done and now we have that notification body now we have the notification body notification title we can just say oops oops yeah and then in the receipment ideas we can give the variable that we just created earlier which is having both the values of opportunity owner and accountant so this is the variable that we have created collection variable is nothing but a list list is nothing but array there is nothing but nothing but list of values so this event ids and sender id now if you see we have target id which we need to select this and then we need to provide way this notification has to be displayed so we want to display it on the displayed on the same record which is getting deleted so record and then id so the same opportunity id on the same opportunity so it will display the notification and click on done so now we have the flow where on opportunity deletion just before the delete we are getting the notification record to get the id actually and then we are creating a list here this list contains um the value of opportunity owner and account owner and finally we are sending a notification by giving that notification id and then giving the recipient id we have created the notification body template and we have given title as oops and then yeah so this is how it will send notification we'll test it out so before testing we need to click on save i think this flow is flow 6 before trigger and send custom notification and then click on save then and activate i think we are good we'll just check it out search for opportunities which is in closed lot now we'll test it so click on opportunity now we need to delete the opportunity which is in closed loss status currently the stage is prospecting will make it to closed lost and then we will delete the record so now this opportunity is closed lost now we will delete this opportunity and then see if we are getting any notification so click on this drop down and click on delete and click on delete and it should give us a notification you see a new notification has come up click on this and if you see oops test account one opportunity is deleted so test account one test account one is that opportunity name and that is how you will have that uh notification this is how you can create notifications in this scenario you have learned how to send notifications plus you also understood how to use get records option in record trigger pro this is how a complete flowchart will look like for any object if you see this is an opportunity object in our scenario 6 where we are trying to send an custom notification on deletion of an opportunity so whenever opportunity is inserted it will follow this path and if an opportunity is updated it will follow this path and if an opportunity is deleted it will follow this path if you say delete is having only three and however insert and update are having six component the reason is workflows and process builders are not applicable for delete they will only work for after insert events and after update events okay however even flow if you see flows are uh flows will have only five floors will have only five events before insert after insert before update after update and before delete it will not have after delete as of current release but we have apex trigger which are having all the six events which are before insert after insert before update after update before delete and after delete and we also have after undelete also which is the seventh event which will get called whenever a record is record from recycle bin it will we can do some actions after record is recovered so that is the reason apex is more powerful than flows which can do complex logics but the thing is we really don't need to write code in flows but in apex we need to code we need to maintain we need to have support and all so that is the reason always try to choose flows if not only go to apex triggers so if you see as per scenario 3 we have added comments in the description field on amount change or opportunity right so that's the reason it is having so whenever opportunity is updated it will check this logic and then do the necessary change and updates the record in the database and we'll do rest of the uh for it will check all the rest of the four events and then finally it will commit into database same way whenever opportunity is deleted it will check the flow and send the notification and then it will check the apex trigger before delete and then it will update it will impact the database and then finally it will check the epic trigger after delete and then finally it will take that particular record out of salesforce database and then putting it will put into recycle bin so this is how a flowchart will look like not only for this object each of the object will be having a similar kind of flowchart insert update and delete let's have a quick quiz now if an opportunity gets inserted and don't fill the closed date then pre-populate that date with current date plus 90 days which automation tool would you use so take five seconds pause and then see the answer so now we have four options record trigger flow before insert workflow process builder and record trigger flow after insert the answer is record trigger flow before insert have you seen this guy of course it's relevant now remember the thumb rule so if you want to pre-populate any field on the same record go with before block so in this case we have before insert which is recorded flow before insert rest of them or after after uh insert events we can also do with workflow process builder and the record trigger flow of insert also but the thing is as they are in after even blocks it will consume extra dml operation which is not recommended so the answer is record trigger flow before insert quiz number two whenever opportunity gets closed send a congrats email to opportunity owner which automation tool would you prefer option a workflow option b process builder option c record trigger flow before update option d record trigger flow after update so and the answer is record trigger flow after update so if you see we can send emails from workflow process builder and record trail flow after update in that case why we have chose answer t so remember the thumb rule 2 whenever a particular scenario is possible with workflow process builder and flow always choose flows okay now within flows we have before and after right then why did we choose option d which is after update so remember thumb rule one where it says if you want to pre-populate any field on the same record then you choose before else choose after in this particular scenario it is sending of email it's not pre-populating the record in the same record that is the reason the answer is t record trigger flow after update hope you got it quiz number three if user updates account records mobile number then all its related contact mobile numbers should also updated same as account mobile number and the options are record triggered flow before update workflow record workflow after update and process builder just take your time and then answer this and the answer is record trigger flow after update the reason is again come to thumb rule whenever a scenario is possible with workflow process pillar and flows then go with the flow within the flow if you want to decide before or after then we need to go to the previous thumbnail which is if you want to pre-populate any field on the same record then choose before else after in our case we want to to update records of related contacts so that is the reason we should be choosing after event years which is after update hope this is clear quiz number four in a given scenario we have object a and object b object b is child of object a via lookup so object bay a is parent and object b is chill and they are connected by a lookup relationship if object a record is deleted delete all its related records on object b so if you already know we cannot with the lookup relationship if object a is deleted chill records will not be deleted however this is true if the relationship is master detail so as we are not able to delete with standard functionality now we need to see the options how to do this option a record trigger flow before delete option b workflow option c record will go after delete and option d process builder so please think about the options by which we can achieve the scenario and the answer is record trigger flow before delete so i put this in red why because there is no record trigger flow after delete operation it does have it in apex triggers not in flows if you have selected this pat your shoulder if you have selected this pat your head quiz number five can we create custom rollup summary using close example to find number of contacts value in account record itself if yes what are the events to use it in close to achieve this so you you already know that the role of summary will be there right to find a number of contacts as such on master detailed relationship however it is not possible in accountant contacts now the thing is can we do this so as per the question can we do that roll up summary using close options are answer a no answer b yes but the events are before insert and before delete answer c yes record trigger flow after insert after update before delete answer d is yes record trigger flow after insert and before delete take time again and then come up with an answer this is little tricky but try to find the answer and the answer is answer c to your flow after insert after update and before delete so people who has answered this really well done and i'm making a video on how to create a custom role of summary using close i will be posting this week wow flow can do many things since we don't hit triggers anymore we can do everything with no current close itself no the answer is no no no no because flows are closer of course at once but that doesn't mean tokens too can do everything so it certainly has some limitations which can be which can be done using apex triggers and fx development batch glasses etc etc things you cannot do with flows before inserting or updating records if you want to throw an error based on some complex logic flows cannot fulfill such requirements then the solution would be fx triggers so you might say you can throw errors with validation rules right but that is for simple logics validation rules cannot work for complex logics if that is the case if you want to throw an error based on some complex logics then definitely you need to go for apex triggers this is something which we will see in my coming upcoming videos on apex studios so in epic stickers we have before insert this before insert is not only used for pre-populating fields but also fire errors based on complex logics sepax triggers before insert is both for pre-operating and spirals but for flows our before insert will is only used for pre-populating fields hope this is clear so this is where the difference between apex triggers before insert and flows before insert and one more thing that we cannot do with flow is let's say contact record is record from recycle pin and you want to send an email to account owner so this is something which you cannot do with pros so you can undelete a record from recycling right as soon as it gets undeleted if you want to send an email close doesn't support that so that is where again apex triggers will come into picture because in apex triggers there is an event called after undelete so whenever undelete happens post that if you want to perform any actions then you can do it without extruders and that's a wrap up if you like the video give a thumbs up if you have any questions comment down below practice practice practice and bye
Info
Channel: Salesforce Exclusive
Views: 5,502
Rating: undefined out of 5
Keywords: record triggered flows with real time scenarios, record triggered flows, salesforce flows, flows salesforce, record triggered flows salesforce, process builder salesforce, workflows salesforce, before trigger after trigger, apex triggers salesforce, salesforce triggers, salesforce record triggered flows, rollup summary salesforce, send custom notifications in flow, sending emails in flow
Id: QI7XwGQKwlM
Channel Id: undefined
Length: 82min 34sec (4954 seconds)
Published: Tue Nov 02 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.