0

I have two custom Objects Member and Issue.

Issue has a master detail relationship with member. The field called MASTER of Issue is a master-detail field that points to Member object.

I'm creating a trigger to update a field of member based on certain criterion:

trigger RollbackUpdate on sade__Issue__c (before insert, before update) {
    for (sade__Issue__c childObj : Trigger.new) {
        if(childObj.sade__Approval_Status__c != null && childObj.sade__Approval_Status__c.equals('Rejected')){
            Id mID = Id.valueOf(childObj.sade__Member__c);
            sade__Member__c me = Database.query('SELECT Id,sade__Membership_ID__c,sade__No_of_Books_Issued__c FROM sade__Member__c WHERE Id =:'+mID+'  LIMIT 1');
            me.sade__No_of_Books_Issued__c -= 1;
            update me;
        }
    }
}

Now, when I'm rejecting an approval I get this issue:

RollbackUpdate: execution of BeforeUpdate caused by: System.QueryException: Variable does not exist: a0H28000002IOujEAG

But I do have a member with ID a0H28000002IOujEAG. Workbench Query SELECT Id,Name FROM sade__Member__c WHERE Name = 'Abhishek De' returns:

    Id                  Name
1   a0H28000002IOujEAG  Abhishek De
1
  • sade__Member__c me = [SELECT Id,sade__Membership_ID__c,sade__No_of_Books_Issued__c FROM sade__Member__c WHERE Id =:mID LIMIT 1];
    – Himanshu
    Mar 1, 2016 at 6:16

1 Answer 1

1

Try like this

Issue in you query you need to add Id =\''+mID+'\'

sade__Member__c me = Database.query('SELECT Id,sade__Membership_ID__c,sade__No_of_Books_Issued__c FROM sade__Member__c WHERE Id =\''+mID+'\'   LIMIT 1');

For a side note.. Your DML and query inside for loop. Store sade__Member__c in a list and update outside of for loop. Do same for query as well.

Else you can hit governor limit..

4
  • Thanks. This works. However -1 update is not working. Can you help? Mar 1, 2016 at 6:18
  • @AbhishekDey are you getting any error?
    – Ratan Paul
    Mar 1, 2016 at 6:20
  • Update is not happening. Mar 1, 2016 at 6:20
  • @AbhishekDey Can you replace this line ` me.sade__No_of_Books_Issued__c -= 1;` with me.sade__No_of_Books_Issued__c = me.sade__No_of_Books_Issued__c != null ? me.sade__No_of_Books_Issued__c - 1 : 0; this and try
    – Ratan Paul
    Mar 1, 2016 at 6:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .