+ Start a Discussion
tmbarrytmbarry 

Access a field on a Child record

Hello All, 

 

I am trying to write a trigger to update the fields on an object based on the completion of a task.

 

trigger UpdateSentMail_02 on Task (after Insert, after update){ 

Integer i = 0;

// Tasks that meet criteria, and new tasks to create
Task[] qualifiedTasks = new Task[0], newTasks = new Task[0];
    
// Map of SD Members
   Map<Id,SD_Member__c> members = new Map<Id,SD_Member__c>();

// Find qualifying tasks
for(Task record:Trigger.new)
        if(Record.subject!=null && record.subject.contains('Print Sf Order Submitted') && record.status == 'Completed')
           qualifiedtasks.add(record);
    
    // Obtain member ID values
    for(Task record:qualifiedtasks)
        members.put(record.whatid,null);
   
    // If there are any membes to query, do so.
    if(!members.isempty())
        members.putall([select id from SD_Member__c where id in :members.keyset()]);


     for(Task record:qualifiedtasks) {
        members.get(record.whatid).Send_Monthly_Letter__c=False;
    }
    
     update members.values();
// Get the current Letter Counter value
    i == (members.get(record.whatid).letter_counter__c);
// Increase the Letter Counter by 1
    i=i+1;

    for(Task record:qualifiedtasks) {
        members.get(record.whatid).Send_Monthly_Letter__c=True;
        members.get(record.whatid).Make_1st_Follow_Up_Call__c=False;
        members.get(record.whatid).Make_2nd_Follow_Up_Call__c=False;
        members.get(record.whatid).Make_3rd_Follow_Up_Call__c=False;
        members.get(record.whatid).Letter_Counter__c=i;
    }
    
    update members.values();
}

 I issue I am havin is with this line:

// Get the current Letter Counter value
    i == (members.get(record.whatid).letter_counter__c);
// Increase the Letter Counter by 1
    i=i+1;

 I need to get the orginal SD_Member__c.Letter_Counter__c value so I can increase it by one.  I was hoping it was as simple as my code above, but I am getting the following error message:

 

Variable does not exist: record.whatid at line 31 column 23

 

Any ideas how I can get the Letter_counter__c value?

 

Marko LamotMarko Lamot

you are reffering to   "record.whatid" out of the for loop  where you define record

tmbarrytmbarry
Ok, I moved the statement to different parts of my code and still can not get it to work. Could you be more specific?
Avidev9Avidev9
Can you post your edited code ?