I have been progressing along my journey trying to pass sub-Opportunity data into an Opportunity record's alert.

Thanks to your help, I was able to successfully compile and trigger a VisualForce email, however, the sub Opportunity values did not pass into the HTML table I built.

Thanks to Lance Shi I know that I need to create a custom controller, which leads me to my next question tree:

  1. Is the only way to create a custom Controller in the Sandbox mode?

This Salesforce Developer tutorial indicates that it is possible just within standard Admin, but navigating to the Apex Classes in admin does not yield a 'New' button.

  1. I have created a basic controller in my Sandbox instance, how do I push this controller to my Production instance even with 0% coverage (I'm not referencing any Apex triggers obviously)

For context, I am aware of requirements for testing Apex Triggers/test class code in normal circumstances.

Here is the controller I have created with the help of this Tutorial:

public class GetOpps {
    private final List<Opportunity> mediaOpps;

    public GetOpps() {
        mediaOpps = [SELECT Name,(SELECT CreatedBy.Name FROM Notes) FROM Opportunity];

    public List<Opportunity> getMediaOpps() {

       Return mediaOpps;

Where mediaOpps represent child Opportunity objects of the main Opportunity. How would I go about testing this so I could reference this code with a VisualForce Component?

2 Answers 2


1.Yes you cannot create an apex class directly in Production .you should create in sandbox and after rigorous testing you move that to PROD via changesets ,IDE or ANT deployment.

2.you cannot skip test code .Its not best practice and your apex should have at least 1% covered to move to PROD assuming your overall coverage is 75% atleast. I would recommend to write test code for your apex and assert all business requirements .

  • I understand why in normal circumstances any code testing makes sense. However, I don't even KNOW how to test an Apex Controller for a VisualForce page in this case. The Salesforce Dev page I linked makes zero mention of logging in to a Sandbox.
    – GPP
    Jan 24, 2016 at 3:50
  • 1
    Unfortunately even though you don't know how to test the controller, that doesn't change the circumstance that testing is required! You're going to need to write a test method that creates some Opportunities, runs your GetOpps.getMediaOpps() method, and verifies an expected route. Check out the trailhead modules on Apex Testing to learn the basics. You're doing great work, you just gotta write some tests and be deployed! Jan 24, 2016 at 4:21
  • 1
    Knockout some Trailhead badges as you learn..you are gone love it once you understand how these test classes are written Jan 24, 2016 at 4:49

Apex code can only be written in sandboxes and Developer Edition orgs. You can't deploy it to a production until you've written tests to cover 75% of your code.

This is partly to ensure that you're being a good tenant in your multi-tenant environment, and partly to ensure that you don't do anything to jeopardize your production data.

  • thanks for the response. In this context of writing a controller for a VisualForce Email Template, do you have a suggestion for how I would be able to test the Controller in question?
    – GPP
    Jan 24, 2016 at 3:52
  • 1
    Christian's comment in another answer is a good start: write a test method that creates the opportunities and child opportunities; verify that getMediaOpps returns the expected data, etc. Check out developer.salesforce.com/page/… and also this might help: developer.salesforce.com/forums/?id=906F000000093OUIAY Jan 24, 2016 at 18:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .