Salesforce APIs全面解析笔记详情 - 应用场景&图解实例

SF API类型】:Salesforce提供了多种APIs,让我们能方便的访问Salesforce数据,包括REST API, SOAP API, Bulk API, Metadata API等,如下图:

各类API介绍】:

#1、REST API :it’s an excellent choice of technology for use with mobile applications and web projects.

简介:REST API is a simple and powerful web service based on RESTful principles. 
资源类别:It exposes all sorts of Salesforce functionality via REST resources and HTTP methods. 
数据操作:For example, you can create, read, update, and delete(CRUD) records, search or query your data, retrieve object metadata, and access information about limits in your org. 
支持格式:REST API supports both XML and JSON.
Rest请求四大构成要素:A REST request consists of four components: a resource URI, an HTTP method, request headers, and a request body. 
工具:Workbench、check out cURL or Postman

URI(/services/data/v36.0):For convenience, the top-level domain is omitted from the displayed URI. For example, the full URI of the resource that’s prepopulated in the URI text box is https://foo.my.salesforce.com/services/data/v36.0.

注意:
在解析某一对象元数据时,所有小写,如:/services/data/v39.0/sobjects/account/describe
在使用Post HTTP Methond插入数据时注意,字符串必须使用双引号,如下:Phone类型数据也写成双引号

最佳实践:

1、插入记录

背景(/services/data/v39.0/sobjects/account     Post        Workbench)

{
    "Name": "A-Post Test Account",
    "Type": "Prospect",
    "Phone": "(023) 444-1837"
}

https://componentstest-dev-ed.my.salesforce.com/services/data.json查看版本系列/.xml

2、查找记录

/services/data/v39.0/sobjects/account/0012800001VHuls.xml (xml格式)
/services/data/v39.0/sobjects/contact/00328000015jLeS/account (查询父记录)

背景(Get        Workbench)

/services/data/v39.0/query/?q=SELECT+Name+FROM+Account+WHERE+Phone='(023)+444-1837'

Use Apex REST API when you want to expose your Apex classes and methods so that external applications can access your code through REST architecture. 
Apex REST API supports both OAuth 2.0 and Session ID for authorization.

Rest Resource:a single data record, a collection of records, or even dynamic real-time information.  URI
standard HTTP methods{HEAD, GET, POST, PATCH, DELETE} no PUT, PUT was used to replace the entire resource, not used in Force.com REST API.

CRUD

Method & Function

====================================================

HTTP method CRUD

———————————————

HEAD R(Retrieve information but lacks resp and body)
GET R(Retrieve information)
POST C(create a new object)
PATCH U(update a record)
DELETE D(delete a record)

Exposing REST Service - Endpoint:

===================================

1.For Security End Points: Use a connected App
2.For Open End Points: Use Salesforce Sites

Calling REST Service:

#2、SOAP API:For example, you can use SOAP API to integrate Salesforce with your org’s ERP and finance systems. 

简介:SOAP API is a powerful web service. It uses a Web Services Description Language(WSDL) file to rigorously define the parameters for accessing data through the API. 
支持格式:SOAP API supports XML only. 
备选方案:Most of the SOAP API functionality is also available through REST API. It just depends on which standard better meets your needs.
应用优势:Because SOAP API uses the WSDL file as a formal contract between the API and consumer, it’s great for writing server-to-server integrations.
WSDLs及分类:Web Services Description Language, It contains the bindings, protocols, and objects to make API calls. | Enterprise(strongly typed | integration for a single Salesforce org) and Partner(loosely typed | For several orgs) WSDLs

/c—Specifies that we’re using the enterprise WSDL. Use /u for the partner WSDL.

Tools:We’re using a third-party tool called SoapUI to consume our enterprise WSDL file. SoapUI is a free and open-source app for testing web services.

登录时password需要password+security_token e.g. 

<urn:login>
    <urn:username>username</urn:username>
    <urn:password>password+security_token</urn:password>
</urn:login>

登录时会遇到如下问题:

TLS 1.0 has been disabled in this organization. Please use TLS 1.1 or higher when connecting to Salesforce using httpshttps://salesforce.stackexchange.com/questions/142362/tls-1-0-has-been-disabled-in-this-organization-please-use-tls-1-1-or-higher-whe

Critical Updates重要更新

help documention:https://help.salesforce.com/articleView?id=000221207&type=1

TLS 的全称是“安全传输层协议”。这是在两个通信应用程序之间提供隐私和数据完整性的协议,并且可用于 Web浏览器和其他需要通过网络安全交换数据的应用程序。
Salesforce 要求在 2017 年 7月 22 日前升级到 TLS 1.1 或更高版本。我们将在该日期开始禁用 TLS 1.0 加密协议,这将阻止仍使用该协议的客户访问一些 Salesforce服务。

Use Apex SOAP API when you want to expose Apex methods as SOAP web service APIs so that external applications can access your code through SOAP.
Apex SOAP API supports both OAuth 2.0 and Session ID for authorization.

#3、Bulk API:

主要用途:Bulk API is a specialized RESTful API for loading and querying lots of data at once. By lots, we mean 50,000 records or more. 
特征:Bulk API is asynchronous, meaning that you can submit a request and come back later for the results. 
用例:Bulk API is great for performing tasks that involve lots of records, such as loading data into your org for the first time.

#4、Streaming API:

简介:Streaming API is a specialized API for setting up notifications that trigger when changes are made to your data. 
模型:It uses a publish-subscribe, or pub/sub, model in which users can subscribe to channels that broadcast certain types of data changes.
优势:The pub/sub model reduces the number of API requests by eliminating the need for polling. Streaming API is great for writing apps that would otherwise need to frequently poll for changes.

5、Metadata API:

功能:Use Metadata API to retrieve, deploy, create, update, or delete customizations for your org. 
用例:The most common use is to migrate changes from a sandbox or testing org to your production environment. 
区别:Metadata API is intended for managing customizations and for building tools that can manage the metadata model, not the data itself.

6、Tooling API:

Use Tooling API to manage and deploy working copies of Apex classes and triggers and Visualforce pages and components. You can also set checkpoints or heap dump markers, execute anonymous Apex, and access logging and code coverage information.

 

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值