1.如何清除Salesforce的log(日志)

  1. 在开发控制台中,选择控制台底部的“Query Editor”标签
  2. 选中复选框“Use Tooling API”
  3. 使用此查询:SELECT Id FROM ApexLog
  4. 删除所有行(使用Shift键选择所有行)删除所有行后,您将能够保存新的调试日志。 参考: ​https://help.salesforce.com/articleView?id=000194045&type=1​​​​

2.如何处理Viscoforce页面Size大小超出显示问题

Salesforce开发指导文档_Salesforce开发

问题:筛选出来的数据过大,修改筛选语句

Salesforce开发指导文档_Salesforce开发_02

3.如何处理Record is read-only的Trigger报的错误问题

Salesforce开发指导文档_Salesforce开发_03

问题:afterupdate无法更新数据,需要在beforeupdate操作

1.找到触发器目标位置

if(Trigger.isAfter &&Trigger.isUpdate){
Cbl_Lead_Approval Approval = new Cbl_Lead_Approval();
Approval.Approval(trigger.new,trigger.oldMap);
}

2.修改触发器

if(Trigger.isBefore&&Trigger.isUpdate){
Cbl_lead_Approval Approval = new Cbl_Lead_Approval();
Approval.Approval(trigger.new,trigger.oldMap);
}

4.如何比较新旧字段值,对其他字段赋值操作

1.新增一个类,并添加比较方法

//创建类
Public without sharing class Cbl_Lead_ChangeDate{
//定义方法,输入新询盘和旧询盘Id值
public void Approval(List<Lead>newleads,List<Id,Lead>oldMap){
//for中创建新值leadfortime
for(Lead leadfortime:List<Lead>Trigger.new){
//获取旧询盘Id
Lead oldLead1 = oldMap.get(leadfortime.id);
//比较方法,新值状态不等于旧值状态更新日期
if(leadfortime.Status != oldLead1.Status){
//新值日期为今日日期
leadfortime.Stage_Date__c =Date.today();
}
}
}
}

2.触发器中添加调用类

trigger TriggerLead on Lead(Before insert,Before Update){
//Beforce isInsert调用类
if(Trigger.IsBefore&&Trigger.isInsert){
//定义类对象
Cbl_Lead_ChangeDate Approval = new Cbl_Lead_ChangeDate();
//调用对象方法,输入新询盘和旧询盘Id值
Approval.Approval(trigger.new,trigger.oldMap);
}
//Beforce Update调用类
if(Trigger.IsBefore&&Trigger.Update){
//定义类对象
Cbl_Lead_ChangeDate Approval = new Cbl_Lead_ChangeDate();
//调用对象方法,输入新询盘和旧询盘Id值
Approval.Approval(trigger.new,trigger.oldMap);
}
}

5.如何通过类中Sql插入数据


//定义类方法,并传入leadId
public Boolean isRepeated(String leadId){
//Select当前lead数据
Lead leadResult = [SELECT Id, Phone, MobilePhone, Email__c, Company,OwnerId FROM Lead
WHERE Id = :leadId];
//创建list数组
List<Lead> leadList = new List<Lead>();
//创建Sql语句,String类型
String leadSql = 'SELECT Id, Phone, MobilePhone, Company, Owner.Name, OwnerId, Status '+
'From Lead '+' Where OwnerId <> \''+leadResult.OwnerId+'\''+
' AND Status <> \'' + 'Disqualified' + '\'';
//插入数据
leadList = (List<Lead>)Database.query(leadSql);
}

6.如何处理Unable to Access Page的问题

Salesforce开发指导文档_Salesforce开发_04

1.问题主要是当前赋值Visualforce的id和对应页面的正确id不匹配导致,查找到问题Link的ApexSalesforce开发指导文档_Salesforce开发_05

2.如何解决如下:

theLink = URL.getSalesforceBaseUrl().toExternalForm()+'/p/process/ProcessInstanceWorkitemWizardStageManager?id=';
//筛选出当前页面审批中的Process Id
List<ProcessInstanceWorkitem> piWorkItems = [SELECT Id FROM ProcessInstanceWorkItem WHERE ProcessInstance.TargetObjectId =:accoutPeriodId
And ProcessInstance.Status = 'Pending'];
if(piWorkItem.size()>0){
//获取当前List的第一个值id
theLink = theLink + piWorkItems.get(0).id
}

7.如何处理Too many SOQL queries:101

Salesforce开发指导文档_Salesforce开发_06

1.问题主要出现当前页面调用了太多触发器,导致许多类都触发了SOQL语句,使得当前数据太大了,只能优化代码了,有三个处理方式:

  • 停止不必要的触发器,添加条件才需要执行
  • 检查旧值和新增,只在更改时执行(beforce update)
  • 如果有任何递归触发SOQL,在递归外,再执行SOQL

8.如何处理A non-foreign key field cannot be referenced in a path expression: Review_Informations__r 

参考下社区发布的文章:

https://salesforce.stackexchange.com/questions/333525/a-non-foreign-key-field-cannot-be-referenced-in-a-path-expression

更新前

public  class Reviews {

public static void updateReviewRangeOnContact (List <Review_Info__c> reviewList){

Set <Id> contactIds = new Set <Id> ();

if(reviewList != null && reviewList.size()>0){
for (Review_Info__c revi : reviewList){
if (revi.Contact__c != null){
contactIds.add(revi.Contact__c);
}
}
}

List <Contact> ContactList = new List <Contact> ();
ContactList = [SELECT id, Review_rate__c,(SELECT Id,Review_Rating__c FROM Review_Informations__r)
FROM Contact
WHERE ID IN : contactIds];

for (contact con : ContactList){
con.Review_rate__c = con.Review_Informations__r.Review_Rating__c;
}
if (ContactList != null && ContactList.size()>0 )
update ContactList;
}
}

更新后:

public  class Reviews {

public static void updateReviewRangeOnContact (List <Review_Info__c> reviewList){

Set <Id> contactIds = new Set <Id> ();

for (Review_Info__c revi : reviewList){
contactIds.add(revi.Contact__c);
}
contactIds.remove(null);
List <Contact> ContactList = [SELECT id, Review_rate__c,(SELECT Id,Review_Rating__c FROM Review_Informations__r)
FROM Contact
WHERE ID IN : contactIds];
for (contact con : ContactList){
if(con.Review_Informations__r.size() > 0) {
con.Review_rate__c = con.Review_Informations__r[0].Review_Rating__c;
}
}
update ContactList;
}
}

9.如何保留小数点后两位数值(金币格式)

//for example to apex visualforce page
<td style="text-align:center;">
//digital format,RMB money format
<apex:outputText value="{0, number, ###,###,###,###,##0.00}" style="display: inline-block;">
<apex:param value="{!invoiceWrapp.order.Tax_Amount__c}"/>
</apex:outputText>
</td>

10.如何写系统page抛出来的测试

//for example to ApexPages.addMessage
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, Label.checkLead + '<a href=\'\\'+ ll.Id + '\' style=\'color:blue;\'> '+ll.Name+'</a>'));
//test for ApexPages.addMesssage
PageReference pageRef2 = new PageReference('apex/Submit?id='+lead0.Id);
Test.setCurrentPage(pageRef2);
SubmitLead_Controller sublead2 = new SubmitLead_Controller(new ApexPages.StandardController(lead0));
sublead2.SubmitLead();
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, Label.checkLead + '<a href=\'\\'+ lead0.Id + '\' style=\'color:blue;\'> '+lead0.Name+'</a>'));
//All the test example
SubmitLead_ControllerTest
//All the example
SubmitLead_Controller

11.查看debug的两种方式

  1. 不进入用户账号界面-新建调试日志

Salesforce开发指导文档_Salesforce开发_07

2.进入用户界面-查看debug栏日志

Salesforce开发指导文档_Salesforce开发_08