• 033_SFDC-Apex案例整理-未完


    1.Boolean can be return null

    Boolean isError;
    if (isError == true) {
      System.debug('Hello Error!');
    }
    System.debug('This is a Error:'+isError);
    

     Return :This is a Error:null

    2.接口的开发,本人仍然倾向于REST ,简单,快捷,适合集成移动端开发; SOAP Webservice:还要去Generate WSDL,每次修改都要重新给予调用者,较麻烦。

    3.Clone :Clone a Quote Line Item with an Apex Controller --------------           /{!QuoteLineItem.Id}/e?clone=1&retURL={!QuoteLineItem.Id}

      

    QuoteLineItem ql = [select Id, QuoteId, PricebookEntryId,
                               Quantity, UnitPrice, Discount,
                               Description, ServiceDate, SortOrder,
                               ListPrice, Subtotal, TotalPrice
                        from QuoteLineItem
                        limit 1];
    QuoteLineItem q2 = ql.clone();
    insert q2;
    System.debug('New Line Item: '+q2);
    

     4.Map List

    Map<ID, Contact> m = new Map<ID, Contact>([SELECT Id, LastName FROM Contact]);
    
    List<Opportunity> oppList = [Select Id, AccountId from Opportunity]; 
    
    Map<Id,Opportunity> accOppMap = new Map<Id,Opportunity>(); 
          for(Opportunity o : oppList){ 
                     accOppMap.put(o.AccountId,o);
                 }
    

     5.Invoking Apex Using JavaScript

    Apex in AJAX:

    <script src="/soap/ajax/15.0/connection.js" type="text/javascript"></script>
    <script src="/soap/ajax/15.0/apex.js" type="text/javascript"></script>
    
    JS:
    var account = sforce.sObject("Account");
    var id = sforce.apex.execute("myClass","makeContact",
    {lastName:"Smith",
    a:account});
    
    Apex:
    global class myClass {
    webService static Id makeContact(String lastName, Account a) {
    	Contact c = new Contact(LastName = lastName, AccountId = a.Id);
    	return c.id;
    	}
    }
    

    @RemoteAction :为JS调用的方法,

    @RemoteAction
    global static String getItemId(String objectName) { ... }
    
    Apex @RemoteAction methods must be static and either global or public.
    

    一种存取Map的方式:

    <apex:repeat value="{!directors}" var="dirKey">
        <apex:outputText value="{!dirKey}" /> --
        <apex:outputText value="{!directors[dirKey]}" /><br/>
    </apex:repeat>
    
    
    // key=> value
    public Map<String,String> directors {
        get {
        return new Map<String, String> {
        'Kieslowski' => 'Poland',
        'del Toro' => 'Mexico',
        'Gondry' => 'France'
            };
        }
    set;
    }
    

     关于分组内容的获取:

     List<AggregateResult> callLogList = [SELECT Name, MAX(CreatedDate) SuccessDate
                                                   FROM B 
                                                  WHERE Name in :a 
                                                    AND N = 'Success'
                                               GROUP BY Name];
            
            Map<Id, Datetime> callLogMap = new Map<Id, Datetime>();
            for (AggregateResult callLog : callLogList) {
            	callLogMap.put((Id)callLog.get('Name'), (Datetime)callLog.get('SuccessDate'));
            }
    

      

    此刻,静下心来学习
  • 相关阅读:
    【转】HTML5的小知识点小集合
    11月15日下午 ajax返回数据类型为XML数据的处理
    11月15日下午 用代码操作文件(文件夹)
    11月15日上午文件上传
    11月14日用AJAX、PHP、SESSION做购物车
    各种进位制转换
    11月13日上午ajax返回数据类型为JSON数据的处理
    11月13日上午省、市、区(县)三级联动
    11月10日下午 ajax做显示信息以后用ajax、Bootstrp做弹窗显示信息详情
    11月10日上午ajax基础知识、用ajax做登录页面、用ajax验证用户名是否可用、ajax动态调用数据库
  • 原文地址:https://www.cnblogs.com/bandariFang/p/7372960.html
Copyright © 2020-2023  润新知