You need to sign in to do that
Don't have an account?
Edwards71
Selecting Task records associated with a particular custom object
Hi,
I'm trying to extract a list of Task Records that are related to a custom object. I'm using the getkeyprefix to identify the 3 digits so I can use this with WhatId.
I'm getting a ' compile error unexpected token GDIPrefix' on the code below. Any ideas why?
Thanks in advance!
Public Task [] getNotListing() { String GDIPrefix = GDI_Action__c.sObjectType.getDescribe().getKeyPrefix(); system.debug(GDIPrefix); return [Select ActivityDate, subject,Description, Contract_reference__c, OwnerID, whoID, whatID FROM Task where AccountId = :System.currentPageReference().getParameters().get('id') and ActivityDate < NEXT_YEAR and WhatID Like GDIPrefix order by ActivityDate ASC]; }
Thanks - you're right. You can't use Like or most other operators with an ID field.
I got this code to work. Thanks for your help.
All Answers
Your code here looks correct. I suspect you have a missing closing curly bracket ( "}" ) further up in your code. This would cause the next function after the function missing the curly bracket to throw this sort of red-herring error.What Chris said. I can't believe I missed that.
When you reference a class variable from a soql query (inside [brackets]), you have to prefix it with a colon.
Thanks. I've put the colon in and now get a 'compile error: invalid operator on id field'.
The code works fine if I delete the ..and WhatId like :GDIPrefix .. bit of the code
Hmmm, right, probably can't use LIKE on an ID field...not sure how to get around that one in SOQL...maybe create a custom field (text) that contains the WhatId value (set by workflow? possibly a formula?)...then you can use LIKE on that field...there may be a better way.
Thanks - you're right. You can't use Like or most other operators with an ID field.
I got this code to work. Thanks for your help.