本文介绍了如何直接从 Salesforce Lightning 下载 CSV 格式的报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 Python 脚本,用于从 Salesforce 以 CSV 格式下载报告.

I am creating a Python script for downloading a report from Salesforce as a CSV.

我的脚本非常适合 Salesforce Classic.但是,我需要让它为 Lightning Experience 工作.我正在使用 simple-salesforce Python 包来访问我们的组织.对于 SF Classic,我输入一个结构如下的链接:https://my-company.my.salesforce.com/my_report_id?view=d&snip&export=1&enc=UTF-8&xf=csv

My script is working perfectly fine for Salesforce Classic. However, I need to get it working for Lightning Experience. I'm using the simple-salesforce Python package to access our org. For SF Classic I enter a link that is structured like this: https://my-company.my.salesforce.com/my_report_id?view=d&snip&export=1&enc=UTF-8&xf=csv

脚本基本上是这样的:

from simple-salesforce import Salesforce
import requests
import pandas as pd
import csv
from io import StringIO

sf = Salesforce(username="my_username", password="my_password",
                security_token="my_token")
sf_org = "https://my_company.my.salesforce.com/"
report_id = "0000" # Some report id

sf_report_loc = "{0}{1}?view=d&snip&export=1&enc=UTF-8&xf=csv".format(sf_org, report_id)

response = requests.get(sf_report_loc, headers=sf.headers, cookies={"sid": sf.session_id})
new_report = response.content.decode("utf-8")
df = pd.read_csv(StringIO(new_report)) # Save the report to a DataFrame.

每当我切换到 Lightning 时,链接都无效并且我被重定向.有没有办法在 Lightning 中完成这项工作?

Whenever I switch to Lightning, the link is invalid and I get redirected. Is there a way to make this work in Lightning?

推荐答案

尝试使用 isdtp 参数.在经典中,它用于强制查看没有侧边栏或标题的页面,例如将 isdtp=vw 添加到随机页面并查看会发生什么.

Try with isdtp parameter. In classic it was used to force view pages without sidebar or header, for example add isdtp=vw to a random page and see what happens.

https://my_company.my.salesforce.com/00O.....?isdtp=p1&export=1&enc=UTF-8&xf=csv ?

(不知道什么是p1",但这是我在 Chrome 下载历史记录中看到的,作为报告源 URL 的一部分)

(no idea what's 'p1' but that's what I see in Chrome's download history as part of the report's source URL)

这篇关于如何直接从 Salesforce Lightning 下载 CSV 格式的报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 15:20