Skip to main content
1 of 2
David Reed
  • 93.7k
  • 14
  • 90
  • 166

The solution turns out to be rather simple, if non-obvious: change cs.Case__c to cs.Case__r.

When you're dealing with relationship fields in Apex, the __c version of the lookup field is typed as an Id value. The __r variant of a lookup field to Some_Object__c is typed as a Some_Object__c, and can be assigned (or extracted as) an sObject class instance in Apex. The __r name of a child relationship is typed as a List<Child_Object__c> and can be interacted with as you'd expect.

These latter two are actually parallel to how standard fields work. Look at the difference in type between Contact.Account and Contact.AccountId, for example, and the type of Account.Contacts. It's just that the syntax doesn't make this distinction quite as clear when dealing with custom fields.

David Reed
  • 93.7k
  • 14
  • 90
  • 166