You need to sign in to do that
Don't have an account?
ckellie
Creating Integer if
I have created an integer that acts as a counter for the number of quote records with the same opportunity id as noted below:
Integer bi = [select count() from Quote where opportunityid = :oid];
I have added two record types on the Quote record; Budget Quote and Firm Quote. I would like to limit the above code to the Budget Quote recordtype. I have tried the following:
Integer bi = [select count() from Quote where opportunityid = :oid and recordtypename='Budget Quote'];
and I recieve the following error:
Compile Error: No such column 'recordtypename' on entity 'Quote'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
How do i solve this error?
Thank you
Actually Objects don't have record type name as a field, They do have recordtypeid. So you have to query the recordtype object as shown below
id recordtypeid = [select id,name from RecordType where sobjecttype='Quote' and name='Budget Quote'].id;
And modify your query as
Integer bi = [select count() from Quote where opportunityid = :oid and RecordTypeId=:recordtypeid ];
Hope this helps
-VPrakash
All Answers
Actually Objects don't have record type name as a field, They do have recordtypeid. So you have to query the recordtype object as shown below
id recordtypeid = [select id,name from RecordType where sobjecttype='Quote' and name='Budget Quote'].id;
And modify your query as
Integer bi = [select count() from Quote where opportunityid = :oid and RecordTypeId=:recordtypeid ];
Hope this helps
-VPrakash
You can filter a query using a relationship and do this with a single query as you've written it, you're just missing the period- 'RecordType.Name' will work.
Just a note that there's also a DeveloperName field in RecordType which might be better to filter by. That way, if the name of the Record Type Name is ever updated, your code will still work. The DeveloperName field defaults to the Name with spaces replaced with underscores (Budget_Quote).
Thank you very much VPrakash. This does this solves my problem.