033_SFDC-Apex案例整理-未完

本文探讨了Salesforce平台上的Apex编程语言与JavaScript的集成应用,包括使用REST与SOAP进行接口开发的选择,Apex控制器中Clone方法的实现,以及通过JavaScript调用Apex方法的示例。同时,文章提供了Apex@RemoteAction方法的使用说明。
摘要由CSDN通过智能技术生成

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'));
        }

  

转载于:https://www.cnblogs.com/bandariFang/p/7372960.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值