zoukankan      html  css  js  c++  java
  • 066_VFPage中Js Button与controller交互方式(一)

    这种方式经常被用来,在button中处理一些逻辑,做法是在detail 页面中加一个button,对应是jS执行调用invoke controller

    Define a webService method in Apex and then call it using the AJAX Toolkit in a button.

    For example, suppose you want to create a Mass Add Notes button on accounts:
    1. Define the Web service method in Apex by clicking Setup | Develop | Apex Classes, clicking New, and adding the following code into the body of your new class:
    sforce.apex.execute(类,方法名,参数);
    global class MassNoteInsert{
    
      WebService static Integer insertNotes(String iTitle,
                                           String iBody,
                                           Id[] iParentIds) {
        Note[] notes = new Note[0];
        iBody = String.escapeSingleQuotes(iBody);
        for (Id iParentId : iParentIds) {
            notes.add(new Note(parentId = iParentId,
                               title = iTitle, body = iBody));
        }
        insert notes; //Bulk Insert  
        
        return notes.size();
      }
    
    }
    

      

    2.Then, click Setup | Customize | Accounts | Buttons and Links, and click New in the Custom Buttons and Links related list.

    3.Name the button and assign it the following attributes:

    1. Display Type: Detail Page Button
    2. Behavior: Execute JavaScript
    3. Content Source: OnClick JavaScript
    {!REQUIRESCRIPT("/soap/ajax/42.0/connection.js")}
    {!REQUIRESCRIPT("/soap/ajax/42.0/apex.js")}
    
    
    var idsToInsert= {!GETRECORDIDS( $ObjectType.Account )};
    var noteTitle = prompt("Please enter the title of the note");
    var noteBody = prompt("Please enter the body of the note");
    
    if (idsToInsert.length) {
    
       // Now make a synchronous call to the Apex Web service
       // method
       var result = sforce.apex.execute(
        "MassNoteInsert",       // class
        "insertNotes",          // method
        {iTitle : noteTitle,    // method arguments
         iBody: noteBody,
         iParentIds: idsToInsert });
    
       alert(result[0] + " notes inserted!"); //response
    } else if (idsToInsert.length == 0) {
       alert("Please select the accounts to which" +
             " you would like to add notes.");
    }

    此刻,静下心来学习
  • 相关阅读:
    SpringBoot2.x前后端分离跨域问题及Swagger不能访问
    SpirngBoot2.x整合Swagger2接口文档
    SpringBoot2.x整合Druid数据源
    SpringBoot2.x整合logback 实现自动打印日志
    docker 进入 mysql中的操作
    Intellij Springboot (子模块)访问jsp页面404
    运行rabbitmq 的docker
    mybatis拦截器修改sql重新set后不生效?
    oracle+mybatis如何在新增时返回主键(自增序列)的值?
    oracle+mybatis报“未找到要求的from关键字”错误?
  • 原文地址:https://www.cnblogs.com/bandariFang/p/9682149.html
Copyright © 2011-2022 走看看