function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Nellson SwasonoNellson Swasono 

How to call toast in Trigger?

I want to have a toast appear when updating a record of a certain type, is this possible?

Basically in the grand scheme of things I would have to call my javascript controller (for the toast), in an .apxc file (Connected to a trigger). Is this possible to do? If not, what are some possible work arounds?
Ajay K DubediAjay K Dubedi
Hi Nellson,

Please refer to the following codes:

1. Try making your trigger like:
 trigger CampaignTrigger on Campaign(after update) {
    if(trigger.isUpdate && trigger.isAfter){
        Class.method(Trigger.new);
    }
}

2. Then in your class create a method() with some return type like boolean or string or anything you want.

3. Then from your Javascript controller/helper call this method (please be sure you have controller name of component as class name).
    get your response and according to your response call toast. Like:
    
    var action = c.get("c.method");
    action.setCallback(this, function(r){
        if(r.getState() === 'SUCCESS'){
        var response = r.getReturnValue();
        if(response == 'Your desired condition'){
            c.set("v.successMessage",'success');
            c.set("v.IsSuccessToast", true);
            h.successToast_Helper(c, e, h);
        }

This will call your toast (set timeout and all inside helper).    
        
    
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks,
Ajay Dubedi
Nellson SwasonoNellson Swasono
Thank you for your response Ajay, 

Not sure what exactly you mean in step 3, when you say "Please be sure you have controller name of component as class name"