Salesforce 遇到的一些问题。

1  关于custom button

调用object以及调用apex:

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

if( '{!Campaign_Plan__c.Campaign_Status__c}' != 'Activated'){
alert('You are not allow to deactivate campaign plan.');
}
else {

var answer = window.confirm ('Are you sure to deactivate current campaign plan?');
alert(answer );
if( answer ){
   alert('answer' );
  //  var campaign = new sforce.SObject("Campaign_Plan__c");
 //alert(campaign);
    alert('{!Campaign_Plan__c.Id}');
    var result = sforce.apex.execute('WD_CampaignPlanUnlock','updateToDraft',{planId :'{!Campaign_Plan__c.Id}'});
alert(result );
    window.location.reload();

  }

 
}

2 审批流中的lock和unlock可以使用apex来改变。

需要在setup中,Process Automation Settings中把Enable record locking and unlocking in Apex勾上,不然会报 {faultcode:'soapenv:Client; faultstring:'No such parameter id defined for operation. please check the WSDL for the service.'} 错误。

3.我在写visualforce page的时候用到了button代码如下:

<apex:commandButton action="{!save}" value="Cancel" immediate="true"/> 其中用到了immediate这个函数,此时,controller中的save方法便不会执行。

<apex:commandButton action="{!save}" value="Cancel" immediate="true"/>

但是在canel方法中如果不使用就会出问题。官方解释:A Boolean value that specifies whether the action associated with this component should happen immediately, without

processing any validation rules associated with the fields on

the page. If set to true, the action happens immediately and
validation rules are skipped. If not specified, this value defaults
to false.在我看来,immediate只会执行action操作,如页面跳转等,不会执行方法里的逻辑操作。

4.with sharing 和 without sharing ,以及默认不声明区别

在salesforce中,声明类大概可以分成三类:分别是可以声明为with sharing,without sharing,以及两者均不声明.

1 public with sharing class A {}
2 
3 public without sharing class B{}
4 
5 public class C{}

三者区别如下:

  • with sharing:类声明称with sharing类型,则需要走sharing settings中的sharing rules;
  • without sharing:类声明称without sharing类型,则不需要走sharing settings中的sharing rules;
  • 不声明:类不声明上述两种类型,则默认走sharing rules,如果别的类调用此类,则按照别的类的sharing rules 校验。

总局:具体用哪个形式,看项目需求,如果项目需要可控度高,防止因为salesforce自身的坑而无可奈何,则可以通过without sharing形式,校验自己用apex代码搞定;如果需要salesforce封装的sharing功能进行快速开发,可以通过with sharing。

sharing settings路径:setup->Administer->Security Controls->Sharing Settings。

Difference between Workflows and ProcessBuilder:
ProcessBuilder:Create a record ,

Update any related record ,

Use a quick action to create a record,

update a record, or log a call Launch a flow ,

Send an email Post to Chatter ,

Submit for approval Call apex methods ,

But the process builder doesn’t support outbound messages.

Workflow does only 4 actions :

Create Task ,

Update Field ,

Email Alert ,

Outbound Message.

TestVisible Annotation

@TestVisible

Use the TestVisible annotation to allow test methods to access private or protected members of another class outside the test class. These members include methods, member variables, and inner classes. This annotation enables a more permissive access level for running tests only. This annotation doesn’t change the visibility of members if accessed by non-test classes.

With this annotation, you don’t have to change the access modifiers of your methods and member variables to public if you want to access them in a test method. For example, if a private member variable isn’t supposed to be exposed to external classes but it should be accessible by a test method, you can add the TestVisible annotation to the variable definition.

Order of Execution (Rules, Triggers etc.) in Salesforce & Debug Log

Salesforce has a bunch of rules that can be defined on objects and fields. For example you can define validation rules, workflow rules, assignment rules, escalation rules, auto-response rules, triggers etc.

As an administrator and developer it is important for you to understand the order in which these rules and triggers are executed. Here is the gist of sequence in which Salesforce will evaluate different rules (For detailed explanation, please click here).

(By the way if you are preparing for Advanced Developer Certification i.e. DEV-501, there are a couple of questions on the order of execution)

  1. System Validation rule (required field, field format) (SV)
  2. Before Triggers are executed (BT)
  3. Custom Validation rules are checked (CV)
  4. After Triggers are executed (AT)
  5. Assignment Rules are executed (AR)
  6. Auto-Response Rules are executed (ARR)
  7. Workflow Rules are executed (WR)
    1. Before and after triggers are executed one more time if the workflow rule updates a field (BT & AT)
  8. Escalation Rules are executed (ER)
  9. Parent Rollup Summary Formula or Cross Object Formula fields are updated in the respective objects. (RSF, COF) (These parent records also goes through the entire execution order)
  10. Criteria Based Sharing rules are evaluated (CBS)
  11. Any Post-Commit Logic is executed (PCL)  (like sending an email)

To remember this sequence you can memorise the following.

SV -> BT -> CV -> AT -> AR -> ARR -> WR (BT, AT) -> ER -> RSFCOF -> CBS -> PCL

update 2021:

On the server, Salesforce:

  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. Before executing a trigger, Salesforce verifies that any custom foreign keys do not refer to the object itself.

    Salesforce runs custom validation rules if multiline items were created, such as quote line items and opportunity line items.

  3. Executes record-triggered flows that are configured to run before the record is saved.
  4. Executes all before triggers.
  5. Runs most system validation steps again, such as verifying that all required fields have a non-null value, and runs any custom 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.
  6. 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.
  7. Saves the record to the database, but doesn't commit yet.
  8. Executes all after triggers.
  9. Executes assignment rules.
  10. Executes auto-response rules.
  11. Executes workflow rules. If there are workflow field updates:
    1. Updates the record again.
    2. Runs system validations again. Custom validation rules, flows, duplicate rules, processes, and escalation rules are not run again.
    3. Executes before update triggers and after update triggers, regardless of the record operation (insert or update), one more time (and only one more time)
  12. Executes escalation rules.
  13. Executes the following Salesforce Flow automations, but not in a guaranteed order.
    • Processes
    • Flows launched by processes
    • Flows launched by workflow rules (flow trigger workflow actions pilot)

    When a process or flow executes a DML operation, the affected record goes through the save procedure.

  14. Executes entitlement rules.
  15. Executes record-triggered flows that are configured to run after the record is saved.
  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. After the changes are committed to the database, executes post-commit logic such as sending email and executing enqueued asynchronous Apex jobs, including queueable jobs and future methods.

官方文档:https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers_order_of_execution.htm

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值