美文网首页
2017/4/19 周三 -- webService/Apex类

2017/4/19 周三 -- webService/Apex类

作者: 每日好奇心 | 来源:发表于2017-04-20 10:35 被阅读24次
  • 自定义按钮调用Apex方法
    使用WebService声明的方法,类名使用global声明
    global class DoCustomerOk { WebService static String doOK(String customerId){ RoseCustomer__c customer = new RoseCustomer__c(); customer.Id = customerId; customer.IsOk__c = true; update customer; return '确认成功'; } }
    在自定义按钮的JS中使用sforce.apex.execute()调用:

var s = sforce.apex.execute("类名","方法名",{参数1:'123456',参数2:'123456',...});

`

    {!REQUIRESCRIPT("/soap/ajax/35.0/connection.js")} 
    {!REQUIRESCRIPT("/soap/ajax/35.0/apex.js")} 

  if({!RoseCustomer__c.IsOk__c} == 1){
    alert('已确认,无需再次确认');
  }else{
    var s = sforce.apex.execute("DoCustomerOk","doOK",            
   {customerId:'{!RoseCustomer__c.Id}'});

       alert(s);
      window.location.reload();
  }

`

  • Apex类修饰符;
    1.private 不可用在Top 类中,仅可在内部类中使用,外部不可访问当new Test 调用my()时,可正确执行,当通过 new Test.InnerClazz时报InnerClazz不 存在

    2.public在当前应用和命名空间使用

    3.global 任意访问,webService必须是global的,如果一个方法或者内部类为global,则Top类必须为global

    4.with sharing/without sharing 当前类权限模式,一般不使用,根据具体情况而定。

  1. with sharing 当前类遵循SF的共享模型按SQL语句执行的结果集只查出有权限的数据。
  1. without sharing 按SQL语句执行

类定义形式
private | public | global
[virtual | abstract | with sharing | without sharing]
class ClassName [implements InterfaceNameList] [extends ClassName] {
// The body of the class
}

  • Batch/Schedule
    实现Database.Batch<sObject> 接口,(实现Database.Stateful防止回滚)
    使用DevelopConsole里的Crtl+E 输入

Database.executeBatch(new BatchName());

执行Batch操作。

相关文章

网友评论

      本文标题:2017/4/19 周三 -- webService/Apex类

      本文链接:https://www.haomeiwen.com/subject/qtbczttx.html