You need to sign in to do that
Don't have an account?
Dippan Patel
Get RecordtypeId if RecordType Exists in SObject
Hi,
I want to get recordtypeId and recordtypeName in Sobject if that exists.. For example,
The above code gives compilation error,
Line: 7, Column: 32
select Id,RecordTypeId,RecordType.Name from ^ ERROR at Row:1:Column:11 No such column 'RecordTypeId' on entity 'Account'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
What should be the right approach for the above scenario?
Thank you!
I want to get recordtypeId and recordtypeName in Sobject if that exists.. For example,
List<RecordType> recordTypeList; try{ recordTypeList = [select Id,Name from RecordType where sObjectType = 'Account']; System.debug('recordTypeList' + recordTypeList); if(!recordTypeList.isEmpty()){ System.debug('inside if recordTypeList'); Account existingAccount = [select Id,RecordTypeId,RecordType.Name from Account where Id = '0010r00000xxxx']; System.debug('existingAccount' ); } } catch(Exception e){ System.debug(LoggingLevel.ERROR, 'Exception: ' + e.getMessage()); }
The above code gives compilation error,
Line: 7, Column: 32
select Id,RecordTypeId,RecordType.Name from ^ ERROR at Row:1:Column:11 No such column 'RecordTypeId' on entity 'Account'. If you are attempting to use a custom field, be sure to append the '__c' after the custom field name. Please reference your WSDL or the describe call for the appropriate names.
What should be the right approach for the above scenario?
Thank you!
Greetings!
You can use:
Id devRecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Development').getRecordTypeId();
Here, 'Development' is the record type's name. You shuld use 'someone'. Also, you will have to specify your SObject type, here I have mentioned Account.
Kindly let me know if it helps you and close your query by marking it as best answer so that it can help others in the future.
Warm Regards,
Shirisha Pathuri
You can try this in query editor, it must return 0.
select Id,Name from RecordType where sObjectType = 'Account'