Skip to main content
Hi,

 

I have two record type the name "QBR" and "Adoption" in Task Object where I have to find the latest Due date from "QBR" and display it in user "Last QBR Date" which is a field in Account object. Likewise, from "Adoption" there are 12 fields base on the latest due date these data should get updated automatically another 12 field which all are in account object. I already wrote a trigger for the above requirement, but the issue here is,

 

when I create a task1 "OBR" or "Adoption" who's due date is 31_2_2018 and another task2 with the due date 31_3_2018, where it suppose to update the field that is in Task2,

 

below the code,

 

trigger QBRDueDateUpdatetoAccount on Task (after insert, after update) {

 

  

 

Id recTypeId1= Schema.getGlobalDescribe().get('Task').getDescribe().getRecordTypeInfosByName().get('QBR').getRecordTypeId();

 

Id recTypeId2= Schema.getGlobalDescribe().get('Task').getDescribe().getRecordTypeInfosByName().get('Adoption').getRecordTypeId();

 

Set<Id> accountIds = new Set<Id>();

 

Set<Id> recordSetId = new Set<Id>();

 

   for(Task t:Trigger.new)

 

   {

 

     if(String.valueOf(t.Whatid).startsWith('001'))

 

     {

 

       if(t.recordtypeid.equals(recTypeId1) || t.recordtypeid.equals(recTypeId2))

 

       {

 

           accountIds.add(t.whatid);  

 

           recordSetId.add(t.recordtypeid);       

 

       }

 

       

 

     } 

 

   }

 

  

 

  

 

  if(!accountIds.isEmpty())

 

  {

 

   

 

   List<Account> acc=[select id,Last_QBR_Date__c,Template_Deployed_Date__c,Number_of_Objects_Managed__c,No_Of_APS_Requests__c,

 

                      No_of_Dashboards__c,Total_Login__c,Number_of_users_added_to_the_system__c,No_of_Devices__c,Number_of_Certificates_Managed__c,

 

                      No_of_Backup__c,Enable_Disable_Performed__c,No_of_Roles__c,Certificate_Requests_Renewals_Push_to__c,SM_AVPs__c,

 

                      (select id,Adoption_Run_Date__c,No_of_Objects_managed__c,Number_of_APS_requests__c,No_of_Dashboards__c,No_Of_Users__c,No_of_Roles__c,

 

                      No_of_Devices__c,No_of_Certificate_managed__c,No_Of_Backup__c,No_Of_Enable_Disable_Performed__c,No_of_Login__c,

 

                      No_of_CR_Renewal_Push_to__c,ActivityDate,recordtypeid from tasks where recordtypeid IN :recordSetId AND status='Completed') 

 

                      from Account where id IN:accountIds];

 

   

 

   for(Account a:acc)

 

   {

 

     for(Task acctask: a.tasks)

 

     {

 

        if(accTask.recordtypeid.equals(recTypeId2))

 

        {

 

         if(a.Last_QBR_Date__c==null || (a.Last_QBR_Date__c!=null && a.Last_QBR_Date__c > acctask.ActivityDate) )

 

         {

 

           a.Last_QBR_Date__c=acctask.ActivityDate;

 

           a.Template_Deployed_Date__c=acctask.Adoption_Run_Date__c;

 

           a.Number_of_Objects_Managed__c=acctask.No_of_Objects_managed__c;

 

           a.No_Of_APS_Requests__c=acctask.Number_of_APS_requests__c;

 

           a.No_of_Dashboards__c=acctask.No_of_Dashboards__c;

 

           a.Total_Login__c=acctask.No_Of_Users__c;

 

           a.Number_of_users_added_to_the_system__c=acctask.No_of_Roles__c;

 

           a.No_of_Devices__c=acctask.No_of_Devices__c;

 

           a.Number_of_Certificates_Managed__c=acctask.No_of_Certificate_managed__c;

 

           a.No_of_Backup__c=acctask.No_Of_Backup__c;

 

           a.Enable_Disable_Performed__c=acctask.No_Of_Enable_Disable_Performed__c;

 

           a.No_of_Roles__c=acctask.No_of_Login__c;

 

           a.Certificate_Requests_Renewals_Push_to__c=acctask.No_of_CR_Renewal_Push_to__c;

 

         }

 

        }

 

       

 

       if(accTask.recordtypeid.equals(recTypeId1))

 

        {

 

         if(a.Last_QBR_Date__c==null || (a.Last_QBR_Date__c!=null && a.Last_QBR_Date__c > acctask.ActivityDate) )

 

         {

 

           

 

         }

 

        }

 

       

 

     }

 

     

 

   }

 

   

 

   update acc;

 

  } 

 

}

 

 Can someone help me on this

 

Thanks in advance
2 个回答
  1. 2018年3月7日 12:31
    Hello Manoj,

     

    Appreciate your time that you have taken to make this post.

     

    I would like to suggest you post this question into Developer Forum or Salesforce Stack Exchange where you will get more and best answer because this community is related to configuration.

     

    Developer Forum

     

    https://developer.salesforce.com/forums

     

     

    Salesforce Stack Exchange

     

    https://salesforce.stackexchange.com/

     

    Regards,

     

    Harsh
0/9000