function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ckellieckellie 

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

Best Answer chosen by Admin (Salesforce Developers) 
VPrakashVPrakash

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

VPrakashVPrakash

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 

This was selected as the best answer
Platy ITPlaty IT

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).

ckellieckellie

Thank you very much VPrakash. This does this solves my problem.