• 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.");
    }

    此刻,静下心来学习
  • 相关阅读:
    《“十三五”国家信息化规划》(全文)
    新华社受权发布“十三五”规划纲要 共分为20篇(
    KDD2015,Accepted Papers
    KDD2016,Accepted Papers
    图像特征提取三大法宝:HOG特征,LBP特征,Haar特征
    【转】34门课改变人生——牛人自学计算机总结
    北上深金融机构势力版图全揭秘20160930
    马云访澳捐2000万美元设立马云-莫利奖学金 只为报答好友肯·莫利
    提升效率
    VMware设置NAT网络
  • 原文地址:https://www.cnblogs.com/bandariFang/p/9682149.html
Copyright © 2020-2023  润新知