2

I am trying to get recordType Id's without using a SOQL query (source codespokes.com: how-to-get-record-type-id-without-soql):

// User need to pass two parameters SObject Type & 
// RecordType Label ( not Record Type Developer Name)
public static Id getRecordTypeId(String ObjectType, String RecordTypeLabel)
{ 
  SObject OBJ;
  // Describing Schema
  Schema.SObjectType Res = Schema.getGlobalDescribe().get(ObjectType);
  if (Res != null)
  {

      OBJ = Res.newSObject();
      // Describing Object 
      Schema.DescribeSObjectResult DesRes = OBJ.getSObjectType().getDescribe(); 

      if(DesRes != null){
        // Get a map of fields for the SObject Save error: unexpected token: 'map'
        map <string schema.recordtypeinfo="schema.recordtypeinfo"> RecordTypeMap = DesRes.getRecordTypeInfosByName();
        if (RecordTypeMap != null) 
            {
            Schema.RecordTypeInfo RecordTypeRes = RecordTypeMap.get(RecordTypeLabel);
            if (RecordTypeRes != null) {
                return RecordTypeRes.getRecordTypeId();
                }
              }
           }
        }
     return null;
    }

But on the line map <string schema.recordtypeinfo="schema.recordtypeinfo"> RecordTypeMap = DesRes.getRecordTypeInfosByName(); I am getting an error Unexpected token: 'map'

What have I done wrong, I've tried re-writing it

5

Try to change that to this:

Map<String, Schema.RecordTypeInfo> RecordTypeMap = DesRes.getRecordTypeInfosByName();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.