3

When i have quering:

Select id,recortype.name from plan__c...

Its fetching record type id not name.

I am working on trigger where i need to update some values on the basis of record type name.

Thanks

  • how are you accessing the field after the query? Can you show the debug statement or a variable assignment where you're seeing the wrong value? It needs to be like: Plan__c p = [Select id,recortype.name from plan__c limit 1]; system.debug(p.recordtype.name); – Jason Benkert Apr 9 '16 at 1:31
  • @jason Thanks for quick reply.Yes i am using the same way.This is strange behaviour in salesforce if you query in query editor it will give name.But when you use in apex or through developer console it will return id.You may please check even with standard object.There is same behaviour. – David Mycka Apr 9 '16 at 1:38
  • Nope, you definitely can see the name. Does your profile have access to the record type by chance? I just did the same in query editor and I see the name in the query result. I'll post the image in the answers section. – Jason Benkert Apr 9 '16 at 1:43
  • Thanks Jason and Jenny,Thanks to both of you for quick help..As Jenny said it is showing id while doing debug.Thanks – David Mycka Apr 9 '16 at 3:33
3

If you debug plan__c.RecordType.Name this will be the string value, if you debug plan__c you will see the id. Example from running the following code in the execute anonymous using the account object:

Account acct = [SELECT Id, RecordType.Name FROM Account WHERE RecordTypeId != null LIMIT 1];
Boolean bool = acct.RecordType.Name == 'Organization';
System.debug(acct);
System.debug('RecordTypeName ' + acct.RecordType.Name + ' equals Organization! Result: ' + bool);  

Results: debug log

1

enter image description here

This works for me, sounds like this is some kind of permission issue perhaps?

  • This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. - From Review – Sergej Utko Apr 9 '16 at 18:00
  • the purpose of posting in this way was to show the image. I can't post an image on a comment on a post. – Jason Benkert Apr 10 '16 at 2:30

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.