lushang 发布的文章

NOTE: this article is not the final version and will be update later

AttachedContentNote

  • This read-only object contains all ContentNote objects associated with an object. This object is available in API version 35.0 and later.
  • link to developer.salesforce.com

ActivityHistory

  • This read-only object is displayed in a related list of closed activities—past events and closed tasks—related to an object. It includes activities for all contacts related to the object. ActivityHistory fields for phone calls are only available if your organization uses Salesforce CRM Call Center.
  • link to ActivityHistory on developer.salesforce.com

The code is an improvement of this article.

  1. The main visualForce page AddmultipleAccounts code:
<apex:page controller="AddmultipleAccountsController">
<apex:form>
<apex:pageBlock title="Add multiple account" id="main_block">
<apex:pageBlockTable value="{!listAccount}" var="acc">
<apex:column headerValue="Account Name">
    <apex:inputField value="{!acc.Name}"/>
</apex:column>
<apex:column headerValue="Account Type">
    <apex:inputField value="{!acc.Type}"/>
</apex:column>
<apex:column headerValue="Industry">
    <apex:inputField value="{!acc.Industry}"/>
</apex:column>
    <!-- you can add more column here -->
</apex:pageBlockTable>
<apex:pageBlockButtons>
<apex:commandButton value="Add 1 Account Row" action="{!addAccount}" reRender="main_block"/>
<apex:commandButton value="Add 5 Account Rows" action="{!addAccounts}" reRender="main_block" />
<apex:commandButton value="Save Accounts" action="{!saveAccounts}" />
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
  1. After insert the records, there will be a simple page to show the result, the page AllAccountsSaved will show the result, you can make more work on this page. the code:
<apex:page sidebar="false" showHeader="true">
<center>
    <h3> Congrats your accounts have been successfully saved! </h3>
</center>
</apex:page>
  1. Here the custom controller AddmultipleAccountsController code:

public with sharing class AddmultipleAccountsController {
    public list<Account> listAccount{get;set;}

    public AddmultipleAccountsController() {
        listAccount = new list<Account>();
        listAccount.add(new Account());
    }

    //add one account at a time
    public void addAccount() {
        listAccount.add(new Account());
    }

    //add five account at a time
    public void addAccounts() {
        for(Integer j=0; j < 5; j++) {
        listAccount.add(new Account());
        }
    }

    public PageReference saveAccounts() {
        try {
            insert listAccount;
        } catch(System.DmlException e) {
            for(Integer i=0; i < e.getNumDml(); i++) {
                System.debug(e.getDmlMessage(i));
            }
        }
        return Page.AllAccountsSaved;
    }
}
  1. A test method AddmultipleAccountsControllerTest for the custom controller above, code:
@isTest
private class AddmultipleAccountsControllerTest {

    static testMethod void testAddAccount() {
         Test.startTest();
         AddmultipleAccountsController aacontroller = new AddmultipleAccountsController();
         aacontroller.addAccount();
         list<Account> listAccount = aacontroller.listAccount;
         Test.stopTest();
         system.assert(listAccount.size() == 2);
    }

    static testMethod void testAddAccounts() {
         Test.startTest();
         AddmultipleAccountsController aacontroller = new AddmultipleAccountsController();
         aacontroller.addAccounts();
         list<Account> listAccount = aacontroller.listAccount;
         Test.stopTest();
         system.assert(listAccount.size() == 6);
    }

    static testMethod void testSaveAccounts() {
        Test.startTest();
         AddmultipleAccountsController aacontroller = new AddmultipleAccountsController();
         aacontroller.listAccount[0].Name = 'lushang test account';
         aacontroller.saveAccounts();
         Test.stopTest();
         Account[] acc = [SELECT id,name from Account where name = 'lushang test account'];
         system.assert(acc.size() == 1);
    }
}
  1. Create a visualForce Tab for the page, the user can use this tab to add multiple records.
  • You can change the tab permission settings in certain profile's "Object Settings"
  • You can translate the tab name in the Translation Workbench's translate bar, section is : "Web Tab"

This article if from developer.salesforce.com and you can see the source here
  1. Loads the original record from the database or initializes the record for an upsert statement.
  2. Loads the new record field values from the request and overwrites the old values.
    If the request came from a standard UI edit page, Salesforce runs system validation to check the record for:

    • Compliance with layout-specific rules
    • Required values at the layout level and field-definition level
    • Valid field formats
    • Maximum field length

    When the request comes from other sources, such as an Apex application or a SOAP API call, Salesforce validates only the foreign keys. Prior to executing a trigger, Salesforce verifies that any custom foreign keys do not refer to the object itself.
    Salesforce runs user-defined validation rules if multiline items were created, such as quote line items and opportunity line items.

  3. Executes all before triggers.
  4. Runs most system validation steps again, such as verifying that all required fields have a non-null value, and runs any user-defined validation rules. The only system validation that Salesforce doesn't run a second time (when the request comes from a standard UI edit page) is the enforcement of layout-specific rules.
  5. Executes duplicate rules. If the duplicate rule identifies the record as a duplicate and uses the block action, the record is not saved and no further steps, such as after triggers and workflow rules, are taken.
  6. Saves the record to the database, but doesn't commit yet.
  7. Executes all after triggers.
  8. Executes assignment rules.
  9. Executes auto-response rules.
  10. Executes workflow rules.
  11. If there are workflow field updates, updates the record again.
  12. If the record was updated with workflow field updates, fires before update triggers and after update triggers one more time (and only one more time), in addition to standard validations. Custom validation rules, duplicate rules, and escalation rules are not run again.
  13. Executes processes.
    If there are workflow flow triggers, executes the flows.
    The Process Builder has superseded flow trigger workflow actions, formerly available in a pilot program. Organizations that are using flow trigger workflow actions can continue to create and edit them, but flow trigger workflow actions aren’t available for new organizations.
  14. Executes escalation rules.
  15. Executes entitlement rules.
  16. If the record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the parent record. Parent record goes through save procedure.
  17. If the parent record is updated, and a grandparent record contains a roll-up summary field or is part of a cross-object workflow, performs calculations and updates the roll-up summary field in the grandparent record. Grandparent record goes through save procedure.
  18. Executes Criteria Based Sharing evaluation.
  19. Commits all DML operations to the database.
  20. Executes post-commit logic, such as sending email.

前言

文章直接翻译自Salesforce开发者页面,原页面很详细,可惜是英文的可能很多人有阅读的障碍,所以翻译成中文,好理解!实际上,原文是针对SOQL查询的,并不是针对一前端网页用户。但是在前端我们使用Salesforce时,也可以使用这样的日期格式或者字面日期,只要转换一下就行非常方便。

典型的字面日期包括:YESTERDAY, TODAY, THIS_WEEK, LAST_MONTH, NEXT_QUARTER, and THIS_FISCAL_YEAR等,这是SOQL查询语句用的。换成前端用户的话,只需要把下下划线\_替换成空格 就行。举例LAST_MONTH变成LAST MONTH.

日期格式

纯日期

格式为 YYYY-MM-DD 例子是 2011-11-11

日期与时间、时区偏移混搭

格式

  • YYYY-MM-DDThh:mm:ss+hh:mm 例子是 2011-11-11T11:11+1:00
  • YYYY-MM-DDThh:mm:ss-hh:mm 例子是 2011-11-11T11:11-8:00
  • YYYY-MM-DDThh:mm:ssZ 例子是 2011-11-11T11:11:11Z

注意:所有时区偏移都是从UTC算起的(可还记得本初子午线和格林威治) 具体可以查看下面两个网页:
http://www.w3.org/TR/xmlschema-2/#isoformats
http://www.w3.org/TR/NOTE-datetime

字面日期

这个就不得了了,为什么?因为实在有太多选择了(部分暂时不能使用在前端,其实前面的就够了):

  • 字面日期(英文/SOQL) 中文(可以直接在前端网页中输入哦) 备注
  • YESTERDAY 昨天
  • TODAY 今天
  • TOMORROW 明天
  • LAST WEEK 上星期
  • THIS_WEEK 本星期
  • NEXT_WEEK 下星期
  • LAST_MONTH 上月
  • THIS_MONTH 本月
  • NEXT_MONTH 下月
  • LAST_90_DAYS 过去 90 天 (注意中间的空格,有数字的字面日期数字需要与前后文字均隔一个空格,下同)
  • NEXT_90_DAYS 未来 90 天
  • LAST_N_DAYS:n 过去 n 天 (n可以随便设置哦!下同)
  • NEXT_N_DAYS:n 未来 n 天
  • NEXT_N_WEEKS:n 未来 n 星期
  • LAST_N_WEEKS:n 过去 n 星期
  • NEXT_N_MONTHS:n 未来 n 个月
  • LAST_N_MONTHS:n 过去 n 个月

THIS_QUARTER
LAST_QUARTER
NEXT_QUARTER
NEXT_N_QUARTERS:n
LAST_N_QUARTERS:n
THIS_YEAR
LAST_YEAR
NEXT_YEAR
NEXT_N_YEARS:n
LAST_N_YEARS:n
THIS_FISCAL_QUARTER
LAST_FISCAL_QUARTER
NEXT_FISCAL_QUARTER
NEXT_N_FISCAL_​QUARTERS:n
LAST_N_FISCAL_​QUARTERS:n
THIS_FISCAL_YEAR
LAST_FISCAL_YEAR
NEXT_FISCAL_YEAR
NEXT_N_FISCAL_​YEARS:n
LAST_N_FISCAL_​YEARS:n

日期限制(最大最小日期)

Saelsforce中的日期是有一个范围的,填入超过这个范围的日期不会被Salesforce接受,同时系统会报错。而在插入(Insert)一个对象时,日期错误可以直接导致整个插入失败。
Salesforce中最小日期为1700-01-01T00:00:00Z GMT, 最大日期为4000-12-31T00:00:00Z GMT.

Salesforce inline editing是非常方便的功能,可以提供方便的在视图中编辑和保存字段的功能。

但是好东西不是十全十美的,它有些限制:
Guidelines for Editing Records with the Inline Editor

而对于列表视图(lists),有下面限制:

  1. 某些标准字段并不支持,比如:Case Status, Opportunity Stage, Opportunity Amount, Opportunity Quantity and Lead Status, and most Task and Event fields只能在记录编辑页面编辑.
  2. 如果org使用了记录类型,则必须保证视图里面的列出的记录全部属于同一个记录类型。换而言之,必须使用记录类型作为筛选条件,同时最多选择一个类型或者留空(对于主记录类型)
  3. 在筛选条件的逻辑里面,不能包含或(OR)从句(clause)
  4. 对于活动(Activities)则必须有额外的筛选,指定任务(Task)为真(True)或者为假(False)

更多信息,可以参考Salesforce英文说明:Editing Records Directly From Enhanced Lists