3

I have written the following code in salesforce

<apex:page Controller="Publication_Tab_Controller" showHeader="true" tabStyle="Publication__c">
<head>

<!-- Include meta tag to ensure proper rendering and touch zooming -->
<meta name="viewport" content="width=device-width, initial-scale=1"></meta>

<!-- Include jQuery Mobile stylesheets -->
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"></link>

<!-- Include the jQuery library -->
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>

<!-- Include the jQuery Mobile library -->
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>

<apex:form >
<apex:tabPanel switchType="client" id="AccountTabPanel" value="{!tabOpt}">
<apex:tab label="Invitation" name="Invitation" id="tabInvitation">
<apex:pageBlock title="Publication">  
    <apex:pageblockTable value="{!pub}" var="a">  
     <apex:column headerValue="Pub-ID">  
      <apex:outputlink value="/{!a.id}">{!a.Name}</apex:outputlink>  
     </apex:column>  
     <apex:column value="{!a.id}" headerValue="Publication SFDC Id"/> 
     <apex:column >

         <a href="#myPopup" data-rel="popup" class="ui-btn ui-btn-inline ui-corner-all">Accept invitation</a>

            <div data-role="popup" id="myPopup">
                  <p>These are the terms and conditions of viewing the publication.
                  </p>
                  <form>
                      <label><input type="checkbox" name="checkbox"> I agree</input></label>


                        <input type="button" id="Submit" value="Submit"></input>


                        <input type="reset" value="Cancel"></input>
                  </form>
            </div>
         <!--apex:commandButton value="Accpet Invitaion" action="{!switch}" reRender="AccountTabPanel"/-->


     </apex:column> 
    </apex:pageBlockTable>     
   </apex:pageBlock>

</apex:tab>
<apex:tab label="View Publication" name="ViewPublication" id="tabViewPublication">
</apex:tab>
<apex:tab label="Approve" name="Approve" id="tabApprove">
</apex:tab>
</apex:tabPanel>
                      <script name='Name'>
                             var j$ = jQuery.noConflict();

                            j$(document).ready(function(){
                                j$("#Submit").click(function() 
                                    {

                                     Publication_Tab_Controller.update_publication(a);
                                    });

                              });
                          </script>                      
</apex:form>  
</apex:page>

Along with the controller

public class Publication_Tab_Controller{
    public list <publication__c> pub {get;set;}
    public Publication_Tab_Controller() {

    String searchquery='select name,id from publication__c';  
    pub= Database.query(searchquery); 
    }
    public Publication_Tab_Controller(ApexPages.StandardController controller) {
    }
    public String tabOpt {get;set;}

    public void switch()
    {
        tabOpt='Review';
    } 
    @RemoteAction
    public static void update_publication(publication__c publication)
    {
        publication.AcceptInvitation__c='Accepted';
        update publication;
    }

 }

But I am not being able to access the update_publication(publication__c publication) from the script. I just started learning salesforce and any help would be really appreciated. Thanks in advance

1

According to the documentation https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_js_remoting_configuring_request.htm the correct JavaScript syntax for calling your Remote Action is:

Visualforce.remoting.Manager.invokeAction(
  '{!$RemoteAction.Publication_Tab_Controller.update_publication}',
  a,
  handleResult
);

Where a is your Account object and handleResult is the name of a JavaScript callback function that will run when the RemoteAction has completed, like this:

function handleResult(result, event) { ... }
3
  • I have a question regarding this . Here the 'a' was actually for <apex:pageblockTable value="{!pub}" var="a"> where pub is of type publication and is being accessed from the controller. Can I directly pass it to the Controller method update_publication? @dominic
    – Aditi
    Jul 26 '15 at 14:03
  • No, the a is a visualforce variable tgat doesn't exist in the rendered html page. You will need to use a javascript variable that references the value.
    – Dominic
    Jul 26 '15 at 14:31
  • Hi @dominic I am still having problems with passing the value of the 'a' variable back to the update_publication method. I would be really grateful if you show me a syntax for that. The variable 'a' is actually supposed to contain the value of the publication, the corresponding button of which is being clicked and the popup is being showed
    – Aditi
    Jul 26 '15 at 15:57

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.