You need to sign in to do that
Don't have an account?
Strange one - passing in string for includes query not working
Hi All,
Sorry this is long one - been hard at this since my last post. Very close, now stumped as something just doesn't added up!
This is strange - the following query works fine
select Id, Name, Accreditations__c from Account where Type = 'Dealer' AND Country_ISO_Code__c = 'CH' AND Accreditations__c includes ( 'RAP','REX' ) AND Accreditations__c != null
Note: Searching for RAP or REX.
Now inside my class I am doing this:
String stEndorsements; String stMulti; public String getStEndorsements(){ stMulti = lead.All_Accreditation_Endorsements__c; stEndorsements = queryString(); return stEndorsements; } public String queryString(){ String[] newList = stMulti.split(';'); String newString = ''; for (Integer i = 0; i < newList.size(); i++){ if (newList.size() != (i+1)){ newString += '\'' + newList[i] + '\',' ; } else { newString += '\'' + newList[i] + '\'' ; } } return newString; }
Now this works fine too, checked through EA and using System.Debug
Here is where it's called
List<Account> accs = new List<Account>(); String prodcode = getProductCode(); if (prodcode==null){ getStEndorsements(); String endor = stEndorsements; System.debug('DEBUG ERROR = '+endor); List<Account> fromLead = [select Id, Name, BillingCity, Country_ISO_Code__c, Owner.Name, Type, Accreditations__c from Account where Type = 'Dealer' AND Country_ISO_Code__c =: lead.Country_ISO__c AND Accreditations__c includes (: endor ) AND Accreditations__c != null LIMIT 1000]; accs = fromLead; }
Here is the debug log
22:56:35.315|METHOD_EXIT|[85]|LeadExtensionController.queryString() 22:56:35.315|METHOD_EXIT|[165]|LeadExtensionController.getStEndorsements() 22:56:35.315|METHOD_ENTRY|[169]|System.debug(ANY) 22:56:35.315|USER_DEBUG|[169]|DEBUG|DEBUG ERROR = 'RAP','REX' 22:56:35.315|METHOD_EXIT|[169]|System.debug(ANY) 22:56:35.315|SOQL_EXECUTE_BEGIN|[171]|Aggregations:0|select Id, Name, BillingCity, Country_ISO_Code__c, Owner.Name, Type, Accreditations__c from Account where Type = 'Dealer' AND Country_ISO_Code__c =: lead.Country_ISO__c AND Accreditations__c includes (: endor ) AND Accreditations__c != null LIMIT 1000 22:56:35.357|SOQL_EXECUTE_END|[171]|Rows:0
The string I am passing in to the includes looks correct to me - can anyone spot what I am doing wrong.
Thanks
Try making endor a List<String>
Hi Kevin - thanks for response
Not sure I understand - I don't explicitly know the values
Do you mean replace this part with a String<List>
Still stuck - here is the whole class
Make queryString() return a list of the strings (instead of one formatted string) that you want to use for your includes statements.
You need to add single quotes for each value and then add the ( (start)and ) (end) and send it via dynamic apex.
Hi Kevin,
Only just getting back to this one
Not sure I understand & here is why
The line below causes an illegal assignment error e.g. String to List
Do I need to convert this from string to list?
Also this is expecting a string value hence why I built out the string value
May be I don't understand what you mean
Hi Hisrinu,
Here is what my string looks like - 'RAP','REX' in debugger, then passed in like this (:endor)
Please can you expand on what you mean by ( (start)and ) (end) e.g. formatting
Thanks