You need to sign in to do that
Don't have an account?
kathybb
Getting compile error on Set constructor - Unexpected token ']'
I'm stuck in a Test program. I'm getting the 'Unexpected token ']' on an attempt at a Set Constructor. Here's the relevant code:
string noteString = 'KBB Test PO'; Set<Id> findPOIds = new Set<id>([select id from SFDC_Purchase_Order__c where PO_Notes__c.contains(noteString)]); List<string> POIdList = database.query(findPOIds); string findTestPOs = [SELECT id, name,Finalized__c,PO_Notes__c,Status__c, Ship_to_location__c, Expedite__c, PO_Date__c, Total_Price__c,Category__c,SFDC_Purchase_Order__c.ownerID FROM SFDC_Purchase_Order__c WHERE id in (:POIdList)]; string findTestPRs = [SELECT id, OwnerId, CreatedBy.id, CreatedBy.Name,name, new_Item_Description__c, Status__c,Request_Date__c,Receive_by_Date__c,Quantity__c,Item_Requested__r.name,Department__c, Item_Requested__r.Price_per_Unit__c, Extended_Price__c,Purchase_Order__r.id FROM SFDC_Purchase_Requisition__c WHERE Purchase_Order__r.id in (:POidList)]; List<SFDC_Purchase_Order__c>myNewPOs = new List<SFDC_Purchase_Order__c>((List<SFDC_Purchase_Order__c>)database.query(findTestPOs)); List<SFDC_Purchase_Requisition__c>myNewPRs = new List<SFDC_Purchase_Requisition__c>((List<SFDC_Purchase_Requisition__c>)database.query(findTestPRs));
I have a couple of questions -- Why won't this compile? , What do I need to do to fix it? and -- How can the right bracket be unexpected when it seems fine with the left bracket?
I'm very grateful for any insight anyone can offer
Thanks a lot.
Karhybb
I think the problem is with the WHERE clause. It should be something like this:
where theBooleanField = :PO_Notes__c.contains(noteString)
Contains is not supported in SOQL query. What you can do is to use like
String noteStringBefore = '%KBB Test PO';
String noteStringAfter = 'KBB Test PO%';
String noteStringMiddle = '%KBB Test PO%';
Set<Id> findPOIds = new Set<id>([select id from SFDC_Purchase_Order__c where (PO_Notes__c LIKE : noteStringBefore OR PO_Notes__c LIKE : noteStringAfter OR PO_Notes__c LIKE : noteStringMiddle)]);
If this post is helpful please throw Kudos.If this post solves your problem kindly mark it as solution.
Thanks