SFDC Ninja
SFDC Ninja
  • 72
  • 427 042

Відео

Apex Triggers - 57 (Trigger Interview Scenario)
Переглядів 64914 днів тому
💻 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)
Переглядів 812Місяць тому
💻 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)
Переглядів 947Місяць тому
💻 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,7 тис.Місяць тому
💻 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,7 тис.2 місяці тому
💻 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,7 тис.2 місяці тому
💻 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,2 тис.2 місяці тому
💻 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)
Переглядів 2 тис.2 місяці тому
💻 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,5 тис.3 місяці тому
💻 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,6 тис.3 місяці тому
💻 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,6 тис.3 місяці тому
💻 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,8 тис.4 місяці тому
💻 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
Переглядів 5 тис.4 місяці тому
💻 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)
Переглядів 6 тис.4 місяці тому
💻 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 - 46 (Deloitte Interview Scenario)
Переглядів 5 тис.5 місяців тому
Apex Triggers - 46 (Deloitte Interview Scenario)
Apex Triggers - 45 (Infosys Interview Scenario)
Переглядів 4,4 тис.5 місяців тому
Apex Triggers - 45 (Infosys Interview Scenario)
Apex Triggers - 44 (EY Interview Scenario)
Переглядів 3,5 тис.6 місяців тому
Apex Triggers - 44 (EY Interview Scenario)
Apex Triggers - 43 (Infosys Interview Scenario)
Переглядів 3,6 тис.6 місяців тому
Apex Triggers - 43 (Infosys Interview Scenario)
Apex Triggers - 42 (Trigger Interview Question)
Переглядів 1,7 тис.6 місяців тому
Apex Triggers - 42 (Trigger Interview Question)
Apex Triggers - 41 (Trigger Interview Question)
Переглядів 2,3 тис.7 місяців тому
Apex Triggers - 41 (Trigger Interview Question)
LWC Scenario - 5 (Mini Project)
Переглядів 1,1 тис.7 місяців тому
LWC Scenario - 5 (Mini Project)
LWC Scenario - 4 (Search Functionality in Lightning Datatable)
Переглядів 1,2 тис.8 місяців тому
LWC Scenario - 4 (Search Functionality in Lightning Datatable)
LWC Scenario - 3 (Lightning Record Picker)
Переглядів 1,2 тис.8 місяців тому
LWC Scenario - 3 (Lightning Record Picker)
LWC Scenario - 2 (Server Side Sorting in Lightning Datatable)
Переглядів 1,1 тис.9 місяців тому
LWC Scenario - 2 (Server Side Sorting in Lightning Datatable)
LWC Scenario - 1 (Client Side Sorting in Lightning Datatable)
Переглядів 3,6 тис.9 місяців тому
LWC Scenario - 1 (Client Side Sorting in Lightning Datatable)
Apex Test Class - 5 (Testing Wrapper Class)
Переглядів 1 тис.9 місяців тому
Apex Test Class - 5 (Testing Wrapper Class)
Apex Test Class - 4 (Testing Queueable Class)
Переглядів 68710 місяців тому
Apex Test Class - 4 (Testing Queueable Class)
Apex Test Class - 3 (Testing Batch Apex)
Переглядів 1,2 тис.10 місяців тому
Apex Test Class - 3 (Testing Batch Apex)
Apex Test Class - 2 (Testing DML Operations)
Переглядів 1,4 тис.10 місяців тому
Apex Test Class - 2 (Testing DML Operations)

КОМЕНТАРІ

  • @user-pu2yc3vn2k
    @user-pu2yc3vn2k 11 годин тому

    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 День тому

    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 День тому

      Hi can you please share your code

  • @niteshreddy7891
    @niteshreddy7891 День тому

    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 2 дні тому

    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 2 дні тому

    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 2 дні тому

    pls upload the codes

  • @sfstart9655
    @sfstart9655 3 дні тому

    @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 3 дні тому

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

  • @Anitha-f5m
    @Anitha-f5m 3 дні тому

    Please can you write and show with apex handler

  • @saikrishna2972
    @saikrishna2972 3 дні тому

    Why did this not go into recusrion 🤔

    • @sfstart9655
      @sfstart9655 3 дні тому

      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 3 дні тому

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

  • @shivanandtotar4357
    @shivanandtotar4357 4 дні тому

    good information

  • @shivamsaini7252
    @shivamsaini7252 4 дні тому

    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 7 днів тому

    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 7 днів тому

    want more iterview videos like this for different topics please

  • @sfstart9655
    @sfstart9655 8 днів тому

    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 9 днів тому

    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 11 днів тому

    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 11 днів тому

    Thank you

  • @joharR-ju7ml
    @joharR-ju7ml 11 днів тому

    Thankyou Sir !!!!

  • @Anitha-f5m
    @Anitha-f5m 12 днів тому

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

  • @Anitha-f5m
    @Anitha-f5m 12 днів тому

    hi

  • @Anitha-f5m
    @Anitha-f5m 12 днів тому

    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 16 днів тому

    Nicely explained

  • @kumareshghosh5593
    @kumareshghosh5593 16 днів тому

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

    • @sfdcninjas
      @sfdcninjas 16 днів тому

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

    • @awesomekj5812
      @awesomekj5812 16 днів тому

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

  • @sonalijadhav9446
    @sonalijadhav9446 18 днів тому

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

  • @gauravjoshi3879
    @gauravjoshi3879 21 день тому

    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 22 дні тому

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

    • @Anitha-f5m
      @Anitha-f5m 5 днів тому

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

    • @Anitha-f5m
      @Anitha-f5m 4 дні тому

      @@gurudeep7956 i got it

  • @Lovepassionkarma
    @Lovepassionkarma 23 дні тому

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

  • @kumareshghosh5593
    @kumareshghosh5593 24 дні тому

    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 25 днів тому

    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 23 дні тому

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

    • @anirudh867
      @anirudh867 23 дні тому

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

    • @pravallika-j5d
      @pravallika-j5d 23 дні тому

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

  • @meghanareddy1364
    @meghanareddy1364 26 днів тому

    at what level was this question asked for?

  • @_DheerajIPPILI
    @_DheerajIPPILI 28 днів тому

    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 28 днів тому

    can you please provide a pdf of all your trigger scenario

  • @SANTHOSHKUMAR-ot7uj
    @SANTHOSHKUMAR-ot7uj 28 днів тому

    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 28 днів тому

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

  • @prasadmuthyala9625
    @prasadmuthyala9625 29 днів тому

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

  • @bhai9458
    @bhai9458 29 днів тому

    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 29 днів тому

    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 29 днів тому

    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 29 днів тому

      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 25 днів тому

      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 29 днів тому

    Thank you very much sir

  • @DudekulaBrahmam-h2m
    @DudekulaBrahmam-h2m 29 днів тому

    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.

  • @pranaysawarkar7071
    @pranaysawarkar7071 Місяць тому

    I am waiting for that please try as soon as possible

    • @pranaysawarkar7071
      @pranaysawarkar7071 29 днів тому

      The triggers question are available on trigger no 54 and that scenarios still pending.......

    • @sfdcninjas
      @sfdcninjas 29 днів тому

      Sure pranay, sorry for the delay

  • @pranaysawarkar7071
    @pranaysawarkar7071 Місяць тому

    Hello ninja, I send you Two trigger scenarios but now as well it will not solved

  • @deepakpatil3956
    @deepakpatil3956 Місяць тому

    WRONG Solution, Code will not work for bulkified scenario, it's a good practise to bulkfy triggers.

  • @sedentaryhooman
    @sedentaryhooman Місяць тому

    which company asked this?

  • @_DheerajIPPILI
    @_DheerajIPPILI Місяць тому

    public class Expected { public static void display(List<Contact> conlist) { Set<Id> accids = new Set<Id>(); Map<Id, Contact> contactMap = new Map<Id, Contact>(); List<Contact> modifiedconlist = new List<Contact>(); List<Contact> latestconlist = new List<Contact>(); // Collect Account IDs from the newly inserted contacts for (Contact c : conlist) { if (c.AccountId != null) { accids.add(c.AccountId); } } // Query all existing contacts under the collected Account IDs whre new contact marked as true if (!accids.isEmpty()) { List<Contact> updateconlist = [SELECT Id, Name, New_Contact__c, AccountId FROM Contact WHERE AccountId IN :accids AND New_Contact__c = true]; System.debug('Retrive list of contacts' + updateconlist); // Disable the checkbox for all existing contacts for (Contact c : updateconlist) { c.New_Contact__c = false; modifiedconlist.add(c); contactMap.put(c.Id, c); } } System.debug('Checkpoint-2'); // Enable the checkbox for the newly inserted contacts for (Contact c : conlist) { if (c.AccountId != null) { // Create a new instance to avoid modifying read-only records Contact newContact = new Contact(Id = c.Id, New_Contact__c = true); latestconlist.add(newContact); } } System.debug('Checkpoint-3'); // Update the modified contacts if (!modifiedconlist.isEmpty()) { update modifiedconlist; } if (!latestconlist.isEmpty()) { update latestconlist; } System.debug('Retrive list of new contacts' + latestconlist); System.debug('Checkpoint-4'); } }

  • @shivadumnawar467
    @shivadumnawar467 Місяць тому

    Thank you sir. Awesome series.

  • @pallerlapradeep9955
    @pallerlapradeep9955 Місяць тому

    Thanks for sharing the knowledge. It's very great explanation. It could have more meaningful if the newly created contact is populated with the account which is same as case account.

  • @shariqueiqbal4820
    @shariqueiqbal4820 Місяць тому

    Seems like a problem in the code... Line 24 is not bulkified. And also in line 56, there is an issue. You created a new skill in line 49 and how can u expect the same skill to be present in the map used in line 56. but I would same your channel has some good content. keep up the good work.

    • @diobrando1253
      @diobrando1253 19 днів тому

      You are right, we can put the skill in the map after insert of line 49 then it will be solved, please correct me if I'm wrong.