salesforce pagereference 和接收url上传递的参数

http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_system_pagereference.htm  salesforce 官方介绍 pagereference

pagereference

   fullURL可以是一个完整的链接地址。也可以是一个相对路径。

  也可以通过url中传递链接参数。string fullURL = 'http://www.baidu.com/s?wd=a';a 可以当做一个参数传递进去。

代码如下:

  PageReference pageRef = new PageReference('fullURL');

这个方法中  PageReference acctPage = new ApexPages.StandardController(account).view(); 默认调转到account默认的视图中(在pagelayout中自定义按钮中会用到这个方法)。 setRedirect(Boolean) Sets the value of the PageReference object's redirect attribute. If set to true, a redirect is performed through a client side redirect.意思是说,设置成true,直接就从客户端跳转了。

 public PageReference save() {
        // Add the account to the database. 
        insert account;
        // Send the user to the detail page for the new account.
        PageReference acctPage = new ApexPages.StandardController(account).view();
        acctPage.setRedirect(true);
        return acctPage;
    }
PageReference Instance Methods
getAnchor()
Returns the name of the anchor referenced in the page’s URL. That is, the part of the URL after the hashtag (#).
getContent()
Returns the output of the page, as displayed to a user in a Web browser.
getContentAsPDF()
Returns the page as a PDF, regardless of the <apex:page> component's renderAs attribute.
getCookies()
Returns a map of cookie names and cookie objects, where the key is a String of the cookie name and the value contains the list of cookie objects with that name.
getHeaders()
Returns a map of the request headers, where the key string contains the name of the header, and the value string contains the value of the header.
getParameters()
Returns a map of the query string parameters that are included in the page URL. The key string contains the name of the parameter, while the value string contains the value of the parameter.
getRedirect()
Returns the current value of the PageReference object's redirect attribute.
getUrl()
Returns the relative URL associated with the PageReference when it was originally defined, including any query string parameters and anchors.
setAnchor(String)
Sets the URL’s anchor reference to the specified string.
setCookies(Cookie[])
Creates a list of cookie objects. Used in conjunction with the Cookie class.
setRedirect(Boolean)
Sets the value of the PageReference object's redirect attribute. If set to true, a redirect is performed through a client side redirect.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
设置和维护 Salesforce 组织..................................................................................................................1 欢迎您 Salesforce 管理员 ........................................................................................................................................................1 Salesforce 试用版......................................................................................................................................................................1 设置您的组织...........................................................................................................................................................................4 管理用户.................................................................................................................................................................................83 管理数据的用户访问权限...................................................................................................................................................116 导入数据...............................................................................................................................................................................221 管理数据...............................................................................................................................................................................334 安全性...................................................................................................................................................................................342 监视组织...............................................................................................................................................................................433 配置 Salesforce Mobile 应用程序.........................................................................................................................................450 安装软件包和管理应用程序...............................................................................................................................................491
### 回答1: 好的。 使用 Python 与 Salesforce REST API 进行交互的代码大致如下: 首先,你需要安装 Salesforce REST API 的 Python 客户端库,例如 `simple-salesforce`。你可以使用 `pip` 安装这个库: ``` pip install simple-salesforce ``` 然后,你需要在 Salesforce 中创建一个连接并获取相应的访问令牌。有关如何进行这些操作的详细信息,请参阅 Salesforce 的文档。 接下来,你可以使用 Python 代码来访问 Salesforce REST API。例如,你可以使用以下代码检索 Salesforce 中的联系人: ```python from simple_salesforce import Salesforce # 创建 Salesforce 连接 sf = Salesforce(username='YOUR_USERNAME', password='YOUR_PASSWORD', security_token='YOUR_SECURITY_TOKEN') # 检索联系人 contacts = sf.Contact.select('Id, FirstName, LastName') for contact in contacts: print(f'{contact["FirstName"]} {contact["LastName"]}') ``` 你还可以使用以下代码在 Salesforce 中创建新的联系人: ```python # 创建新联系人 new_contact = { 'FirstName': 'John', 'LastName': 'Doe', 'Email': '[email protected]' } sf.Contact.create(new_contact) ``` 这只是一些简单的示例代码。Salesforce REST API 提供了更多功能,你可以在 Salesforce 的文档中了解有关详细信息。 ### 回答2: Python是一种高级编程语言,而Salesforce REST API是一种用于与Salesforce平台进行通信和交互的接口。以下是使用Python编写与Salesforce REST API交互的代码示例: 1. 导入所需的库和模块: ```python import requests import json ``` 2. 定义Salesforce连接信息: ```python base_url = 'https://your_salesforce_instance.salesforce.com' api_version = 'vXX.X' # 根据你的Salesforce实例的版本选择 access_token = 'your_access_token' ``` 3. 发送GET请求以获取记录: ```python def get_records(object_name): url = f'{base_url}/services/data/{api_version}/sobjects/{object_name}' headers = { 'Authorization': f'Bearer {access_token}', 'Content-Type': 'application/json' } response = requests.get(url, headers=headers) if response.status_code == 200: records = response.json() return records else: return None ``` 4. 发送POST请求以创建记录: ```python def create_record(object_name, record_data): url = f'{base_url}/services/data/{api_version}/sobjects/{object_name}' headers = { 'Authorization': f'Bearer {access_token}', 'Content-Type': 'application/json' } response = requests.post(url, headers=headers, data=json.dumps(record_data)) if response.status_code == 201: new_record = response.json() return new_record else: return None ``` 请注意,上述代码只是示例代码,你需要根据自己的实际需求进行适当的修改和定制。你需要替换`your_salesforce_instance.salesforce.com`为你的Salesforce实例的主机名,并根据你的访问权限获取和设置正确的访问令牌(access token)。此外,你还需要根据所需操作的对象名称(object name)和记录数据(record data)进行调整。 希望以上示例代码能帮助你开始使用Python与Salesforce REST API进行交互。 ### 回答3: Python和Salesforce REST API的代码可以用来与Salesforce平台进行数据交互。 1. 导入必要的Python模块: ```python import requests import json ``` 2. 设置Salesforce REST API的访问凭证: ```python username = 'your_username' password = 'your_password' security_token = 'your_security_token' client_id = 'your_client_id' client_secret = 'your_client_secret' grant_type = 'password' ``` 3. 获取访问令牌(access token): ```python data = { 'grant_type': grant_type, 'client_id': client_id, 'client_secret': client_secret, 'username': username, 'password': password + security_token } response = requests.post('https://login.salesforce.com/services/oauth2/token', data=data) response_data = json.loads(response.text) access_token = response_data['access_token'] instance_url = response_data['instance_url'] ``` 4. 使用访问令牌调用Salesforce REST API: ```python headers = { 'Authorization': 'Bearer ' + access_token, 'Content-Type': 'application/json' } # 示例:创建一个新的联系人 new_contact = { 'LastName': 'Smith', 'FirstName': 'John', 'Email': '[email protected]' } create_contact_url = instance_url + '/services/data/v51.0/sobjects/Contact/' response = requests.post(create_contact_url, headers=headers, data=json.dumps(new_contact)) response_data = json.loads(response.text) created_contact_id = response_data['id'] ``` 以上是使用Python访问Salesforce REST API的基本代码示例。确保用户名、密码、安全令牌、客户端ID和客户端密钥正确,并根据实际需求进行相应的修改。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值