Skip to main content

How to Create Trigger to update User if Account Type "Prospect" then deactivate User otherwise Active

Hello friends today post , create a trigger on Account, if account record type change in "prospect" then user deactivate and other type activate user ....
so let us start ........

Step=>1. Create a trigger on Account
                   goto developer console , File=>New=>trigger

                     updateUser on Account

                    trigger name:- updateUser.apxt

trigger updateUser on Account (after update) {
    Set<Id>allId=new Set<Id>();
    for(Account a:Trigger.new){
        if(a.Type=='Prospect'){
            allId.add(a.Id);
            deactivateHelper.updateUser(allId);
        }
    }
}

Step=>2.
               create a Future method of Apex class
               goto File=>New=>Apex Class
             Apex class name:- deactivateHelper

global  class deactivateHelper {
    @future
    public static void updateUser(Set<Id>allId){
        System.debug('result'+allId);
     
        Contact clst=[SELECT Id,Name,Email from Contact WHERE AccountId=:allId];
        System.debug('Contact deatails=>'+clst);
        List<User>userListToDeactivate=new List<User>();
        userListToDeactivate = [SELECT Id,Name from User where username=:clst.Email];
        System.debug('User details=>'+userListToDeactivate);
        if(userListToDeactivate.size()>0){
            for(User u : userListToDeactivate){
                u.IsActive = false;
            }
        }
        System.debug('User=>'+userListToDeactivate);
        update userListToDeactivate;
    }
 
}

Note: @future is a annotation of future method.

                                        Output:







Buy me a coffeeBuy me a coffee

Comments

Popular posts from this blog

How to used slds-hide/show class for div hide and show in lightning component

Hello friends today post ,how to create a lightning component to use slds-hide/show class, very easy to use class and aplly.. so let us start ... firstly create a lightning component and there are two or three div or anything when you want to hide/show ... so see given bellow example and udes slds-hide/show class Step=>1.                   goto developer console=>File=>New=>Lightning Component                           sldshideshow.cmp <aura:component >     <aura:attribute name="First" type="string" default="slds-show"/>     <aura:attribute name="Second" type="string" default="slds-hide"/>         <center>     <div class="slds-box" style="width:300px;height:300px;margin-top:15px;">         <div class="{!v.First}">         ...

How to Create Floating Marquee

Hello frnds today post , how to create floating Marquee in Lightning Component so let us begin............. Step=>1. goto developer console                             File=>New=>Lightning Component                    FloatingMarq.cmp                  <aura:component>       <aura:handler name="init" value="{!this}" action="{!c.doInit}" />     <aura:attribute name="intervalId" type="Integer" default="0"/>       <div id="parentDIV" style="overflow:hidden">         <p style="position:relative;" id="tofloat">             <b><span style="color:red">Important Note : </span>             I am Floating (Left to Right) Imformation...</b...

Create Overlays with the New Modal Component

Hello friends, Now modal tag is available in #LWC, we can create a modal using the #LWC Standard tag. snapshot given below with code. Step-1 Create LWC component Step-2 Add below code Step-3 I am showing how my component is look like. Thanks for reading