SFDC Ninja
SFDC Ninja
  • 73
  • 436 200

วีดีโอ

Apex Triggers - 58 (Trigger Interview Scenario)
มุมมอง 817วันที่ผ่านมา
Easily create and automate custom document templates directly from Salesforce using Titan’s simple, code-free document builder 🔗 titandxp.com/pricing/titan-docs/
Apex Triggers - 57 (Trigger Interview Scenario)
มุมมอง 74321 วันที่ผ่านมา
💻 Join the Titan Community : Discover Exclusive Insights on LinkedIn www.linkedin.com/company/formtitan/mycompany/ 💻 Explore the Power of Titan : Visit Our Official Website Now 🔗 titandxp.com/
Apex Triggers - 56 (Trigger Interview Scenario)
มุมมอง 892หลายเดือนก่อน
💻 Join the Titan Community : Discover Exclusive Insights on LinkedIn www.linkedin.com/company/formtitan/mycompany/ 💻 Explore the Power of Titan : Visit Our Official Website Now 🔗 titandxp.com/
Apex Triggers - 55 (Trigger Interview Scenario)
มุมมอง 1Kหลายเดือนก่อน
💻 Join the Titan Community : Discover Exclusive Insights on LinkedIn www.linkedin.com/company/formtitan/mycompany/ 💻 Explore the Power of Titan : Visit Our Official Website Now 🔗 titandxp.com/
Apex Triggers - 54 (Infosys Interview Scenario)
มุมมอง 1.8Kหลายเดือนก่อน
💻 Join the Titan Community : Discover Exclusive Insights on LinkedIn www.linkedin.com/company/formtitan/mycompany/ 💻 Explore the Power of Titan : Visit Our Official Website Now 🔗 titandxp.com/
Apex Triggers - 53 (Trigger Interview Scenario)
มุมมอง 1.7K2 หลายเดือนก่อน
💻 Join the Titan Community : Discover Exclusive Insights on LinkedIn www.linkedin.com/company/formtitan/mycompany/ 💻 Explore the Power of Titan : Visit Our Official Website Now 🔗 titandxp.com/
Apex Triggers - 52 (IBM Interview Scenario)
มุมมอง 1.7K2 หลายเดือนก่อน
💻 Join the Titan Community : Discover Exclusive Insights on LinkedIn www.linkedin.com/company/formtitan/mycompany/ 💻 Explore the Power of Titan : Visit Our Official Website Now 🔗 titandxp.com/
Apex Triggers - 51 (NTT Data Interview Scenario)
มุมมอง 2.3K2 หลายเดือนก่อน
💻 Join the Titan Community : Discover Exclusive Insights on LinkedIn www.linkedin.com/company/formtitan/mycompany/ 💻 Explore the Power of Titan : Visit Our Official Website Now 🔗 titandxp.com/
Apex Triggers - 50 (NTT Data Interview Scenario)
มุมมอง 2K3 หลายเดือนก่อน
💻 Join the Titan Community : Discover Exclusive Insights on LinkedIn www.linkedin.com/company/formtitan/mycompany/ 💻 Explore the Power of Titan : Visit Our Official Website Now 🔗 titandxp.com/
Apex Triggers - 49 (Trigger Interview Scenario)
มุมมอง 1.5K3 หลายเดือนก่อน
💻 Join the Titan Community : Discover Exclusive Insights on LinkedIn www.linkedin.com/company/formtitan/mycompany/ 💻 Explore the Power of Titan : Visit Our Official Website Now 🔗 titandxp.com/
Apex Triggers - 48 (Trigger Interview Scenario)
มุมมอง 1.6K3 หลายเดือนก่อน
💻 Join the Titan Community : Discover Exclusive Insights on LinkedIn www.linkedin.com/company/formtitan/mycompany/ 💻 Explore the Power of Titan : Visit Our Official Website Now 🔗 titandxp.com/
Salesforce Queueable Apex Interview Questions
มุมมอง 1.7K4 หลายเดือนก่อน
💻 Join the Titan Community : Discover Exclusive Insights on LinkedIn www.linkedin.com/company/formtitan/mycompany/ 💻 Explore the Power of Titan : Visit Our Official Website Now 🔗 titandxp.com/
Salesforce Future Apex Interview Questions
มุมมอง 1.8K4 หลายเดือนก่อน
💻 Join the Titan Community : Discover Exclusive Insights on LinkedIn www.linkedin.com/company/formtitan/mycompany/ 💻 Explore the Power of Titan : Visit Our Official Website Now 🔗 titandxp.com/
Salesforce Batch Apex Interview Questions
มุมมอง 6K4 หลายเดือนก่อน
💻 Join the Titan Community : Discover Exclusive Insights on LinkedIn www.linkedin.com/company/formtitan/mycompany/ 💻 Explore the Power of Titan : Visit Our Official Website Now 🔗 titandxp.com/
Apex Triggers - 47 (Accenture Interview Scenario)
มุมมอง 6K4 หลายเดือนก่อน
Apex Triggers - 47 (Accenture Interview Scenario)
Apex Triggers - 46 (Deloitte Interview Scenario)
มุมมอง 5K5 หลายเดือนก่อน
Apex Triggers - 46 (Deloitte Interview Scenario)
Apex Triggers - 45 (Infosys Interview Scenario)
มุมมอง 4.5K6 หลายเดือนก่อน
Apex Triggers - 45 (Infosys Interview Scenario)
Apex Triggers - 44 (EY Interview Scenario)
มุมมอง 3.6K6 หลายเดือนก่อน
Apex Triggers - 44 (EY Interview Scenario)
Apex Triggers - 43 (Infosys Interview Scenario)
มุมมอง 3.7K6 หลายเดือนก่อน
Apex Triggers - 43 (Infosys Interview Scenario)
Apex Triggers - 42 (Trigger Interview Question)
มุมมอง 1.8K6 หลายเดือนก่อน
Apex Triggers - 42 (Trigger Interview Question)
Apex Triggers - 41 (Trigger Interview Question)
มุมมอง 2.3K7 หลายเดือนก่อน
Apex Triggers - 41 (Trigger Interview Question)
LWC Scenario - 5 (Mini Project)
มุมมอง 1.1K7 หลายเดือนก่อน
LWC Scenario - 5 (Mini Project)
LWC Scenario - 4 (Search Functionality in Lightning Datatable)
มุมมอง 1.2K8 หลายเดือนก่อน
LWC Scenario - 4 (Search Functionality in Lightning Datatable)
LWC Scenario - 3 (Lightning Record Picker)
มุมมอง 1.3K8 หลายเดือนก่อน
LWC Scenario - 3 (Lightning Record Picker)
LWC Scenario - 2 (Server Side Sorting in Lightning Datatable)
มุมมอง 1.1K9 หลายเดือนก่อน
LWC Scenario - 2 (Server Side Sorting in Lightning Datatable)
LWC Scenario - 1 (Client Side Sorting in Lightning Datatable)
มุมมอง 3.7K9 หลายเดือนก่อน
LWC Scenario - 1 (Client Side Sorting in Lightning Datatable)
Apex Test Class - 5 (Testing Wrapper Class)
มุมมอง 1K10 หลายเดือนก่อน
Apex Test Class - 5 (Testing Wrapper Class)
Apex Test Class - 4 (Testing Queueable Class)
มุมมอง 70610 หลายเดือนก่อน
Apex Test Class - 4 (Testing Queueable Class)
Apex Test Class - 3 (Testing Batch Apex)
มุมมอง 1.2K10 หลายเดือนก่อน
Apex Test Class - 3 (Testing Batch Apex)

ความคิดเห็น

  • @user-pu2yc3vn2k
    @user-pu2yc3vn2k 2 วันที่ผ่านมา

    Great Content! Try this approach! Set<Id> accIds = new Set<Id>(); for (Case c : oldCases.values()) { if (c.AccountId != null) { accIds.add(c.AccountId); } } if (accIds.size() > 0) { List<Account> accList = [SELECT Id, Owner.Email, Owner.Name FROM Account WHERE Id IN :accIds]; List<Task> taskList = new List<Task>(); List<Messaging.SingleEmailMessage> emailList = new List<Messaging.SingleEmailMessage>(); for (Account a : accList) { taskList.add( new Task( Subject = 'Followup Task while deleting Case on Account', Status = 'In Progress', // WhoId = con.Id, WhatId = a.Id ) ); Messaging.SingleEmailMessage ms = new Messaging.SingleEmailMessage(); ms.setToAddresses(new List<String>{a.Owner.Email}); ms.setPlainTextBody(a.Owner.Name); ms.setSubject('Case is deleted from these Account and Task is being created in respect of this!'); emailList.add(ms); } if (taskList.size() > 0) { try { insert taskList; } catch (Exception e) { System.debug('Exception occured while inserting the task --> '+e.getMessage()); } } if (emailList.size() > 0) { try { Messaging.sendEmail(emailList); } catch (Exception e) { System.debug('Error while sending mails'+e); } } }

  • @swaroopragswaroop5210
    @swaroopragswaroop5210 2 วันที่ผ่านมา

    Hi 2 things I wanted to ask.. 1. Can we handle this in before delete context 2. And I saw u iterated over deleted caselist and created tasks and email. Here can we iterate over account list right? I am just trying to understand if there is any problem in my approach Please let me know

  • @naveensai2175
    @naveensai2175 2 วันที่ผ่านมา

    Hi Sir could you please write a trigger on Account object whenever Account getting updated we need to send an email to the account owner also send contacts data only those created between last update and current update of account

  • @rajeshprogram2488
    @rajeshprogram2488 3 วันที่ผ่านมา

    Hi just wanted to know do u need null check

  • @naveensai2175
    @naveensai2175 5 วันที่ผ่านมา

    public static void preventDuplicateRecord(List<Account> accList){ // Collect unique account names (normalized to lowercase) Set<String> newAccNames = new Set<String>(); for (Account acc : accList) { if (acc.Name != null) { newAccNames.add(acc.Name.toLowerCase()); } } // Query existing accounts with names in the set List<Account> existingAccounts = [ SELECT Id, Name FROM Account WHERE Name IN :newAccNames ]; // Collect existing account names and their IDs Set<String> existingAccNames = new Set<String>(); Map<String, Id> existingNameToIdMap = new Map<String, Id>(); for (Account acc : existingAccounts) { existingAccNames.add(acc.Name.toLowerCase()); existingNameToIdMap.put(acc.Name.toLowerCase(), acc.Id); } // Flag duplicate records for (Account acc : accList) { if (acc.Name != null) { String normalizedName = acc.Name.toLowerCase(); // Check if the name exists and if it's not the same as the current record if (existingAccNames.contains(acc.Name.toLowerCase()) && !existingNameToIdMap.get(acc.Name.toLowerCase()).equals(acc.Id)) { acc.addError('Duplicate Account Name detected: ' + acc.Name); } } } }

  • @naveensai2175
    @naveensai2175 5 วันที่ผ่านมา

    You are trying to insert 4 Account records, all with the same name, and that name does not currently exist in the database. Will it allow Insertion ?

    • @JShorts511
      @JShorts511 3 วันที่ผ่านมา

      The following code will not allow /*Trigger Scenario: Write a trigger to prevent duplicate accounts based on name whenever an Account is inserted or updated. Scenario is to validate records before they are saved to database. so we use before trigger. context variables to access runtime contexts are Trigger.isInsert and Trigger.isUpdate*/ trigger AccountTrigger on Account(before insert,before update){ //set to collect Account Name from triggering records. List<String> accNames=new List<String>(); //accessing run time context if(Trigger.isBefore){ if(Trigger.isInsert){ //iterating over triggering records for(Account acc:Trigger.new){ accNames.add(acc.Name); } } if(Trigger.isUpdate){ //iterating over triggering records for(Account acc:Trigger.new){ //checking whether the account's Name is changed or not if(acc.Name != Trigger.oldMap.get(acc.Id).Name){ accNames.add(acc.Name); } } } } List<Account> accList=[SELECT Id,Name FROM Account WHERE Name IN:accNames]; set<String> accNameSetToCheckDups=new set<String>(); //Map to get number of accounts with same name Map<String,Integer> accNamesCountwithName=new Map<String,Integer>(); //iterating over accNames if(!accNames.isEmpty()){ for(String acctName:accNames){ if(!accNamesCountwithName.containsKey(acctName)){ accNamesCountwithName.put(acctName,0); }else { Integer count=accNamesCountwithName.get(acctName)+1; accNamesCountwithName.put(acctName,count); } } } //iterating over accList to collect existing names if(!accList.isEmpty()){ for(Account acc:accList){ accNameSetToCheckDups.add(acc.Name); } } //iterating over Triggering records to prevent duplicates if(!accNameSetToCheckDups.isEmpty() || accNamesCountwithName.keySet() !=null ){ //if triggering records has the same name more than one (If we are inserting /updating with same name at a time) for(Account acc:Trigger.new){ if(accNamesCountwithName.get(acc.Name)>1 || accNameSetToCheckDups.contains(acc.Name)){ acc.addError('Account already exists with the same name'); } } } }

    • @naveensai2175
      @naveensai2175 3 วันที่ผ่านมา

      @@JShorts511 thank you

  • @srisadgurusairam1688
    @srisadgurusairam1688 6 วันที่ผ่านมา

    Nice Explanation

  • @Rohitkumar-vg5xi
    @Rohitkumar-vg5xi 7 วันที่ผ่านมา

    but an opportunity might have multiple Tasks ?

  • @user-pu2yc3vn2k
    @user-pu2yc3vn2k 8 วันที่ผ่านมา

    Thanks for making amazing content, keep it up bro :) Try this approach, Map<Id, String> phoneToIdMap = new Map<Id, String>(); for (Contact c : newContacts) { if (c.Phone != null && c.Phone != oldContacts.get(c.Id).Phone && c.AccountId != null) { phoneToIdMap.put(c.AccountId, c.Phone); } } if (phoneToIdMap.size() > 0) { List<Contact> conList = [SELECT Id, AccountId, Phone FROM Contact WHERE AccountId IN :phoneToIdMap.keySet()]; List<SObject> updateList = new List<SObject>(); Map<Id, Account> accMap = new Map<Id, Account>(); //we take map because if we directly insert acc in above list it gives duplicate Ids found error! for (Contact c : conList) { c.Phone = phoneToIdMap.get(c.AccountId); updateList.add(c); accMap.put( c.AccountId, new Account( Id = c.AccountId, Phone = phoneToIdMap.get(c.AccountId) ) ); } if (accMap.size() > 0) { updateList.addAll(accMap.values()); } if (updateList.size() > 0) { try { update updateList; } catch (Exception e) { System.debug('Exception occured in updating list --> '+e.getMessage()); } } }

  • @hemantsinghbisht4371
    @hemantsinghbisht4371 9 วันที่ผ่านมา

    Hi can anyone tell me why I'm not getting any changes in account object even tho I have done all the steps just like video .! 😮

    • @sfdcninjas
      @sfdcninjas 8 วันที่ผ่านมา

      Hi can you please share your code

  • @niteshreddy7891
    @niteshreddy7891 9 วันที่ผ่านมา

    Hi SFDC ninja: I have a doubt, Instead of adding to Map. Directly in line 25 we can null check accountId and create instance of Account there itself and update account. Works right ? Great work by the way, Your classes are very useful 🙏

  • @AJAYKUMARGHANTA
    @AJAYKUMARGHANTA 10 วันที่ผ่านมา

    I think we can also use account list and fetching related contacts and updating phone through map , its works for me actually in a simple way

  • @kumareshghosh5593
    @kumareshghosh5593 10 วันที่ผ่านมา

    I used a diff approach , class: public with sharing class phoneAccConsHandler { //whenever a contact phone gets updated, it's parent account phone should get updated, also all of the account's other contacts phone also should get updated with the same phone number. public static void afterUpdate(List<contact> newCons,Map<id,contact> oldConMap){ set<id> accIds=new Set<id>(); Map<id,string> accidPhoneMap=new Map<id,string>(); for(Contact con:newCons){ if(con.accountId!=null && con.Phone!=null && oldConMap==null){ accIds.add(con.accountId); accidPhoneMap.put(con.accountId,con.phone); }else if(con.accountId!=null && con.Phone!=null && oldConMap.get(con.id).phone!=con.phone || oldConMap.get(con.id).accountId!=con.accountId){ accIds.add(con.accountId); accIds.add(oldConMap.get(con.id).accountId); accidPhoneMap.put(con.accountId,con.phone); accidPhoneMap.put(oldConMap.get(con.id).accountId,con.phone); } } //update account Phone List<account> Accounts=new List<account>(); for(Account acc:[select id,phone from account where id in:accIds]){ acc.phone=accidPhoneMap.get(acc.id); Accounts.add(acc); } If(Accounts.size()!=0){ update Accounts; } //list all contact's of that account: List<contact> allConsToBeUpdated=new List<contact>(); List<contact> allCons=[Select id,accountId,Phone from Contact where accountId in:accIds]; for(Contact con:allCons){ con.phone=accidPhoneMap.get(con.accountId); allConsToBeUpdated.add(con); } if(allConsToBeUpdated.size()!=0){ update allConsToBeUpdated; } } }

  • @srisadgurusairam1688
    @srisadgurusairam1688 10 วันที่ผ่านมา

    pls upload the codes

  • @sfstart9655
    @sfstart9655 11 วันที่ผ่านมา

    @SFDC NINJA ,I saw all Ur Trigger Videos .Champion effect loved it. In this scenario lets say Account A has contacts c1,c2,c3 .where C1 phone updated to 999 and C2 phone to 888 .so Account phone and all c1,c2,c3 phone now 888. But if u update multiple contacts with apex and show the difference in video i think it adds more value and understandability for Biggers.

  • @ypravallika9080
    @ypravallika9080 11 วันที่ผ่านมา

    Thank you for sharing the solution, this is the trigger which I got in Accenture interview😊

    • @awesomekj5812
      @awesomekj5812 11 วันที่ผ่านมา

      Were you able to solve it ?

  • @Anitha-f5m
    @Anitha-f5m 11 วันที่ผ่านมา

    Please can you write and show with apex handler

  • @saikrishna2972
    @saikrishna2972 11 วันที่ผ่านมา

    Why did this not go into recusrion 🤔

    • @sfstart9655
      @sfstart9655 11 วันที่ผ่านมา

      Here in line 31 a check to make sure not include contact which phone is same to update rel cons of acc.This way recursion can be avoided although After Trigger is Used..Correct me if i was wrong

  • @adeshlandge767
    @adeshlandge767 11 วันที่ผ่านมา

    We need not to use a for loop in the Trigger.

  • @shivanandtotar4357
    @shivanandtotar4357 12 วันที่ผ่านมา

    good information

  • @shivamsaini7252
    @shivamsaini7252 12 วันที่ผ่านมา

    thank you bro for this awesome work and i have a scenario .if if are handling bulk delete an account does not have any opp but others have in this scenario else of Aggregate function will not execute .i have tried for this scenario plz have a look and guide me further trigger OppAmountSumOnAccount on Opportunity(after insert,after undelete,after delete,after update){ set<id> accountIds = new set<id>(); if(!trigger.new.isEmpty()){ if(trigger.isAfter && (trigger.isInsert || trigger.IsUndelete)){ for(opportunity opp : trigger.new){ if(opp.accountid != null){ accountIds.add(opp.accountId); } } } if(trigger.isAfter && trigger.isUpdate){ for(opportunity opp : trigger.new){ if(opp.accountid != null){ accountIds.add(opp.accountId); } if(trigger.oldMap.get(opp.id).accountId != null && (opp.accountId != trigger.oldMap.get(opp.id).accountId || opp.amount != trigger.oldMap.get(opp.id).amount)){ accountIds.add(trigger.oldMap.get(opp.id).accountId); } } } } if(!trigger.old.isEmpty()){ if(trigger.isAfter && trigger.isDelete){ for(opportunity opp : trigger.old){ if(opp.accountid != null){ accountIds.add(opp.accountId); } } } } map<id,account> accMap = new map<id,account>(); if(!accountIds.isEmpty()){ list<AggregateResult> agrList = [select accountId ids,sum(amount) sumAmnt from opportunity where accountId IN : accountIds group by AccountId]; if(!agrList.isEmpty()){ for(AggregateResult agr: agrList){ account acc = new account(); acc.id = (id)agr.get('ids'); acc.totalOppAmount__c = (Decimal)agr.get('sumAmnt'); accMap.put(acc.id,acc); if(accountids.contains(acc.id)){ accountids.remove(acc.id); } } } //here we are handling account which doesnot have any associated opportunity after the action for(id accid:accountids){ account acc1 = new Account(); acc1.id =accid; acc1.totalOppAmount__c = 0; accMap.put(acc1.id,acc1); } } if(!accMap.isEmpty()){ update accMap.values(); } }

  • @infantremi408
    @infantremi408 15 วันที่ผ่านมา

    Hi, I guess there is an issue in this snippet, In the second for loop you were iterating the trigger.new again but the accMap was created for only the records where the related account Id is not null and description should be updated. So, if a contact record is updated without any change on the description, we will face an issue in line 26 as KeyNotExists I guess. However we can overcome this by adding a containsKey() in line 26. Thanks!

  • @mayankmj35
    @mayankmj35 15 วันที่ผ่านมา

    want more iterview videos like this for different topics please

  • @sfstart9655
    @sfstart9655 16 วันที่ผ่านมา

    public static void updtAccDescriptionWithCon(List<Contact> newList , Map<Id,Contact> oldMap) { List<Account> AccLsts = new List<Account>(); if(!newList.isEmpty()){ for(Contact con : newList){ //if Update event if(oldMap !=null && con.AccountId !=null && (oldMap.get(con.Id).Description != con.Description)){ AccLsts.add(new Account(Id=con.AccountId ,Description =con.Description)); } } } if(!AccLsts.isEmpty()){ update AccLsts; } } //Please correct me if i was wrong.

  • @swatisharma-oz6df
    @swatisharma-oz6df 17 วันที่ผ่านมา

    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

  • @RanjitaBehera-nw3vl
    @RanjitaBehera-nw3vl 19 วันที่ผ่านมา

    Only for Insert Operation----> public with sharing class OpportunityAmountTriggerHelper { public static void getOppAmount(List<Opportunity> lstNewOpp) { set<id> accIds=new set<id>(); if(!lstNewOpp.isEmpty()) { for(Opportunity opp:lstNewOpp) { if(opp.AccountId != null && opp.Amount != null) { accIds.add(opp.AccountId); } } } if(!accIds.isEmpty()) { List<Account> accToUpdate=new List<Account>(); map<id, Opportunity> mapOpp=new map<id, Opportunity>(); List<Opportunity> getAcc=[select Accountid, Amount from Opportunity where Accountid in: accIds ORDER BY Amount desc limit 1 OFFSET 1]; if(!getAcc.isEmpty()) { for(Opportunity opt:getAcc) { mapOpp.put(opt.Accountid, opt); } } for(Id ids:accIds) { if(mapOpp.containskey(ids)) { account accnt=new account(); accnt.id=ids; accnt.AnnualRevenue=mapOpp.get(ids).amount; accToUpdate.add(accnt); } } if(!accToUpdate.isEmpty()) { update accToUpdate; } } } }

  • @joharR-ju7ml
    @joharR-ju7ml 19 วันที่ผ่านมา

    Thank you

  • @joharR-ju7ml
    @joharR-ju7ml 19 วันที่ผ่านมา

    Thankyou Sir !!!!

  • @Anitha-f5m
    @Anitha-f5m 20 วันที่ผ่านมา

    Please can you make vedio on custom validation in LWC in detailed way

  • @Anitha-f5m
    @Anitha-f5m 20 วันที่ผ่านมา

    hi

  • @Anitha-f5m
    @Anitha-f5m 20 วันที่ผ่านมา

    Please can you make vedio on custom validation with full clarity in lwc component like howmany way are availble in lwc for custom validation

  • @goldylodhi2116
    @goldylodhi2116 24 วันที่ผ่านมา

    Nicely explained

  • @kumareshghosh5593
    @kumareshghosh5593 24 วันที่ผ่านมา

    Something I would be doing happily with validation rule/record trigger flow.

    • @sfdcninjas
      @sfdcninjas 24 วันที่ผ่านมา

      Yes but this scenario is asked to a candidate in an interview

    • @awesomekj5812
      @awesomekj5812 24 วันที่ผ่านมา

      yeah I was gonna say the same ....that FLAT and field value check could have been done in Validation rule

  • @sonalijadhav9446
    @sonalijadhav9446 26 วันที่ผ่านมา

    What is reason we can't call future from another future method??

  • @gauravjoshi3879
    @gauravjoshi3879 29 วันที่ผ่านมา

    Sir i am facing issue in a trigger "trigger will fire when we will update opportunity to closed won and it will create order and order item as that are in opportunity line item " when i am using try and catch block it is working fine but when i am not using i am not getting expected result please help trigger CreateOrderOnOpportunityWon on Opportunity (after update) { List<Order> ordersToInsert = new List<Order>(); List<OrderItem> orderItemsToInsert = new List<OrderItem>(); Set<Id> opportunityIds = new Set<Id>(); for (Opportunity opp : Trigger.new) { if (opp.IsWon && Trigger.oldMap.get(opp.Id).StageName != 'Closed Won') { System.debug('Opportunity moved to Closed Won: ' + opp.Id); opportunityIds.add(opp.Id); } } System.debug('Opportunity Ids moved to Closed Won: ' + opportunityIds); if (!opportunityIds.isEmpty()) { try { List<OpportunityLineItem> opportunityLineItems = [SELECT OpportunityId, Product2Id, Quantity, UnitPrice, PricebookEntryId FROM OpportunityLineItem WHERE OpportunityId IN :opportunityIds]; System.debug('Queried OpportunityLineItems: ' + opportunityLineItems); List<Opportunity> opportunities = [SELECT Id, AccountId, ContractId, Pricebook2Id FROM Opportunity WHERE Id IN :opportunityIds]; System.debug('Queried Opportunities: ' + opportunities); Map<Id, Order> oppOrderMap = new Map<Id, Order>(); for (Opportunity opp : opportunities) { Order newOrder = new Order(); newOrder.AccountId = opp.AccountId; newOrder.ContractId = opp.ContractId; newOrder.EffectiveDate = Date.today(); newOrder.Status = 'Draft'; newOrder.Pricebook2Id = opp.Pricebook2Id; ordersToInsert.add(newOrder); oppOrderMap.put(opp.Id, newOrder); System.debug('Prepared Order to insert: ' + newOrder); } if (!ordersToInsert.isEmpty()) { try { insert ordersToInsert; System.debug('Orders inserted successfully: ' + ordersToInsert); for (OpportunityLineItem oli : opportunityLineItems) { Order newOrder = oppOrderMap.get(oli.OpportunityId); if (newOrder != null) { OrderItem newOrderItem = new OrderItem(); newOrderItem.Product2Id = oli.Product2Id; newOrderItem.Quantity = oli.Quantity; newOrderItem.UnitPrice = oli.UnitPrice; newOrderItem.PricebookEntryId = oli.PricebookEntryId; // Add PricebookEntryId newOrderItem.OrderId = newOrder.Id; orderItemsToInsert.add(newOrderItem); System.debug('Prepared OrderItem to insert: ' + newOrderItem); } else { System.debug('No matching order found for OpportunityLineItem: ' + oli); } } if (!orderItemsToInsert.isEmpty()) { try { insert orderItemsToInsert; System.debug('OrderItems inserted successfully: ' + orderItemsToInsert); } catch (DmlException dme) { System.debug('Error inserting OrderItems: ' + dme.getMessage()); System.debug('DML Error Details: ' + dme.getDmlMessage(0)); System.debug('DML Error Status Code: ' + dme.getDmlStatusCode(0)); System.debug('DML Error Fields: ' + dme.getDmlFields(0)); } } else { System.debug('No OrderItems to insert'); } } catch (DmlException dme) { System.debug('Error inserting Orders: ' + dme.getMessage()); System.debug('DML Error Details: ' + dme.getDmlMessage(0)); System.debug('DML Error Status Code: ' + dme.getDmlStatusCode(0)); System.debug('DML Error Fields: ' + dme.getDmlFields(0)); } } else { System.debug('No Orders to insert'); } } catch (Exception e) { System.debug('Error in trigger execution: ' + e.getMessage()); System.debug('Exception Stack Trace: ' + e.getStackTraceString()); } } else { System.debug('No Opportunities moved to Closed Won'); } }

  • @pravallika-j5d
    @pravallika-j5d หลายเดือนก่อน

    This is not working for me, getting recurssive DML exception. Can you help me

    • @Anitha-f5m
      @Anitha-f5m 13 วันที่ผ่านมา

      @@gurudeep7956 I got Answer today I tried now after updating account duplicate contact is not creating

    • @Anitha-f5m
      @Anitha-f5m 12 วันที่ผ่านมา

      @@gurudeep7956 i got it

  • @Lovepassionkarma
    @Lovepassionkarma หลายเดือนก่อน

    why am I getting error whenever I insert a new record with phone number?

  • @kumareshghosh5593
    @kumareshghosh5593 หลายเดือนก่อน

    I have used the sort method which will also help in bulk process , here is my code (done for only after insert) : public with sharing class accSecondOppHolder { //scenario: update account description field with the second highest related amount opportunity details. public static void afterOperation(List<opportunity> newOpps,map<id,opportunity> oldOppMap){ set<id> accId=new Set<id>(); for(Opportunity opp:newOpps){ if(opp.accountid!=null){ accId.add(opp.accountId); } } List<opportunity> allOpps=[Select id,stageName,accountId, amount from opportunity where accountId in:accId]; Map<id,List<decimal>> accidOppMap=new Map<id,List<decimal>>(); for(Opportunity opp:allOpps){ If(opp.accountId!=null && opp.amount!=null){ if(!accidOppMap.containsKey(opp.accountId)){ accidOppMap.put(opp.accountId,new List<decimal>{opp.amount}); }else{ accidOppMap.get(opp.accountId).add(opp.amount); } } } List<account> allAcc=new List<account>(); for(Id ids:accId){ Account acc=new Account(); if(accidOppMap.containsKey(ids) && accidOppMap.get(ids).size()!=0){ acc.id=ids; List<decimal> amountList= accidOppMap.get(ids); amountList.sort(); acc.Description='Second higest opportunity amount is: '+ amountList[amountList.size()-2]; allAcc.add(acc); }else{ acc.id=ids; acc.Description='No related opportunity exist'; allAcc.add(acc); } } if(allAcc.size()!=0){ update allAcc; } } }

  • @explore-everything-withme
    @explore-everything-withme หลายเดือนก่อน

    Thank you for your video. I have a question , it is mentioned that we can process max 200 records at a time in execute method. Then how we are calculating how many times the execute method will be executed to process the 1236 records by specifying batch size as 400. Anyone please clear this doubt.

    • @pravallika-j5d
      @pravallika-j5d หลายเดือนก่อน

      it will 1200/400 = 3 + 1(for remaining 36 Records), total=4 times

    • @anirudh867
      @anirudh867 หลายเดือนก่อน

      Divide 1236/400 = 3 batches each of around 400 records

    • @pravallika-j5d
      @pravallika-j5d หลายเดือนก่อน

      200 is the default batch size, it applies when we dont mention batch size, minmum is 1 and maximum is 2000

  • @meghanareddy1364
    @meghanareddy1364 หลายเดือนก่อน

    at what level was this question asked for?

  • @_DheerajIPPILI
    @_DheerajIPPILI หลายเดือนก่อน

    Trigger - trigger Accdesc on Contact (after insert, after update, after delete, after undelete) { if (trigger.isAfter && trigger.isInsert) { UpdateAccDec.DMLConInsertion(trigger.new); } if (trigger.isAfter && trigger.isUpdate) { UpdateAccDec.DMLConUpdate(trigger.new, trigger.oldMap); System.debug('Checkpoint -1'); } if (trigger.isAfter && trigger.isDelete) { UpdateAccDec.DMLDelete(trigger.old); } if (trigger.isAfter && trigger.isUndelete) { UpdateAccDec.DMLUndelete(trigger.new); } } Handler Class - public class UpdateAccDec { public static void DMLConInsertion(List<Contact> conlist) { Set<Id> accIds = new Set<Id>(); List<Account> accList = new List<Account>(); System.debug('Checkpoint-2'); for (Contact c : conlist) { if (c.AccountId != null) { accIds.add(c.AccountId); } } System.debug('Accountids' + accIds); accList = [SELECT Id, Name, Description, (SELECT Id, Name, CreatedDate FROM Contacts) FROM Account WHERE Id IN :accIds]; for (Account a : accList) { String accDes = ''; for (Contact c : a.Contacts) { accDes += c.Name + ' ' + c.CreatedDate.format() + ' '; } if (accDes.endsWith(', ')) { accDes = accDes.removeEnd(', '); } a.Description = accDes; } if (!accList.isEmpty()) { update accList; } System.debug('Accounts' + accList); } public static void DMLConUpdate(List<Contact> conlist, Map<Id, Contact> oldMap) { Set<Id> oldAccIds = new Set<Id>(); Set<Id> newAccIds = new Set<Id>(); List<Contact> oldConList = new List<Contact>(); List<Contact> newConList = new List<Contact>(); System.debug('Checkpoint -2'); for (Contact c : conlist) { System.debug('Contact ids' + c.Id); Contact oldCon = oldMap.get(c.Id); System.debug('Oldcontactid' + oldCon.Id); if (c.AccountId != oldCon.AccountId) { oldAccIds.add(oldCon.AccountId); newAccIds.add(c.AccountId); } else if (c.AccountId != null) { newAccIds.add(c.AccountId); System.debug('New Accountid' + c.AccountId); } } System.debug('Old Accountids' + oldAccIds); System.debug('New Accountids' + newAccIds); oldConList = [SELECT Id, Name, CreatedDate, AccountId FROM Contact WHERE AccountId IN :oldAccIds]; newConList = [SELECT Id, Name, CreatedDate, AccountId FROM Contact WHERE AccountId IN :newAccIds]; System.debug('Old contact list' + oldConList); System.debug('New contact list' + newConList); if (!oldConList.isEmpty()) { DMLConInsertion(oldConList); } if (!newConList.isEmpty()) { DMLConInsertion(newConList); } } public static void DMLDelete(List<Contact> conlist) { if (!conlist.isEmpty()) { DMLConInsertion(conlist); // reuse the code } } public static void DMLUndelete(List<Contact> conlist) { if (!conlist.isEmpty()) { DMLConInsertion(conlist); // reuse the code } } }

  • @shubhampatil9431
    @shubhampatil9431 หลายเดือนก่อน

    can you please provide a pdf of all your trigger scenario

  • @SANTHOSHKUMAR-ot7uj
    @SANTHOSHKUMAR-ot7uj หลายเดือนก่อน

    I think this code will not perform well in Bulikified manner. Revised version :: // EY case - esc field checked means , task will be created on primary cont of specific acc // after insert, after update public class CaseHandler{ public static void taskCreation(List<Case> newCases, Map<Id, Case> oldMapCases){ Case oldCase= new Case(); Set<Id> accIds = new Set<Id>(); Map<Id,Contact> contMap = new Map<Id, Contact>(); List<Task> tasksToUpdated = new List<Task>(); for(Case cs : newCases){ if(oldMapCases != null){ oldCase = oldMapCases.get(cs.Id) if(cs.Escalation && cs.Escalation != oldCase.Escalation && cs.AccountId != null){ accIds.add(cs.AccountId); } } else{ accIds.add(cs.AccountId); } } List<Contact> contactList = [SELECT Id, PrimaryContact FROM Contact WHERE PrimaryContact = true && AccountId IN: accIds ORDER BY CreatedDate DESC]; for(Contact con : contactList){ if(!contMap.containsKey(con.Id)){ Task tk = new Task(); tk.WhoId = con.Id; tk.Subject = 'Follow up task'; tasksToUpdated.add(tk); } } if(!tasksToUpdated.isEmpty()){ insert tasksToUpdated; } } }

  • @rajenderv5442
    @rajenderv5442 หลายเดือนก่อน

    your voice not clear and your explanation very hurry please explain slowly

  • @prasadmuthyala9625
    @prasadmuthyala9625 หลายเดือนก่อน

    If we use order by and offset can we decrease lines of code??

  • @bhai9458
    @bhai9458 หลายเดือนก่อน

    when changed the parent on contacts, and if the parent has more than 2 contacts it should throw error while chainging parent also give me code sir,

  • @Salesforce_M
    @Salesforce_M หลายเดือนก่อน

    Trigger PreventMoreThanTwoContacs on Contact (before insert) { Set<Id> accountIds = new Set<Id>(); for (Contact contact : Trigger.new) { if (contact.AccountId != null) { accountIds.add(contact.AccountId); } } List<Account> accountsWithContacts = [ SELECT Id, (SELECT Id FROM Contacts) FROM Account WHERE Id IN :accountIds ]; for (Contact contact : Trigger.new) { if (contact.AccountId != null) { for (Account account : accountsWithContacts) { if (account.Id == contact.AccountId && account.Contacts.size() >= 2) { contact.addError('This Account already has two Contacts. You cannot add more.'); } } } } }

  • @parthipan0345
    @parthipan0345 หลายเดือนก่อน

    Great.. it will work for single account but its wont work for bulk records because it will store second highest amount for account getting in list. We may need to use map to store accountid and second highest amount.

    • @sfdcninjas
      @sfdcninjas หลายเดือนก่อน

      Hi buddy, yes you are correct in upcoming video i am going to show for bulk records as well. But can you please comment your approach it will help me and others to learn new things. Thanks

    • @gaurangi8834
      @gaurangi8834 หลายเดือนก่อน

      Can we use it ? for(Account acc: [select id,(select id, Amount from Opportunities order by Amount desc offset 1 limit 1) from Account where Id IN:accids]){ Account accrec = new Account (); accrec.id=acc.id; Accrec.description=acc.opportunities.Amount;}

  • @shyanilmishra6169
    @shyanilmishra6169 หลายเดือนก่อน

    Thank you very much sir

  • @DudekulaBrahmam-h2m
    @DudekulaBrahmam-h2m หลายเดือนก่อน

    There was an issue in above trigger that I have updated the parent account of an opportunity in this scenario updated parents account total sum is updated properly but the old parent accounts total sum is showing incorrect.