You need to sign in to do that
Don't have an account?
Jonathan Osgood 3
Multiple Record Types in SOQL
Want my soql query to find records with specific record types. OR stement returning error: expecting right square bracket, found 'OR'
Do I need to create additional soql queries to first obtain record types, then reference in existig soql?
Thanks!
Existing soql
Do I need to create additional soql queries to first obtain record types, then reference in existig soql?
Thanks!
Existing soql
List<AggregateResult> results = [SELECT Account__c, SUM(X2_1_a_Total_of_jobs_Year_0__c) mysum0, FROM Form__c WHERE Account__c IN:accountIds AND (RecordType.DeveloperName ='Baseline Report') OR (RecordType.DeveloperName ='Annual Report') GROUP BY Account__c] ;
You could use your existing SOQL, but make sure the text you put in is actually the developer name, not the name. I imagine it is exactly what Vivek originally suggested, but with underscores rather than spaces: I would definitely use the RecordTypeInfosByName method when you are trying to create new records with a specific record type, or when checking a record's record type in trigger context, but for SOQL I think what you were trying to do is best.
All Answers
Try below SQL and let me know if it works.
Best Regards,
-Vivek Deshmane
That clears out the error, but the soql returns 0 results. I've tried in dev console querying tool with same result. This syntax has worked for me before, but I think I may to do something like:
then reference in my existing soql.
I was hoping to avoid another soql query though
Use below coe to get Recordtype id without SOQL Query.
Let me know if it works and mark best answer.
Best Regards,
-Vivek Deshmane
The syntax was a little different, but very close. This worked:
Id BaselineRecordTyepId = Schema.SObjectType.Form__c.RecordTypeInfosByName.get('Baseline Report').RecordTypeId;
If this helps you please mark as best answer.
Best Regards,
-Vivek Deshmane
You could use your existing SOQL, but make sure the text you put in is actually the developer name, not the name. I imagine it is exactly what Vivek originally suggested, but with underscores rather than spaces: I would definitely use the RecordTypeInfosByName method when you are trying to create new records with a specific record type, or when checking a record's record type in trigger context, but for SOQL I think what you were trying to do is best.
This is very helpful. I went back to the oringal soql approach, but as mentioned, put in the record type api name this time! Can't beleive I missed that! Good to know I'm not crazy as I've used this approach before! On the upside, I now have a better idea of when to use apex and when to use soql. Use case matters. Here's a great Stack Exchange post I found for both plus a third, industrial-strength Force.com application using a utility class. (http://salesforce.stackexchange.com/questions/11968/what-would-be-the-best-approach-to-get-the-recordtype-id)
trigger Contact_Importance_Update on Account (before update) {
Id recTypeId = Account.sObjectType.getDescribe().getRecordTypeInfosByName().get('Exhibitor').getRecordTypeId();
List<Account> accountsToVerify = new List<Account>();
Thanks,
Lakis