这种方式经常被用来,在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.");
}

066_VFPage中Js Button与controller交互方式(一)的更多相关文章

  1. html中的 button,input-button, image, input-image的区别

    hmtl中 为了验证 form的 action提交属性, 是指 表单提交到的 页面, 可以是任意 性质的页面, 如:html页面, php页面, asp页面等都可以, 实际在测试的时候, 可以就写 提 ...

  2. unity中js脚本与c#脚本互相调用

    unity中js脚本与c#脚本互相调用   test1.js function OnGUI() { if(GUI.Button(Rect(25,25,100,30),"JS Call CS& ...

  3. PhoneGap或者Cordova框架下实现Html5中JS调用Android原生代码

    PhoneGap或者Cordova框架下实现Html5中JS调用Android原生代码 看看新闻网>看引擎>开源产品 0人收藏此文章, 发表于8小时前(2013-09-06 00:39) ...

  4. 控制器controller与指令中的link、controller中变量作用域的关系

    angjualrjs中的作用域与原生js中的函数嵌套原理一致,都是存在作用域的继承.若在子控制器(同样包括在指令中的link或是controllerding中定义变量,此时指令中必须未使用scope独 ...

  5. JSON(二)——JavaScript中js对象与JSON格式字符串的相互转换

    首先我们来看一下js中JSON格式的字符串 var JSONStr1 = "{\"name\" : \"张三\"}"; 注意以下的写法不是j ...

  6. WebView中JS调用Android Method 遇到的坑整理

    WebView是android中常用的一个组件,其作用是展示网页,并让网页和android app进行一些业务逻辑上的交互. 其坑无数,相信用过的都知道,一个一个来解决吧. 1.怎么互调: <! ...

  7. BootStrap中的button使用

    原文地址:http://www.phloxblog.in/bootstrap-buttons/#.U5xYso2fclm 站点中事件的触发往往依赖于button或者超链接.因此,button能够觉得是 ...

  8. C# winForm webBrowser页面中js调用winForm类方法(转)

      有时我们在winform项目中嵌入了网页,想通过html页面调用后台方法,如何实现呢?其实很简单,主要有三部:   1.在被调用方法类上加上[ComVisible(true)]标签,意思就是当前类 ...

  9. 如何在MFC界面开发中响应Button按钮的Down和Up事件

    通过尝试有两种方案可以解决这个问题,第一种方案是通过PreTranslateMessage函数在调度消息之前对消息类型进行筛选,第二种方案是重载CButton类,在重载后的类CForTestButto ...

  10. [原创]在Framelayout中放置button控件出现的覆盖问题

    android Framelayout(帧布局)是很常用的布局,主要用来处理需要多个view叠加显示的情况. 然而在使用中,我发现Framelayout中的Button控件,会挡住所有其他控件,而不论 ...

随机推荐

  1. flutter2.x报错解决type (RouteSettings) => Route<dynamic> is not a subtype of type (RouteSettings) => Route<dynemic> of function result

    flutter2.x报错解决type (RouteSettings) => Route <dynamic>? is not a subtype of type (RouteSetti ...

  2. Linux环境下:程序的链接, 装载和库[ELF文件详解]

    编译过程拆解 预处理处理生成.i文件, .i文件还是源码文件 将所有的宏定义#define展开. 处理#if, #else, #endif等条件编译指令 处理#include, 原地插入文件 cpp ...

  3. 电商网站Web自动化测试实战( 编写京东搜索脚本python+selenium框架)

    电商网站Web自动化测试实战( 编写京东搜索脚本) 1,打开京东页 京东首页地址:https://www.jd.com/,故进入京东首页如下: 2,打开浏览器开发者模式 定位元素前需先打开浏览器开发者 ...

  4. vue-cli环境搭建 (超详细保姆级教程)

    一.使用之前,我们先来掌握3个东西是用来干什么的. npm: Nodejs下的包管理器. webpack: 它主要的用途是通过CommonJS的语法把所有浏览器端需要发布的静态资源做相应的准备,比如资 ...

  5. Osx10.14升级watchman踩坑记

    背景 使用 watchman 检测文件变化通知非常的好用, 但有些时候会出现 watchman 占用内存和 CPU 特别疯狂, 通过 watch-del 也无济与事, 由于 watchman 的版本 ...

  6. grequest案例对比requests案例

    grequets和requests案例各一个,使用上对比: import grequests import requests headers = { "content-type": ...

  7. JZOJ 5346. 【NOIP2017提高A组模拟9.5】NYG的背包

    题目 分析 很神奇的贪心 \(Code\) #include<cstdio> #include<algorithm> using namespace std; typedef ...

  8. JZOJ 5351. 【NOIP2017提高A组模拟9.7】简单无向图

    题目大意 给定 \(n\) 个度数为 \(\in [1,2]\) 之间的点,求能组成多少种简单无向图(可不连通,点与点之间有别) 分析 显然答案只与 \(n1,n2\) 有关 那么 \(dp\)?(我 ...

  9. [SWPUCTF 2021 新生赛]jicao

    CTF web安全 阅读代码可知当传入一个post型的参数id与wllmNB相等并且传入一个get型的参数json: 但是这里有一个函数json_decode,上网搜索可知json_decode这个函 ...

  10. Shell命令-基础

    Shell命令 1 变量 定义变量时,变量名不加美元符号$,注意,变量名和等号之间不能有空格 a="myname" 用语句给变量赋值时, for file in `ls /etc` ...