function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Medhanie HabteMedhanie Habte 

Too Many SoQL queries 101

Greetings all, I am running into the Too Many SOQL queries issue when running a test for this apex class. The testregistrations component passes but the mypage_test fails.

Any thing, I may need to adjust here.
public class eventsControllerTests {

static testMethod void myPage_Test()
  //Test converage for the myPage visualforce page
  PageReference pageRef = Page.Events_Home;
  // create an instance of the controller
  eventsController myPageCon = new eventsController();
  //try calling methods/properties of the controller in all possible scenarios to get the best coverage.

  String efSetupPage = myPageCon.Setup().getUrl();


    static testMethod void testRegistrationsTrigger(){
        //First, prepare 200 contacts for the test data
        String contactLastName = 'Apex';
        String contactFirstName = 'Joe';
        String contactTitle = 'Manager';
        Contact ct = new Contact(lastname=contactLastName, firstname=contactFirstName, title=contactTitle);
        insert ct;
        ct = [SELECT Name, Title from Contact WHERE Id = :ct.Id];
        Event__c ev = new Event__c(name = 'My Event');
        insert ev;

        Event_Registration__c reg = new Event_Registration__c(Contact__c=ct.Id,Event__c=ev.Id);
        insert reg;

        reg = [SELECT Name_on_Badge__c, Title_On_Badge__c from Event_Registration__c WHERE Id = :reg.Id];
        System.assertEquals(ct.Name, reg.Name_on_Badge__c);
        System.assertEquals(ct.Title, reg.Title_on_Badge__c);


Best Answer chosen by Medhanie Habte
Medhanie HabteMedhanie Habte
Resolved. I don't use the app so I uninstalled it.

All Answers

I dont see any issues with this code. It could be because of the triggers that are being fired when you insert contact or event or Registration.

Shrikant BagalShrikant Bagal
Please post your VF code?
Shrikant BagalShrikant Bagal
"Events_Home" Page
Medhanie HabteMedhanie Habte
Here's the Events_Home Page
<apex:page showHeader="true" standardStylesheets="true" sidebar="true" controller="eventsController">

    <table border="0" width="600">
           <td> <h1 style="font-family:Georgia;font-size:200%">Events</h1></td>
           <td align="left">        
                <apex:form >
                    <apex:commandButton action="{!Setup}" value="Initialize Sample Data"/>
                    <apex:commandButton action="{!showPopup}" value="Remove Sample Data" rerender="popup"/>
                      <apex:outputPanel id="popup">
                        <apex:outputPanel styleClass="popupBackground" layout="block" rendered="{!displayPopUp}"/>
                        <apex:outputPanel styleClass="customPopup" layout="block" rendered="{!displayPopUp}">
                          <b>WARNING:</b> The following records will be deleted: accounts named <b>Test-Customer</b> and 
                          <b>Test-Vendor</b>, and associated contacts, eventd named <b>Test Event</b>, and associated tracks, 
                          sessions and speakers, and venues named <b>Test Convention Center</b>.<br/><br/> 
                          Click OK to continue or Cancel to abort.<br/><br/>
                          <apex:commandButton value="OK" action="{!closePopupOK}" rerender="popup"/>
                          <apex:commandButton value="Cancel" action="{!closePopupCancel}" rerender="popup"/>
    <table border="0" width="600">

                <p>Events for Salesforce helps you manage customer conferences, partner meetings or any other type of multi-session event. Events can be as simple as a web presentation, or as complex as a multi-day conference with multiple speakers and break outs.</p>
                <p>Using Events for Salesforce is simple, Create your Event, add one or more Tracks, then add one or more Sessions to each Track. You can also track event venus, such as a hotel or confernece center, and assign individual Speakers to each Session.</p>
                <p>To help you get started, included is an automated "initialize" process, which creates a sample event in your system.</p>

                <a href="" class="twitter-follow-button" data-show-count="false" data-size="large">Follow @texasrob</a>
                <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);;js.src="//";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
                <p>Follow me on Twitter to send question or comments, as well as enhancement requests. I will implement your ideas as time allows.</p>
                <p>Please take the time to rate this app on the AppExchange for the benefit of the community. <a href="">Rate Events on the AppExchange</a></p>

    <style type="text/css">
            background-color: white;
            border-style: solid;
            border-width: 2px;
            left: 50%;
            position: absolute;
            z-index: 9999;
            /* These are the 3 css properties you will need to tweak so the pop 
            up displays in the center of the screen. First set the width. Then set 
            margin-left to negative half of what the width is. You can also add 
            the height property for a fixed size pop up.*/
            width: 500px;
            margin-left: -250px;
            opacity: 0.20;
            filter: alpha(opacity = 20);
            position: absolute;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            z-index: 9998;

Medhanie HabteMedhanie Habte
Resolved. I don't use the app so I uninstalled it.
This was selected as the best answer