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.

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章