17 Trigger & Test Class Scenario | After Update | Update related Opportunity when Account is updated
ฝัง
- เผยแพร่เมื่อ 13 ธ.ค. 2024
- studysalesforce... [Find all Salesforce Video links]
Udemy : Enroll Salesforce Admin Certification Masterclass : kadge.io/admin201
Udemy : Enroll Salesforce PD1 Certification Masterclass : kadge.io/pd1
Udemy : Enroll Salesforce Flow Builder Masterclass: kadge.io/flowb...
For Online Individual or Group Training Please Email or Visit below Website.
Email: sanjaygupta.techschool@gmail.com or
Visit: studysalesforce...
Connect with Sanjay Gupta:
Linkedin: / sanjay-gupta-bb2a79bb
Find Below: TH-cam Playlist Links for Salesforce Videos
Salesforce Administrator (Lightning Experience) Video Series
• 01 How to create Devel...
LWC | Lightning Web Component
• 01 LWC | Introduction ...
Salesforce Flow Scenarios
• 01 Screen Flow Scenari...
Aura Component Development
• 01 Introduction to Lig...
Apex Programming | Apex Test | Async Apex in Salesforce
• 01 Introduction to Ape...
Salesforce Interview Preparation Videos
• What is workflow rule ...
Flow Builder in Salesforce Lightning Video Series
• What is Flow Builder i...
Apex Triggers in Salesforce
• 01 Introduction to Ape...
Asynchronous Apex in Salesforce
• 01 Introduction to Asy...
Process Builder in Salesforce Lightning Video Series
• What is process builde...
Workflow Rule in Salesforce Video Series
• What is workflow rule ...
Report & Dashboard in Salesforce Video Series
• Introduction to Report...
Data Security in Salesforce Video Series
• Introduction to Data S...
Please like and subscribe to support the efforts.
#Salesforce #lightning #development #flow #admin #salesforceadmin #salesforcetraining #learnsalesforce #interview #salesforcedeveloper #developer #sanjaygupta #sanjayguptatechschool #studysalesforce #apex #trigger #integration #lwc #aura #lightningwebcomponent
For Online Individual or Group Training Please Email or Visit below Website.
Email: sanjaygupta.techschool@gmail.com or Visit: studysalesforce.com/
Connect with Sanjay Gupta on Linkedin: www.linkedin.com/in/sanjay-gupta-bb2a79bb/
Udemy : Enroll Salesforce Flow Builder Masterclass: kadge.io/flowbuilder
Udemy : Enroll Salesforce Admin Certification Masterclass : kadge.io/admin201
Udemy : Enroll Salesforce PD1 Certification Masterclass : kadge.io/pd1
Please like and subscribe to support the efforts.
Can you take this one in your next video. write a trigger to get the product count of opportunity and update count field on account
Super love you sir
hello sir, would you like to cover one scenario of updating Parent record field if any of the child record is updated(if contact phone is updated then update account)without nested for loop
Hi Sir, Thank you for your efforts. I am getting below error on every after update triggers
AccountTrigger: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id 0063x00001b1B3NAAU; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, OpportunityTrigger: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0; first error: MISSING_ARGUMENT, Id not specified in an update call: [] Class.OpportunityTriggerHandler.createTask: line 37, column 1 Trigger.OpportunityTrigger: line 16, column 1: [] Class.AccountTriggerHandler.updateOppStagetoClosedLostOnAcc: line 141, column 1 Trigger.AccountTrigger: line 19, column 1
u are using wrong DML statement. I think u should use insert instead of update. if u want to use then specify the id to update the specific record
is this below code correct ?
------------------------------------------------------------------------
/*When Account Active field is updated from yes to no then update all related Opportunities Stage to Close Lost if stage is not equal to Close Won */
------------------------------------------------------------------------
trigger AccountTrigger on Account(after update){
if(trigger.isUpdate && trigger.isAfter){
AccountTriggerHelper.updateOpportunity(trigger.new, trigger.oldMap);
}
}
// Apex class for Business Logic
public class AccountTriggerHelper{
public static void updateOpportunity(Listacclist,map accOldmap){
Set accountIds = new Set();
List OppRecordList =new List();
for(Account acc:acclist){
if(acc.Active__c == 'NO' && acc.Active__c!=accOldmap.get(acc.id).Active){
accountIds.add(acc.id);
}
}
for (Opportunity opp:[select id,Stage, accountid from Opportunity where accountid in:accountIds]){
if(opp.stage!='Close WON' && opp.stage!='Close Lost'){
opp.stage = 'Close Lost';
OppRecordList.add(opp);
}
}
if(OppRecordList.size()>0){
update OppRecordList;
}
}
I have no idea why my code is not working. Can you pls check?
trigger AccountTrigger on Account (before insert, after update) {
//AccountTriggerHandler.updateRating(Trigger.new);
if (trigger.isafter && trigger.isupdate)
{
AccountTriggerHandler.afterUpdate(Trigger.new, trigger.oldmap);
}
}
-------------------------------------------------------------------------------------------------------------------
public class AccountTriggerHandler {
//public static void updateRating (List accList)
// {
/* for (Account acc: accList)
{
if (acc.Industry=='Media' || acc.Industry=='Energy')
{
acc.rating='Hot';
}
} */
//}
public static void afterUpdate (List accList, map oldAccMap)
{
map updatedAccMap = new map();
list oppList = new list();
for (account acc: accList)
{
if (oldAccMap.get(acc.id).active__c=='Yes' && acc.active__c=='No')
updatedAccMap.put(acc.id, acc);
}
if (updatedAccMap.size()>0)
{
for (opportunity opp: [select id, stagename from opportunity where accountid in : updatedAccMap.keyset() ])
{
if ( opp.stagename!='Closed Lost' && opp.stagename!='Closed Won')
{
opp.stagename='Closed Lost';
oppList.add(opp);
}
}
}
if (oppList.size()>0)
{
update oppList;
}
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------
Make more amazing videos! Employ a company like Promo-SM!!!