As soon as an Opportunity is deleted, create a Task for the Opportunity’s parent Account Owner

แชร์
ฝัง
  • เผยแพร่เมื่อ 16 ก.ย. 2024

ความคิดเห็น • 41

  • @saikumarreddy.t6038
    @saikumarreddy.t6038 ปีที่แล้ว +1

    Hi Bro, Very Informative videos thank u so much

  • @choutomaharaj4772
    @choutomaharaj4772 5 หลายเดือนก่อน +1

    All the hardwork for finding OwnerId is unnessessary because the error is coming because of WhatId, i just task.ownerid=opp.ownerid, and it work like a charm. Please note that I am not condaming or anything, I love your content but pointing out error.

    • @salesforcemakessense
      @salesforcemakessense  5 หลายเดือนก่อน +1

      No thats really good if you were able to figure out while writing it. Thats the idea of use cases and there are multiple ways of doing it.
      Happy learning 🙂

  • @user-pz5ys9mj2q
    @user-pz5ys9mj2q 9 หลายเดือนก่อน +1

    Mind Blowing

  • @Ankitkumar-ro6fl
    @Ankitkumar-ro6fl 2 หลายเดือนก่อน +1

    even we dont requre set of accounids.we can fulfill need of accountid by map values. am i right?

  • @Ankitkumar-ro6fl
    @Ankitkumar-ro6fl 5 หลายเดือนก่อน +1

    hi, himanshu nice explaination, I have a question ...we can not use opp.id to assign task.whatid...it is ok but we are using opp.id when we are assigning owner id to task...how it is possible ?

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

      Hi Ankit, can you rephrase your question please? I am unclear of whats the ask

    • @salesforcemakessense
      @salesforcemakessense  5 หลายเดือนก่อน +1

      To assign owner we should use ownerId not oppId as oppId is opportunity and ownerId is the user id

  • @user-qy2sv9li9v
    @user-qy2sv9li9v 7 หลายเดือนก่อน +1

    Hi Himanshu, Hope I am not too late to make a comment,
    I have a question here, why can't we use opp.OwnerId because the OwnerId of Parent 'Account' and Child 'Opportunity' will be same.
    And Sorry if I am not making sense here.

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

      What if Opportunity is reassigned to a new owner before deletion

  • @kunalmarathe1855
    @kunalmarathe1855 6 หลายเดือนก่อน +1

    can u share all the usecases and answer in document

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

      Hi Kunal, I dont have that handy at the moment.

  • @SfdcLearner
    @SfdcLearner 5 หลายเดือนก่อน +1

    Bro, I have a Question.
    I know we can Update Child Records on After Update trigger. Can we Update Child on Before Update ! If no, Why !

    • @salesforcemakessense
      @salesforcemakessense  5 หลายเดือนก่อน +1

      So, ideally you would want to update related records ONLY AFTER the parent is updated.
      Consider this: If parent update failed, you would end up updating child records as you have written code in before update.
      Since after update ensures your commit is successful, it opens the gate to update related records.
      Hope that makes sense :)

    • @SfdcLearner
      @SfdcLearner 5 หลายเดือนก่อน +1

      @@salesforcemakessense Man you are making Salesforce Make Sense really ♥️

    • @salesforcemakessense
      @salesforcemakessense  5 หลายเดือนก่อน +1

      @@SfdcLearner thats the plan 😄

  • @gauravjoshi3879
    @gauravjoshi3879 9 หลายเดือนก่อน +1

    Hi bro, can we do with a single map

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

      Mostly yes, I will encourage you to give it a try.

  • @srivalligodavarthi9109
    @srivalligodavarthi9109 ปีที่แล้ว +1

    too much logical thinkings neede for this scenario. as a fresher can do it?☹

    • @salesforcemakessense
      @salesforcemakessense  ปีที่แล้ว +1

      Take it slow, understand every line thats been written. Assess why I have written it, try to make sense of it and then write it on your console too and make sense of it again. This way you will get the hang dont worry.

  • @rajeshganne8359
    @rajeshganne8359 3 หลายเดือนก่อน +1

    Too much confusion

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

      Hi Rajesh, have you started the playlist from the very first video?

  • @alishalinski
    @alishalinski 6 หลายเดือนก่อน +1

    Thank u for all videos
    I’ve done it this way , just wanted to share
    public class OpportunityTriggerHandler {
    public static void createTaskForAccOwner(list oppTriggerold,Map oppTriggerOldMap){
    set accIds = new set();
    for(Opportunity eachOpp : oppTriggerold){
    if(eachOpp.AccountId!=null){
    accIds.add(eachOpp.AccountId);
    }
    }
    Map accMap = new Map([select id,OwnerId from account where Id IN:accIds]);
    list accOwnerTaskList = new List();
    for(Opportunity eachOpp : oppTriggerold){
    Task accOwnerTask = new Task();
    accOwnerTask.OwnerId = accMap.get(eachOpp.AccountId).OwnerId;
    accOwnerTask.WhatId = eachOpp.AccountId;
    accOwnerTask.Priority= 'High';
    accOwnerTask.Subject = 'Please find out the reason of deletetion of opportunity named: '+eachOpp.Name;
    accOwnerTaskList.add(accOwnerTask);
    }
    if(!accOwnerTaskList.IsEmpty()){
    insert accOwnerTaskList;
    }
    }
    }

    • @salesforcemakessense
      @salesforcemakessense  6 หลายเดือนก่อน +1

      Looks good to me Alisha, well done!

    • @maheshbabu-te8sk
      @maheshbabu-te8sk หลายเดือนก่อน

      hi i thinkk Triggeroldmap is not needed anyway ur fetching oldmapids

  • @sasireddypolimera
    @sasireddypolimera 11 หลายเดือนก่อน +1

    i think u made it some what Complicated using Two Maps , crt me if i didnt follow the best pratices and didnt work for bulk records -- >
    trigger OppdeleteTaskAccOwner on Opportunity (after delete) {
    Set setid=new Set();
    for(Opportunity opp:Trigger.old){
    if(opp.AccountId!=null){
    setid.add(opp.AccountId);
    }
    }
    List tsklist=new List();
    Map mapowner=new Map();
    List acclist=[select Id,OwnerId from Account where Id IN:setid];
    for(Account acc:acclist){
    mapowner.put(acc.Id,acc.OwnerId);
    }
    for(Account accrec:acclist){
    Task tsk=new Task();
    tsk.Subject='Call';
    tsk.Status='Completed';
    tsk.Priority='Low';
    tsk.Description='Opp Record deleted please do inquiry';
    tsk.OwnerId=mapowner.get(accrec.Id);
    tsklist.add(tsk);
    }
    insert tsklist;
    }

    • @salesforcemakessense
      @salesforcemakessense  11 หลายเดือนก่อน +1

      The idea is to explain a use case but also explain situations and scenarios and what can you do with what you have.
      But yes the solution you have provided here looks correct on first glance, so its a better approach to this problem for sure.
      Hope you got the idea.

    • @sasireddypolimera
      @sasireddypolimera 11 หลายเดือนก่อน +2

      @@salesforcemakessense but ur videos are too good broo, nice explanation and good content ❣️❣️

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

      @@sasireddypolimera thank you 🙏

    • @gauravjoshi3879
      @gauravjoshi3879 9 หลายเดือนก่อน +1

      thankyou

  • @wasim-bh2wt
    @wasim-bh2wt 4 หลายเดือนก่อน +1

    public static void handleActivitiesAfterDelete(List oldRecords){

    Set accountIds = new Set();
    Map oppvsAccountMap = new Map();
    Map accIdVsOwnerIdMap = new Map();

    for(Opportunity opp : oldRecords){
    accountIds.add(opp.AccountId);
    oppvsAccountMap.put(opp.Id, opp.AccountId);
    }
    for(Account acc : [Select Id, OwnerId From Account Where Id IN : accountIds]){
    accIdVsOwnerIdMap.put(acc.id, acc.OwnerId);
    }

    List taskRecordList = new List();
    for(Opportunity opp : oldRecords){

    Task taskRecord = new Task();
    taskRecord.Priority = 'High';
    taskRecord.Description = 'Task Created Successfully';
    taskRecord.Subject = 'Follow Up';
    taskRecord.OwnerId = accIdVsOwnerIdMap.get(oppvsAccountMap.get(opp.Id));
    taskRecordList.add(taskRecord);

    }

    if(!taskRecordList.isEmpty()){
    insert taskRecordList;
    }
    }