You need to sign in to do that
Don't have an account?

Apex Class 'OR' expression confusion
Hi
We have a custom visualforce page that has it's content pulled to it by different Apex Classes.
In short, the records pulled are determined by their record type + a certain field entry.
Right now the Apex Class pulls in RecordTypeA results.
I can edit it (and the Test Class) to pull in RecordTypeB results.
However, when I use the 'OR' expression to have both of the RecordType results show up, only RecordTypeA results are shown up.
This is the code piece (syntax gave no errors)
Is there something else that needs to be added to the code for it to process both record type results?
Thank you
We have a custom visualforce page that has it's content pulled to it by different Apex Classes.
In short, the records pulled are determined by their record type + a certain field entry.
Right now the Apex Class pulls in RecordTypeA results.
I can edit it (and the Test Class) to pull in RecordTypeB results.
However, when I use the 'OR' expression to have both of the RecordType results show up, only RecordTypeA results are shown up.
This is the code piece (syntax gave no errors)
for(recordtype rt:[select id from recordtype where (name=:'1893 Ambassador Request' OR name=:'WebAMB Request') and Sobjecttype =: 'Case' limit 1]) caserecordtype=rt.id; for(recordtype rt:[select id from recordtype where name=: 'CustomerUK' and Sobjecttype =: 'Account' limit 1]) accountrecordtype=rt.id;
Is there something else that needs to be added to the code for it to process both record type results?
Thank you
As far as the SOQL, I believe you can just use IN to make the queries work instead of OR. Not that it helps the issue, but a thought.
for(recordtype rt:[select id from recordtype where name IN('1893 Ambassador Request', 'WebAMB Request') and Sobjecttype =: 'Case' limit 1])
{caserecordtype=rt.id};
for(recordtype rt:[select id from recordtype where name = 'CustomerUK' and Sobjecttype = 'Account' limit 1])
{accountrecordtype=rt.id};
Also, I've not used "=:" in SOQL. Does it work as you expect?
https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql_select_comparisonoperators.htm
SOQL fetches records randomly in no particular order. If you want the records to be fetched in some order like the one that is the most recently created, you have to use ORDER BY. Else, it is just random. So any one record which satisfy the conditions in your where clause will be fetched. You got only RecordTypeA when you tried doesn't mean that only RecordTypeA will be fetched always.
Thanks
@Squire HomerJ Kershner
Variable rt refers to recordtype and it is looping through Cases where the Status field is set to Accepted.
I've tested the suggested idea with 'IN' expression, but the result are still the same, it will only display the '1893 Ambassador Request' records in the list.
As for the "=:" in SOQL, it does seem to work as expected so far.
@Jithin Krishnan 2
Yes that is true, but on the current list, there will be no RecordTypeB results at all. Ever.
It doesn't seem to matter if I use 'OR' or 'IN' expression for the list to include both results.
Individually I can set the Class to bring up either only RecordTypeA results, or only RecordTypeB results, but any sort of expression to include both of them will result only RecordTypeA results to show up.
Here is the full code if that may be useful:
Hi
Some updates.
Removing the LIMIT will make only RecordTypeB records visible.
Using ID's instead of names for RecordTypes makes no difference.