• M.Mehtab
  • 0 Points
  • Member since 2012

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 0

I am very new to Apex development and this is my very first trigger. I am trying to update a custom field 'No_on_Call__c' on Tasks which counts the number of people that are on the call since we activated the Shared Activites feature recently.

When saving a test task the trigger gives me a SELF REFERENCE error and says it cannot recursively update itself. It makes sense but i just cannot figure out how to fix this and it is frustrating me no end.


Here is the code:


trigger Numberofcalls on Task (before insert,before update) {

Integer i=0;

// Get TaskID

String TskID= Trigger.new[i].Id;

list<TaskRelation> Tsr= [SELECT RelationId  FROM TaskRelation WHERE TaskId = :TskID];

list<Task> Tsk= [Select No_on_Call__c FROM Task WHERE Id =: TskId];

for (Task o : Tsk) {
                Integer count = Tsk.size();

                if (o.No_on_Call__c != count) {
                    o.No_on_Call__c = count;
         Update o;