这种方式经常被用来,在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. Ant Design Table 如何动态自定义?Ant Popover 遮挡?

    项目场景: 基于electron + Vue + node.js + express + mysql + evanpatchouli-mysql + Ant-Design-Vue,编写一款属于自己的轻 ...

  2. Sqoop导出ClickHouse数据到Hive

    背景 公司采购了外部服务,其存储为ClickHouse,按照公司要求需要将其数据采集到Hive. 验证环境 CDH: 6.3.2 ClickHouse: 19.15.4.10 Sqoop: 1.4.7 ...

  3. 使用Ajax跨域实现百度搜索功能

    上图 实现过程 1. 在百度上随便搜索一个内容 2. 在Network中找到一个地址右击 copy 然后 Copy link address 3. 将地址保存起来,取出中间有用的部分作为url属性的值 ...

  4. Grafana 系列文章(十二):如何使用Loki创建一个用于搜索日志的Grafana仪表板

    概述 创建一个简单的 Grafana 仪表板, 以实现对日志的快速搜索. 有经验的直接用 Grafana 的 Explore 功能就可以了. 但是对于没有经验的人, 他们如何能有一个已经预设了简单的标 ...

  5. Vue13 样式动态绑定

    1 class样式的动态绑定 1.1 说明 通过命令v-bind:class设置一个对象,动态切换class.可以简写为:class. class=""可以和:class=&quo ...

  6. LOJ 数列分块入门 6

    \(\text{Solution}\) 涉及到插入,分块需要动态维护块内的元素及相对位置 于是妙用 \(\text{vector}\) 学到了 \(insert\) 操作,在某个迭代器前插入元素 这样 ...

  7. 代码随想录算法训练营day12 | leetcode 239. 滑动窗口最大值 347.前 K 个高频元素

    基础知识 ArrayDeque deque = new ArrayDeque(); /* offerFirst(E e) 在数组前面添加元素,并返回是否添加成功 offerLast(E e) 在数组后 ...

  8. 代码随想录算法训练营day07 | leetcode 454.四数相加II 383. 赎金信 15. 三数之和 18. 四数之和

    LeetCode 454.四数相加II 分析1.0 这个最直接暴力法,不过过于暴力了,害怕.jpg 失误 读题理解失误:题目要求的是四元组的个数,读完题到我这里成了输出四元组,悲哉 分析2.0 记录有 ...

  9. 03#Web 实战:实现下拉菜单

    实现过程 实现一个简易的鼠标悬停菜单项显示其子项的下拉框控件.将用到 CSS 绝对定位.流式布局.动画等:JQuery 鼠标移入和移出事件.DOM 查找.效果图如下: HTML 结构: <div ...

  10. spring boot 3.x 配置spring security

    参考文章:https://spring.io/guides/gs/securing-web/ 导入maven <dependency> <groupId>org.springf ...