salesforce中常用技能总结(纯粹干货,深度积累)

来源:互联网 发布:刺客信条2mac 编辑:程序博客网 时间:2024/04/28 05:29

学习总结越往后越精彩:认知从浅层次到深化

1、使用SOQL语句查询时,字符串类型的只能使用‘单引号’,否则报错:Unknown error parsing query;

eg:SELECT Id, Subject, CaseNumber, Status, Priority 

        FROM Case 

        WHERE CaseNumber = '00001036' //注意此处autoNumber类型数字为String类型

2、标准字段的API Name即为该标准字段的Field Name;

eg:Case标准对象的Subject API Name即为 Subject

3、计算两个日期之间相隔的天数:

eg:TODAY() - DATEVALUE( CreatedDate )

        Implementd__Date__c - DATEVALUE( CreatedDate )

注意:只有当日期为标准字段时,才使用DATEVALUE()来转化

4、在terminal中使用curl方式查看json数据(通常使用workbench>utilities>REST Explorer),通常会用到sessionId,获取方法如下:

String sessionID = UserInfo.getSessionId();
System.debug(sessionID);

5、完整版REST services demo

@RestResource(urlMapping='/Cases/*')global with sharing class CaseManager {    @HttpGet    global static Case getCaseById() {        RestRequest req = RestContext.request;        String caseId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);        Case result = [SELECT CaseNumber, Subject, Status, Origin, Priority                       FROM Case                       WHERE Id = :caseId];        return result;    }    /*HttpGet步骤:1、创建RestRequest类型的req对象(RestContext.request的返回值类型就是RestRequest)2、通过req对象的requestURI属性利用字符串检索技术拿到caseId3、创建Case对象result,并将通过caseId查到的记录赋值给该对象,注意“WHERE Id = :caseId”4、返回Case对象*/    @HttpPost    global static ID createCase(String subject, String status,        String origin, String priority) {        Case thisCase = new Case(            Subject=subject,            Status=status,            Origin=origin,            Priority=priority);        insert thisCase;        return thisCase.Id;    }    /*HttpPost步骤:1、声明并创建一个Case类型对象thisCase,并为该对象的标准字段赋值2、将自定义对象插入到Case表中形成一条记录3、返回一个新纪录的类型为ID的变量Id用于查找新纪录*/    @HttpDelete    global static void deleteCase() {        RestRequest req = RestContext.request;        String caseId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);        Case thisCase = [SELECT Id FROM Case WHERE Id = :caseId];        delete thisCase;    }    /*思路:要删除某一条记录首先要找到该记录,而方法可以是利用soql语言查找到某一记录的主码,这里是Id(使用rest服务请求获取到uri后从uri中取得的id)HttpDelete步骤:1、创建ResrRequest对象req2、声明caseId,并将rest请求到的uri截取/后的值赋给该变量3、利用soql语句查到Id = :caseId的那条记录4、删除该记录*/    @HttpPut    global static ID upsertCase(String id, String subject, String status, String origin, String priority) {        Case thisCase = new Case(        Id = id,            Subject = subject,            Status = status,            Origin = origin,            Priority = priority        );        upsert thisCase;        return thisCase.Id;    }    /*HttpPut步骤:1、声明并创建一个Case类型对象thisCase,并为该对象定义标准字段赋值2、将自定义对象插入到Case表中形成一条记录或者更新Id为id的记录3、返回一个新纪录的类型为ID的变量Id用于查找新纪录*/    @HttpPatch    global static ID updateCaseFields() {        RestRequest req = RestContext.request;        String caseId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);        Case thisCase = [SELECT Id FROM Case WHERE Id = :caseId];        Map<String, Object> params = (Map<String, Object>)JSON.deserializeUntyped(req.requestBody.toString());        for(String fieldName : params.keySet()) {            thisCase.put(fieldName, params.get(fieldName));        }        update thisCase;        return thisCase.Id;    }    /*HttpPatch步骤:1、创建RestRequest类型的req对象(RestContext.request的返回值类型就是RestRequest)2、通过req对象的requestURI属性利用字符串检索技术拿到caseId3、创建Case对象,并把按Id查到的Case表记录赋值给该对象4、将请求获得的requestBody转化成字符串后,反序列化为对象强制转化为Map<String, Object>后赋值给Map变量params5、遍历对象的key,并在通过id找到的Case对象thisCase中写入key-value6、更新记录7、返回记录的id*/}/*共性:1、每个对象系统自带一个Id属性,它是系统自动分配的;2、每一种Http方法均为global static3、@HttpPut与@HttpPost的区别(upsert,insert)*/



区别:put vs patch

the same:You can update records with the put or patch methods.

the difference: put can either create new resouce or update the existing resource; patch can update the existing resouce exclusively.

6、Apex中在使用类继承时需要使用到的关键字:extends,super,virtual,override.跟Java继承不同的是,超类必须使用virtual修饰,子类使用override和extends修饰,如果需要重写父类的方法,父类中该方法需要用virtual修饰,子类需要使用override。另外如果子类需要使用超类的域或者方法则需要使用super关键字,注意构造方法的复用不需要用成对的virtual和override关键字修饰超类的构造方法和子类的构造方法。

7、利用公式字段插入图片:IMAGE(path,img_title,height,width)

8、在report中使用The "Power of One" technique来统计不重复的数据

9、在Apex中使用静态资源加载jquery:

<apex:page>        <!-- Add the static resource to page's <head> -->    <apex:includeScript value="{! $Resource.jQuery }"/>        <!-- A short bit of jQuery to test it's there -->    <script type="text/javascript">        jQuery.noConflict();        jQuery(document).ready(function() {            jQuery("#message").html("Hello from jQuery!");        });    </script>        <!-- Where the jQuery message will appear -->    <h1 id="message"></h1>    </apex:page>

10、简单的使用vf标准控制器来展示Contact列表,并实现点击名称跳转详细页面。方法有三种:

<apex:page standardController="Contact" recordSetVar="contacts"><apex:pageBlock title="Contact List"><apex:repeat value="{!contacts}" var="ct"><li><apex:outputLink value="/{!ct.Id}">{!ct.Name}</apex:outputLink><!-- <apex:outputLink value="{!URLFOR($Action.Contact.View,ct.id,[retURL=''])}">{!ct.Name}</apex:outputLink> --><!-- <apex:outputLink value="https://componentstest-dev-ed.my.salesforce.com/{!ct.Id}">{!ct.Name}</apex:outputLink>  --></li></apex:repeat> </apex:pageBlock></apex:page> 

11、增强lookup查找功能:我们通过lookup进行对父记录Name进行搜索时,通常默认只能使用Name来搜索,有时候比如我们在子记录中想要通过Phone来搜索Account的Name,这个时候可以在setup->enter 'Search Settings' in Quick Search Box中即可增强搜索

12、将使用html编辑的前端网站放到force.com平台上的方法:将做好的网站,比如shangpinhui/Bootstrap所有文件打包成zip上传到salesforce的Static Resources中,比如拿shangpinhui为例,目录结构为:shangpinhui->images/js/css/index.html,打包上传后命名为ShangpinhuiZip(名字不能一数字开头),之后在Visualforce Pages中编辑如下代码:

<apex:page docType="html-5.0" sidebar="false" showHeader="false" standardStylesheets="false"       action="{!URLFOR($Resource.ShangpinhuiZip, 'shangpinhui/index.html')}"></apex:page>

在action里面通过URLFOR表达式来将页面加载进去。这样就不用考虑修改网站页面资源引用的路径了,注意在Developer Edition里面由于每个账号限制只允许放一个网站绑定一个url,所以要实现多个网站同时上传作为作品展示,可以再做一个列表,分别通过超链接映射到相应的网站上,这样就可以将您的所有作品都绑定在一个页面上分别访问。

13、在Company Information中可以查看User Licence的使用次数,如下图:



1 0
原创粉丝点击