Salesforce 遇到的一些问题。

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zhang44429824/article/details/78842435

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.

猜你喜欢

转载自blog.csdn.net/zhang44429824/article/details/78842435