function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Need help creating a related list record

Hi All,


I have written a trigger which will add a record in the related list, the condition for adding the record is that...

1. <Is Launch>: TRUE first, FALSE later 2. <Track Root Cause>: TRUE first, FALSE later. 3. <Actual Completion Date>: descending (later first)


it should check the first two value if condition doesn't met then sort the related list based on Actual completion date and copy that record in the new record..below are my code....

trigger CreateRootCause1 on Project__c (after update) {

  if(trigger.newmap.get('In Cancellation'||  trigger.newmap.get('In Closing'){
 List<Task__c> lsttask=new List<Task__c>();
 lsttask=[select id,name,Project__c,Is_Launch__c,Actual_completion_date__c,Target_Date_current_baseline__c from Task__c where (Is_Launch__c=true OR Track_Root_Cause__c=true) AND Order by Actual_completion_date__c desc limit 1];
 List<Root_Cause__c> lstrc=new List<Root_Cause__c>();
for(Task__c t:lsttask){
     Root_Cause__c RCDel= new Root_Cause__c();
     RCDel.Name=t.Name +' - '+'Final';;         
    insert lstRc;

here am not abe to achieve the 3rd condition if both the second condition fails then it should copy the record from 3rd one
Bindhyachal Kumar SinghBindhyachal Kumar Singh

Hi Irish@acc


Use following instead of you query:


lsttask=[select id,name,Project__c,Is_Launch__c,Actual_completion_date__c,Target_Date_current_baseline__c from Task__c where Order by Actual_completion_date__c,Is_Launch__c,Track_Root_Cause__c desc limit 1];