1

I am trying to fetch all the Opportunities associated with the User.Below is the Visualforce Email Template. I am stuck with the line of the code

received error: Error: Invalid field Opportunities__r for SObject User

<messaging:emailTemplate  recipientType="User" relatedToType="User" subject="Opportunity report for User: {!relatedTo.Name}"
   language="{!recipient.LanguageLocaleKey}">
<messaging:htmlEmailBody>
<html>
<body>
    <p> Dear {!recipient.Name},</p>
    <p>Below is the list of opportunities . </p>
    <p>table border = "0" </p>

    <p> Close Date</p> <p>Opportunity Name</p>
    <th>Amount</th> <th>Stage</th>
    </tr>
   <apex:repeat var="Opp" value="{!relatedTo.Opportunities__r}"> 
    <apex:OutputPanel rendered = "{!Opp.MightyHR__Closein7days__c = 1}" >  
    <tr>
    <td><a  href =" https://gopagoni-dev-ed.my.salesforce.com/{!Opp.Id}">{!Opp.CloseDate}</a></td>
    <td>{!Opp.Name}</td>
    <td> {!Opp.Amount}</td>
    <td>{!Opp.Stage}</td>
    </tr>
    </apex:OutputPanel>

     </apex:repeat>


    </table>
    <p/>
    <center>
    <apex:outputLink value="http://www.salesforce.com">
     For more detailed information login to Salesforce.com
                </apex:outputLink>

     </center>

    </body>

</html>

</messaging:htmlEmailBody>
</messaging:emailTemplate>
  • 1
    you can't access relatedTo.Opportunities__r related records. you may require controller help here. Try like this.. infallibletechie.com/2013/05/… – Ratan Paul Jan 25 '16 at 7:34
  • Thanks for the link. If we observe the Schema from User to Opportunity there is reference but when comes to the visual email template it doesn't work.Any clue y this happens @Ratan – user7447 Jan 25 '16 at 11:43
  • 1
    In case of VF email template reference field won't work like trigger context.. We can say it is a salesforce limitations.. Yeah there is a very good reason for this limitation. I think because of performance issue or something I am not sure.. Hope someone will give you a correct Ans to question.. Thanks – Ratan Paul Jan 25 '16 at 11:50
0

Here is the process flow how i achieved this. Refer to the http://www.infallibletechie.com/2013/05/visualforce-email-template-with-custom.html .

The above links helps to write the code.

1.Created an Apex class 2.Visualforce controller 3.Visualforce email template. In the Template we pass the User id.this will be passed to the controller and then to the apex class.The apex class fetches the records and displays to the user

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.