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
Shree KShree K 

How to use Opportunity record type name/Developer Name in conditions in an efficient way

Hi Everyone,
I need to use a condition , when ever  an Opportunity is created with its stage as 'Won' and recordtype name as 'Global' a record in custom Object has to be created ,i am good till here , what I wonder is , Is there any way that i can use Opportunity Object's record type name without querying RecordType Object, all i am looking for is a condition like below to be built without querying another Object coz i already have a list Opp,

If (Opp.StageName='Confirmed' && RecordTypeName(would like to use this as a string )= 'Global') 

Thanks
Ck


 
Best Answer chosen by Shree K
Anupama SamantroyAnupama Samantroy
Hello,

You can create a map to store the RecordType id vs the RecordTypeInfo. 
Map<ID,Schema.RecordTypeInfo> rt_Map = Opportunity.sObjectType.getDescribe().getRecordTypeInfosById();

Then in the trigger use like below.
if(Opp.StageName='Confirmed'  && rt_map.get(opp.recordTypeID).getName().containsIgnoreCase('Global')){
               //Do your stuff
          }

There is no SOQL used.

Thanks
Anupama

All Answers

GulshanRajGulshanRaj
Hi,

You can use recordType.Name inside you same SOQL query like this:
select id, name, stageName, RecordType.Name from opportunity
And you can use it inside you if condition with Opp.RecordType.Name=='Global'


Regards
Gulshan Raj
Anupama SamantroyAnupama Samantroy
Hello,

You can create a map to store the RecordType id vs the RecordTypeInfo. 
Map<ID,Schema.RecordTypeInfo> rt_Map = Opportunity.sObjectType.getDescribe().getRecordTypeInfosById();

Then in the trigger use like below.
if(Opp.StageName='Confirmed'  && rt_map.get(opp.recordTypeID).getName().containsIgnoreCase('Global')){
               //Do your stuff
          }

There is no SOQL used.

Thanks
Anupama
This was selected as the best answer