0

I am trying to use a switch statement with the getsobjecttype() function but keep getting getting errors like:

Method does not exist or incorrect signature: void getsobjecttype() from the type String

Here is the code I am using

String recordId = '00561000000Mjya';
switch on String.valueOf(recordId.getsobjecttype()) {
    when 'Order__c' {
        // do something here
    }   
}

I've tried without casting as a String as well but this didn't work.

1 Answer 1

3

Problem is with "String recordId = '00561000000Mjya';" because you are casting as string and string does not have getsobjecttype().

Try this one:

Id recordId = '00561000000Mjya';
    switch on String.valueOf(recordId.getsobjecttype()) {
        when 'Order__c' {
            // do something here
        }   
    }

You must log in to answer this question.

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