0

I have those two methods inside my RSVP class :

 public LIST<News__c> getExcerpts() {
        String paramId = Apexpages.currentPage().getParameters().get('eventid');
        return [SELECT Title__C, Excerpt__c FROM News__c WHERE id = :paramId LIMIT 1];  
    }
    public PageReference rsvpMe() {
        // QUERY EVENT
        try {
            List<News__c> eventList = [
                select Name,
                    Title__c,
                    Id
                from News__c
                where Id = :paramId
            ];


            // EVENT NOT FOUND
            if (eventList.isEmpty()) {
                ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.Warning, 'The event was not found.'));
                return null;
            }

When I use the command button on my page the following error gets displayed "The event was not found") I cannot find anything wrong with this piece of code and cannot find an error in the methods. Anyone know how to make it work ?

here are the visualforce page code for the form that activates this method:

        <form role="form">
            <fieldset>
                <div class="form-group">
                    <label for="email">Confirm Email Address</label>
                    <apex:inputText styleClass="form-control" id="email" required="true" value="{!email}" />
                </div>
                <apex:inputHidden id="eventid" value="{!eventid}" />
                <script>
                    var jsEmail = "{!$Component.email}";
                    var jsEvent = "{!$Component.eventid}";
                </script>
                <script>
                window.onload=function()
                   {
                document.getElementById(jsEmail).value = "{!$CurrentPage.parameters.email}";
                   };
      </script>

  <apex:commandButton action="{!rsvpMe}" value="RSVP" id="rsvpButton" styleClass="btn btn-primary btn-lg btn-block" />

And here is the output that redirects them to the form page page:

 <apex:outputLink styleclass="btn btn-sm btn-default" onclick="ga('send', 'event', 'News_ReadMoreLatestNews', 'click', 'Read more news');" value="{!$Page.calypso_news}?id={!article.id}">Read More</apex:outputLink>
  • Your eventList array is empty. Maybe the paramId variable is null. Check out its content with System.debug(). Also, verify whether your current page contains a parameter named eventid and whether it's valid. – Riadh Mankai Feb 1 '16 at 13:45
  • The current page url is this: calypso_news?id=a0p7E0000005UPhQAM it doesnt let me get the debug for param id but the SOQL query seems fine to me. Can you see any errors ? – Greg Feb 1 '16 at 13:56
  • The SOQL query is fine. It is just return nothing. Your returned list is empty. I see the param name is id and not eventid, so try this: Apexpages.currentPage().getParameters().get('id'); – Riadh Mankai Feb 1 '16 at 14:14
  • <apex:outputLink value="/calypso_RSVP?eventid={!article.id}" styleClass="btn btn-primary btn-sm btn-xs-block" id="register" rendered="{!IF(AND(article.Category__c == 'Events', ISBLANK(article.Custom_Registration_URL__c), article.Event_Date_End__c > NOW()), TRUE, FALSE)}">Register <i class="fa fa-arrow-circle-o-right"></i></apex:outputLink> – Greg Feb 1 '16 at 14:24
  • thats the button for the redirect – Greg Feb 1 '16 at 14:24
1

It looks like you're defining paramid only in the context of the getExcerpts method, in which case it's value won't be accessible to other methods.

You should define it as a public variable outside the method to allow it to be accessed from other methods.

Eg.

Public string paramid { get; set; }

Then set its value in the getExcerpts method as you are already trying to but without "string" at the start.

Ie.

paramid = ApexPages.CurrentPage() etc...

Also, how are you calling the getExcerpts method - as an Action on the page? Or from a constructor method? The paramid variable won't be populated until The getExcerpts method has been run...

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