Salesforce基础知识总结

27、【系统Name字段最大长度总结】:Maximum length for system 'Name' fields

User Alias最大长度为8且允许重复.

26、【启用Admin登录任何User功能】:官方文档
Setup -> Login Access Policies

25、【在Community中使用Asset File】:
a. 访问Asset File:Setup -> Enter "Asset File" in Quick Find / Search Box;
b. 属性Let unauthenticated users see this asset file,勾选后Community Builder里边配的Login Experience Builder Page的背景图片才能被Guest User看见;

24、【Sharing Rule基于条件共享——空值处理】:
a. 文本空值使用"";(
List View可不填值表示空值)


23、【DML Statements vs. Database Class Methods】:

Example: If we are inserting 10 records in an object, Where 5 records are correct and remaining 5 records are incorrect.

  • In DML statement (Insert) all the 10 records will be failed, because if one record is incorrect or error means all other remaining records will not be inserted. It will throw error.
  • In Database.insert 5 records will be inserted, remaining 5 records will be failed.(i.e. Partial DML Operation).

22、【设置初始密码 + 初始UI为LEX】:
a. 通过System.setPassword(uid, pwd);为用户设置初始密码:Partner User可直接登陆;Internal User登陆后跳转至change pwd页面,若用作测试不想change pwd,点击Cancel即可。
b. User对象的字段 UserPreferencesLightningExperiencePreferred 可控制UI风格,ture -> LEX;false -> Classic.

21、【会话设置 - Admin代理登陆Logout后重新登回Admin】:
背景:在使用代理登陆时,当我们退出后,往往会跳转到重新登陆界面,但我们更希望保持Admin的登陆状态。
方案:
安全性控制==》会话设置==》unchecked 在登录为用户后强制重新登录;

20、【Admin - Recycle Bin注意事项】:View and Purge the Recycle Bin
1. 被删除的记录最多保存15天,之后管理员将无法恢复;
2. 临时存储在Recycle Bin的记录不占用Salesforce数据存储空间;
3. 存储容量是Org Data Storage以MB计的25倍;如:org分配了2000M数据存储空间,2000 * 25 = 50000条存储记录。
Note:如果数据被误删且超过15天,如需恢复得联系Salesforce Surport,而且成本包括固定费用
$1w (10000美金) + 20个工作日的时间成本,另外最多恢复当前日期前3个月的数据。- Salesforce Data Export Service

补充:当清空垃圾箱后没办法通过undelete按钮恢复数据,此时可以使用Data Loader (Export All) / Salesforce Inspector导出大量被删除的没有超过15天的数据:


19、【Admin - Tab Show/Hide注意事项】:
如果用户对某对象无Read权限,那么即使Tab设置为Default On,也看不见Tab。

18、【在Data Loader中
Use Bulk API注意事项】:
You can hard delete records when you configure Data Loader to Use Bulk API. Keep in mind that hard deleted records are immediately deleted and can’t be recovered from the Recycle Bin

17、【Unit TestLoading Test Data from Static Resource】:
a、在Excel中录入一些测试数据,保证第一行为字段名,第二行为值;
b、将Excel转为CSV文件后导入静态资源;
c、在测试类里面调用
Test.loadData(Sobject.sObjectType, 'Static Resource Name')返回List<Sobject>

16、【Sandbox License】:一张图比较不同sandbox类型的区别


15、【Manage Sets of Apex Test Classes with Test Suites】:当有新需求变更时我们往往需要重新部署到生产环境,我们可以将这个部署单元的测试类代码打包,以检测整体的覆盖率和异常,这时就可以使用Test Suite了。

14、【Cross-object formulas】:
NOTE: If you create a formula that references a field on another object and display that formula in your page layout, users can see the field on the object even if they don’t have access to that object record. For example, if you create a formula field on the Case object that references an account field, and display that formula field in the case page layout, users can see this field even if they don’t have access to the account record.

13、Multiple-Picklist值如果Label和API Name不一致,那么填入API Name,展示会自动显示Label Name,如果需要填写多个值,需要用";"隔开。

12、【Apex中不支持Switch Case语法】:  Add "Switch" or "Case" Statement to Apex
但支持switch on ... when ...的语法。

public static void mainRouterMethod(String methodname, String dataparm){
    switch on methodname{
        when 'searchProperty'       { return OnePage_Controller.searchProperty(dataparm);         }   
        when 'queryPropertyDetail'  { return OnePage_Controller.queryPropertyDetail(dataparm);    }
        when 'savePropertyData'     { return OnePage_Controller.savePropertyData(dataparm,atts);  } 
        when 'queryPropertyRelatedTower'     { return OnePage_Controller.queryPropertyRelatedTower(dataparm);  } 
    }
}

11、可以自lookup,但是不能自master-detail。

10、equals()用法:常量.equals(变量),如果弄反,一旦常量为空,将抛错。

9、【理解Savepoint和rollback()】:
当一个事务中的逻辑执行完毕后,rollback()方法会使原DML操作回滚到保存点的状态,实例如下:

8、【Database DML Parameters - allOrNothing】:
对Database.insert(List<SObject> sobjects, allOrNothing)方法中第二个参数的认识:
如果allOrNothing为false表示允许部分insert成功,如果true表示一有失败全部操作失败,项目中多用false。
实例:

List<Account> accList = new List<Account>{
    new Account(Name='ttt'),
    new Account()
};
Database.SaveResult[] srList = Database.insert(accList, false);
for(Database.SaveResult sr : srList) {
    if (!sr.isSuccess()) {
        // Operation failed, so get all errors                
        for(Database.Error err : sr.getErrors()) {
            System.debug('The following error has occurred.');                    
            System.debug(err.getStatusCode() + ': ' + err.getMessage());
            System.debug('Fields that affected this error: ' + err.getFields());
        }
    }
}

这个时候Name为ttt的Account成功插入数据库,另外一个则插入失败,报错如下:


7、【update record cross object】:

// Query for the contact, which has been associated with an account.
Contact queriedContact = [SELECT Account.Name 
                          FROM Contact 
                          WHERE FirstName = 'Mario' AND LastName='Ruiz'
                          LIMIT 1];
// Update the contact's phone number
queriedContact.Phone = '(415)555-1213';
// Update the related account industry
queriedContact.Account.Industry = 'Technology';
// Make two separate calls 
// 1. This call is to update the contact's phone.
update queriedContact;
// 2. This call is to update the related account's Industry field.
update queriedContact.Account; 

6、【upsert用法】:

Contact jane = new Contact(FirstName='Jane',
                         LastName='Smith',
                         Email='jane.smith@example.com',
                         Description='Contact of the day');
insert jane;
// 1. Upsert using an idLookup field
// Create a second sObject variable.
// This variable doesn’t have any ID set.
Contact jane2 = new Contact(FirstName='Jane',
                         LastName='Smith',  
                         Email='jane.smith@example.com',
                         Description='Prefers to be contacted by email.');
// Upsert the contact by using the idLookup field for matching.
upsert jane2 Contact.fields.Email;
// Verify that the contact has been updated
System.assertEquals('Prefers to be contacted by email.',
                   [SELECT Description FROM Contact WHERE Id=:jane.Id].Description);

5、You don’t need to specify the Id field in the query as it is always returned in Apex queries, whether it is specified in the query or not. For example: SELECT Id,Phone FROM Account and SELECT Phone FROM Account are equivalent statements.

4、Master-Detail关系中,标准对象不能作为detail side。
master -> parent | detail -> child
如果Test为自定义对象,那么为其创建一个master关系字段Account,那么,Account字段必填。 

3、【关于Dependent Fields】:Dependent Picklist Considerations
Controlling Field: Checkbox(Std / Custom),Picklist(Std / Custom)
Dependent Field: Picklist(Custom),Multiple Picklist(Custom)


2、【Future methods】:
Future methods must be static methods,
and can only return a void type.
The specified
parameters must be primitive data types.

List<Account> accList = new List<Account>{
    new Account(Name='ttt'),
    new Account()
};
Database.SaveResult[] srList = Database.insert(accList, false);
for(Database.SaveResult sr : srList) {
    if (!sr.isSuccess()) {
        // Operation failed, so get all errors                
        for(Database.Error err : sr.getErrors()) {
            System.debug('The following error has occurred.');                    
            System.debug(err.getStatusCode() + ': ' + err.getMessage());
            System.debug('Fields that affected this error: ' + err.getFields());
        }
    }
}

List<Account> accList = new List<Account>{
    new Account(Name='ttt'),
    new Account()
};
Database.SaveResult[] srList = Database.insert(accList, false);
for(Database.SaveResult sr : srList) {
    if (!sr.isSuccess()) {
        // Operation failed, so get all errors                
        for(Database.Error err : sr.getErrors()) {
            System.debug('The following error has occurred.');                    
            System.debug(err.getStatusCode() + ': ' + err.getMessage());
            System.debug('Fields that affected this error: ' + err.getFields());
        }
    }
}
// Query for the contact, which has been associated with an account.
Contact queriedContact = [SELECT Account.Name 
                          FROM Contact 
                          WHERE FirstName = 'Mario' AND LastName='Ruiz'
                          LIMIT 1];
// Update the contact's phone number
queriedContact.Phone = '(415)555-1213';
// Update the related account industry
queriedContact.Account.Industry = 'Technology';
// Make two separate calls 
// 1. This call is to update the contact's phone.
update queriedContact;
// 2. This call is to update the related account's Industry field.
update queriedContact.Account; 
Contact jane = new Contact(FirstName='Jane',
                         LastName='Smith',
                         Email='jane.smith@example.com',
                         Description='Contact of the day');
insert jane;
// 1. Upsert using an idLookup field
// Create a second sObject variable.
// This variable doesn’t have any ID set.
Contact jane2 = new Contact(FirstName='Jane',
                         LastName='Smith',  
                         Email='jane.smith@example.com',
                         Description='Prefers to be contacted by email.');
// Upsert the contact by using the idLookup field for matching.
upsert jane2 Contact.fields.Email;
// Verify that the contact has been updated
System.assertEquals('Prefers to be contacted by email.',
                   [SELECT Description FROM Contact WHERE Id=:jane.Id].Description);
Contact jane = new Contact(FirstName='Jane',
                         LastName='Smith',
                         Email='jane.smith@example.com',
                         Description='Contact of the day');
insert jane;
// 1. Upsert using an idLookup field
// Create a second sObject variable.
// This variable doesn’t have any ID set.
Contact jane2 = new Contact(FirstName='Jane',
                         LastName='Smith',  
                         Email='jane.smith@example.com',
                         Description='Prefers to be contacted by email.');
// Upsert the contact by using the idLookup field for matching.
upsert jane2 Contact.fields.Email;
// Verify that the contact has been updated
System.assertEquals('Prefers to be contacted by email.',
                   [SELECT Description FROM Contact WHERE Id=:jane.Id].Description);
Contact jane = new Contact(FirstName='Jane',
                         LastName='Smith',
                         Email='jane.smith@example.com',
                         Description='Contact of the day');
insert jane;
// 1. Upsert using an idLookup field
// Create a second sObject variable.
// This variable doesn’t have any ID set.
Contact jane2 = new Contact(FirstName='Jane',
                         LastName='Smith',  
                         Email='jane.smith@example.com',
                         Description='Prefers to be contacted by email.');
// Upsert the contact by using the idLookup field for matching.
upsert jane2 Contact.fields.Email;
// Verify that the contact has been updated
System.assertEquals('Prefers to be contacted by email.',
                   [SELECT Description FROM Contact WHERE Id=:jane.Id].Description);
Contact jane = new Contact(FirstName='Jane',
                         LastName='Smith',
                         Email='jane.smith@example.com',
                         Description='Contact of the day');
insert jane;
// 1. Upsert using an idLookup field
// Create a second sObject variable.
// This variable doesn’t have any ID set.
Contact jane2 = new Contact(FirstName='Jane',
                         LastName='Smith',  
                         Email='jane.smith@example.com',
                         Description='Prefers to be contacted by email.');
// Upsert the contact by using the idLookup field for matching.
upsert jane2 Contact.fields.Email;
// Verify that the contact has been updated
System.assertEquals('Prefers to be contacted by email.',
                   [SELECT Description FROM Contact WHERE Id=:jane.Id].Description);
Contact jane = new Contact(FirstName='Jane',
                         LastName='Smith',
                         Email='jane.smith@example.com',
                         Description='Contact of the day');
insert jane;
// 1. Upsert using an idLookup field
// Create a second sObject variable.
// This variable doesn’t have any ID set.
Contact jane2 = new Contact(FirstName='Jane',
                         LastName='Smith',  
                         Email='jane.smith@example.com',
                         Description='Prefers to be contacted by email.');
// Upsert the contact by using the idLookup field for matching.
upsert jane2 Contact.fields.Email;
// Verify that the contact has been updated
System.assertEquals('Prefers to be contacted by email.',
                   [SELECT Description FROM Contact WHERE Id=:jane.Id].Description);
Contact jane = new Contact(FirstName='Jane',
                         LastName='Smith',
                         Email='jane.smith@example.com',
                         Description='Contact of the day');
insert jane;
// 1. Upsert using an idLookup field
// Create a second sObject variable.
// This variable doesn’t have any ID set.
Contact jane2 = new Contact(FirstName='Jane',
                         LastName='Smith',  
                         Email='jane.smith@example.com',
                         Description='Prefers to be contacted by email.');
// Upsert the contact by using the idLookup field for matching.
upsert jane2 Contact.fields.Email;
// Verify that the contact has been updated
System.assertEquals('Prefers to be contacted by email.',
                   [SELECT Description FROM Contact WHERE Id=:jane.Id].Description);

It’s important to note thatfuture methods are not guaranteed to execute in the same order as they are called. Again, future methods are not guaranteed to execute in the same order as they are called.

1、All Apex variables, whether they’re class member variables or method variables, are initialized to null. Make sure that you initialize your variables to appropriate values before using them.For example, initialize a Boolean variable to false.

未完待续......

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值