2

I am following this SF VF email example.

They have the relatedToType="Account" and their <apex:repeat var="cx" value="{!relatedTo.Cases}"> references Cases which should loop through the Cases related to Account - Being a one to many relationship. I can make this work fine.

When I change the relatedToType="Contact" and my <apex:repeat var="cx" value="{!relatedTo.MyCustomObject__r}"> which is also a one to many relationship I get the following error on trying to save the template:

Error: Invalid field MyCustomObject__r for SObject Contact

I have also tried __c but with the same error.

Any ideas?

UPDATE:

The accepted answer below (and comments) worked for me. I was focusing on the related 'object' not the 'field' that actually related them both together.

  • 1
    Get the child relationship name and append __r there . – Mohith Shrivastava Jan 8 '16 at 12:39
  • 2
    The child relationship name is usually plural (unless you've manually changed it), and you have to use __r. So use {!relatedTo.MyCustomObjects__r}. You can see the child relationship name, by going to the lookup field, it's at the bottom left. – rael_kid Jan 8 '16 at 12:42
4

The child relationship name has to be observed and __r needs to be appended .

enter image description here

In your set up menu navigate to Object > field > and observe child relationship name

| 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.