1

I have few different record-types in my object and I like to know either by Id/Name what record-type the user have selected and based on that record type selection I have to perform some logic behind that.

I have before insert, before update trigger on trigger.New

Map<ID,RecordType> rt_Map = New Map<ID,RecordType>([Select ID, Name From RecordType Where sObjectType = 'mycustom_object__C']);

if(rt_map.get(opp.recordTypeID).name.containsIgnoreCase('YOUR VALUE')) //<<<ERROR
{
        //Do your stuff
}

error:

Initial term of field expression must be a concrete SObject: Map

1 Answer 1

1

Please see the example below
Map rt_Map = New Map([Select ID, Name From RecordType Where sObjectType = 'Project__c']);

system.debug((rt_map.get('012g000000051uFAAQ')).name);


I am able to get the name of recordtype. In your case what is opp ? That object does not seem to be defined in your code snippet.
Since this rt_Map is holding values for Id as Key, you must only give Id(String) to fetch values.


you can share your complete code in case it does not work.

Rgds

8
  • Is there a way to find out what record type user have selected to create a record? and I see that you are hard-coding the id to get the name but I was looking a way to get either its id or name based on the user selection. is that possible in apex? - the opp is a opportunity i was trying to play around ... thats psudo code
    – Nick
    May 27, 2015 at 17:03
  • i have tried your code getting this error unexpected token: 'Map'
    – Nick
    May 27, 2015 at 17:07
  • Map<ID,RecordType> rt_Map = New Map<ID,RecordType>([Select ID, Name From RecordType Where sObjectType = 'Project__c']); system.debug((rt_map.get('012g000000051uFAAQ')).name);
    – Dave
    May 27, 2015 at 17:13
  • Somehow the above answer did not show the map variable correctly, use as mentioned in my above comment. It is same map as you used.
    – Dave
    May 27, 2015 at 17:13
  • I'm curious to know the question I have asked and I will repeat here again Is there a way to find out what record type user have selected to create a record? and I see that you are hard-coding the id to get the name but I was looking a way to get either its id or name based on the user selection. is that possible in apex
    – Nick
    May 27, 2015 at 17:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .