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