How To Write A Trigger To Update Number Of Contacts In Account
391 views
Hey guys, today in this post we are going to learn about How to Write a trigger to update parent business relationship phone number when ever the contact phone number is updated using trigger handler and helper course in Salesforce
Real time scenarios:- Write a trigger on Contact to update the parent Account Phone number when ever the Contact Telephone is updated through trigger handler and helper grade in Salesforce.
- Don't forget to check out:- Trigger to check indistinguishable proper name to custom object in Salesforce Click Here For More Data
Files we used in this post case
contactTrigger.apxt | Apex Grade Trigger | It will be fired when ever contact telephone number is updated. |
contactTriggerHandler.apxc | Apex Class Trigger Handler | Noon handler trigger to update account phone number with contact phone number when ever contact is updated. |
Parent Object:-Business relationship Fields:-Phone Child Object:-Contact Fields:- Phone, AccountId (Lookup) | Trigger to updated parent Business relationship from Contact based on lookup relation AccountId. |
Final Output
Other related post that would y'all like to learn.
- Notice the below steps for this post.
Create Noon Class Trigger
Stride v:- Create Apex Grade : contactTrigger.apxt
From Programmer Console ➡ File ➡ New ➡ Apex Class
contactTrigger.apxt [Apex Grade Controller]
trigger contactTrigger on Contact ( before insert , before update , earlier delete , afterwards insert , later update , later delete , later on undelete ) { if ( trigger . isBefore ) { system . debug ( 'I am before trigger ' ) ; } else if ( trigger . isAfter ) { system . debug ( 'I am after trigger ' ) ; if ( trigger . isUpdate ) { contactTriggerHandler . afterUpdateHelper ( trigger . new ) ; } } } |
Create Noon Trigger Handler and Helper Class
Stride 5:- Create Apex Class : contactTriggerHandler.apxc
From Programmer Console ➡ File ➡ New ➡ Apex Course
contactTriggerHandler.apxc [Apex Class Controller]
1 2 three 4 v half dozen 7 8 nine x 11 12 13 xiv fifteen xvi 17 xviii 19 20 21 22 23 24 25 | public form contactTriggerHandler { public static void afterUpdateHelper ( List < Contact > conList ) { Ready < Id > setId = new Set < Id > ( ) ; for ( Contact con : conList ) { setId . add ( con . AccountId ) ; } system . debug ( 'setId ' + setId ) ; List < Account > accItemList = [ Select Id , Proper name , Telephone , ( Select Id , FirstName , LastName , Telephone , AccountId From Contacts ) From Business relationship Where Id IN : setId ] ; for ( Account a1 : accItemList ) { for ( Contact c1 : a1 . Contacts ) { if ( c1 . Phone != null ) { a1 . Telephone = c1 . Telephone ; update accItemList ; } } } } } |
Further post that would you like to larn in LWC
- The Sitemap to Notice all Published Mail of The Tutorial w3web.net Click Here For More Information
To Find Some Of import Additional Data
If you call back you lot and your family members also like to earn money in additional time, then go this link. In this site, you can earn money for the lifetime at low effort. To Earn Unlimited Everyday With This Trick, Sign Up Free and Become Magic.. Get Started for Complimentary
Bank check Out Youtube:- Earn Unlimited Everyday With This Fob:- Click Hither
FAQ (Oftentimes Asked Questions)
What is trigger in Salesforce?
A trigger is an Apex script that executes before or afterward information manipulation language (DML) events occur.
Why exercise we use triggers in Salesforce?
Typically, we use triggers to perform operations based on specific conditions, to alter related records or restrict sure operations from happening.
What are different events in trigger?
The events that fire a trigger include the following: DML statements that change data in a table ( INSERT , UPDATE , or DELETE ) DDL statements.
- Your reaction of the article ▾
Source: https://www.w3web.net/trigger-to-update-account-phone-with-contact-phone/
Posted by: gouletterappe1973.blogspot.com
0 Response to "How To Write A Trigger To Update Number Of Contacts In Account"
Post a Comment