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.

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
        }   
    }
| improve this answer | |

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.