Salesforce跨Org的迁移

由于某些原因(新环境事先未准备、基于已有的功能等)基于已有Organization的Sandbox做开发及内部测试再迁移到新的环境做UAT及正式使用,一般来说迁移会是件很痛苦的事情!除非你对已有的Organization的所有东西从头到尾的了解!除了环境没有的情况下其它情况多应该采用所在Org的Sandbox。

未知的东西凡事都得多思考再动手!

一、思路

1、了解迁移的基础知识

Ant Migration Tool Guide

https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/meta_development.htm

Metadata API Developer Guide

https://developer.salesforce.com/docs/atlas.en-us.api_meta.meta/api_meta/meta_intro.htm

 

2、工具

(1)Ant 

导航Build>Develop>Tools>Lightning Platform Tools and Toolkits>Ant Migration Tool查看Ant使用文档及下载

https://developer.salesforce.com/docs/atlas.en-us.daas.meta/daas/forcemigrationtool_install.htm

(2)Packages选取工具

VS Code的扩展工具 —— Salesforce Package.xml Generator Extension for VS Code,选取及修改元数据都非常方便

https://marketplace.visualstudio.com/items?itemName=VignaeshRamA.sfdx-package-xml-generator

(3)VS Code

由于Ant在部署时避免出现governer limit(如Maximum size of request is 52428800 bytes),部署静态资源等可以直接采用VS Code非常方便

https://code.visualstudio.com/

 

3、错误排查

(1)查找错误

直接通过部署工具如Ant或SFDC后台查看错误并记录到本地,如

除了看错误明细以外还可以查看报错的位置(增强自信心!)

 后台查找方式:Deploy>Deployment Status

(2)快速定位

A、借助第三方平台Down一个待迁移Org完整的Metadata,方面快速找到缺失元数据members所属的types

https://packagebuilder.herokuapp.com

B、通过功能强大的第三方工具(如Visual Studio 2015)打开retrieve的Metadata,方便快速查找问题

(3)解决错误

错误日志进行分类,一类类进行处理,前期错误太多的话处理到一定数量就进行deploy

(4)记录问题

 对各类型的错误解决方式进行记录,方便下次排查

 

二、准备

仅整理了部分

1、Translation Settings设置为enabled

Administer>Translation Workbench>Translation Settings>Enable

2、为组织开启State and Country/Territory Picklists

Administer>Data Management > State and Country/Territory Picklists

3、开启Turn on account teams for your organization

Build>Customize>Accounts>Account Teams>Enable Account Teams

 

三、问题及解决(未详细整理-供自己使用)

1、安装第三方Packages

Error: Cannot create a new component with the namespace: ONTAP

2、设置Account的Sharing为Private

Error:sfdc Can't specify an external sharing model for Account 

Administer>Security Controls>Sharing Settings选择Account设置Account and Contract为Private

3、关闭 Enable Account History
Error: exceeded the allowed number of fields to track on a given entity
(1)找到对应的Object进行关闭
(2)在元数据中关闭<enableHistory>true</enableHistory>替换为<enableHistory>false</enableHistory>
https://www.tutorialkart.com/salesforce/how-to-enable-field-history-tracking-in-salesforce/
Error: The entity: Account does not have history tracking enabled
<trackHistory>true</trackHistory>替换为<trackHistory>false</trackHistory>
4、引用所有相关的对象
Error: referenceTo value of 'CN_POC_Type__c' does not resolve to a valid sObject type
5、移除Account中的标准字段IsExcludedFromRealign
IsExcludedFromRealign是根据启用Manage Territories而自动生成的,在Administer>Manage Territories不可见即启动不了时需要移除
objects/Account.object (Account.IsExcludedFromRealign) -- Error: Could not resolve standard field's name.
https://success.salesforce.com/answers?id=90630000000h2oxAAA
6、因为picklist是Global Value Set,所以需要添加GlobalValueSet元数据抓取相关数据
Error: The global picklist cannot be resolved
<types>
<members>CN_BDS_Audit_Status</members>
...
<name>GlobalValueSet</name>
</types>
https://success.salesforce.com/answers?id=9063A000000ZmHJQA0
7、将Account里的Record Types全部删除
objects/Account.object (Account.Account_Channel_MT) -- Error: Picklist value: External Referral in picklist: AccountSource not found
or
objects/ONTAP__Product__c.object (ONTAP__Product__c.ONTAP__Parts) -- Error: Picklist value: ISP in picklist: CN_Channel__c not found
如,
<recordTypes>
<fullName>Account_Channel_AB</fullName>
...
</recordTypes>
8、【首先确保Packages在目标迁移环境已安装好】对应第三方packages如OnTap下的某些Object在待迁移环境与目标迁移环境不匹配时,需将多余的待迁移元数据删除
objects/Account.object (Account.ONTAP__City__c) -- Error: Cannot create a new component with the namespace:
ONTAP. Only components in the same namespace as the organization can be created through the API
如,
<fields>
<fullName>ONTAP__City__c</fullName>
...
</fields>
9、将移除的UserRole对应的sharedTo进行移除
objects/Account.object (Account.CN_Prospect_Createdby_Today) -- Error: In field: role - no Role named CHINA found
将<role>CHINA</role>直接移除
<sharedTo>
<role>CHINA</role>
</sharedTo>
10、为formula类型的field且直接关联到了ontap,建议移除无用的object或当前field
objects/CN_Feedback__c.object (CN_Feedback__c.Question_Type__c) -- Error: Field CN_Question_Type__c does not exist. Check spelling.
11、直接移除对应的validationRules
objects/Account.object (Account.DataAndNegotationReqForProspConvert)
-- Error: Field $Setup.Approval_Settings__c.Prospect_Conversion_Approval_Required__c does not exist. Check spelling.
12、移除ONTAP__City__c
layouts/Account-Account Layout.layout -- Error: In field: field - no CustomField named Account.ONTAP__City__c found
or
objectTranslations/Account-en_US.objectTranslation -- Error: In field: fullName - no CustomField named Account.ONTAP__City__c found
or
layouts/Account-Account Layout.layout -- Error: In field: page - no ApexPage named AzureAccountAttachments found
<layoutItems>
<behavior>Edit</behavior>
<field>ONTAP__City__c</field>
</layoutItems>
13、移除app中不存在的tab 或 加上不存在的CustomTab
applications/OnTap_India.app -- Error: In field: tab - no CustomTab named Target_Achievement found
<CustomApplication xmlns="http://soap.sforce.com/2006/04/metadata">
<tabs>Target_Achievement</tabs>
</CustomApplication>
14、去掉FlowDefinition
flowDefinitions/Survey_Question_Supplement.flowDefinition
-- Error: You can't create a flow definition directly through the API. A flow definition is created automatically when you create
<types>
<members>*</members>
<name>FlowDefinition</name>
</types>
同时去掉Flow
<types>
<members>*</members>
<name>Flow</name>
</types>
15、移除对应的customMetadata
customMetadata/Contract_Expired_Notify_Setting.Competitive_Contract_Expired.md
-- Error: Custom metadata type Contract_Expired_Notify_Setting__mdt is not available in this organization.
16、加上ApexPage为IN_Maintain的
tabs/Maintain.tab -- Error: In field: page - no ApexPage named IN_Maintain found
17、添加确少的ApexClass
classes/KPI_Report_Controller_Test.cls -- Error: Variable does not exist: CN_BatchKpiCreation
18、Custom Settings的元数据也是出现在CustomObject
classes/IN_OnTabMainDataImport.cls -- Error: Variable does not exist: CN_Import_Max_Number__c
如少了ONTAP__OnTapSettings__c
19、直接移除对应的relatedLists
layouts/Account-Account Layout.layout -- Error: Invalid field:TERRITORY.NAME in related list:AccountAssignedTerritory2sRelatedList
<relatedLists>
...
<relatedList>AccountAssignedTerritory2sRelatedList</relatedList>
</relatedLists>
20、干脆不迁移Profile及ProfilePasswordPolicy,再去手工创建
profiles/IN BDR Director.profile -- Error: In field: recordType - no RecordType named Account.Account_Channel_CD found
21、第三方package如果源迁移环境添加了自定义的field迁移时必须要勾选对应的Object
classes/CN_ABI_Utility.cls -- Error: CN_Total_Quantity__c,
No such column 'CN_Total_Quantity__c' on entity 'ONTAP__Order__c'. If you are attempting to use a custom field,
如 ONTAP__Order__c
22、去掉Activities对应的Settings元数据
settings/Activities.settings -- Error: You can't use the Tooling API or Metadata API to enable or disable Shared Activities.
To enable this feature, visit the Activity Settings page in Setup. To disable this feature, contact Salesforce.
23、translations里手工移除flowDefinitions
translations/en_US.translation -- Error: In field: fullName - no FlowDefinition named Send_Account_Deactivation_to_Approval found
如,
<flowDefinitions>
...
</flowDefinitions>
24、actionOverrides手工添加对应的page、class
objects/Account.object -- Error: CN_NewAccount does not exist or is not a valid override for action New.
如 添加 CN_NewAccount
25、将迁移过程中新增的东西暂时移除以免打乱节奏
pages/IN_Maintain.page -- Error: Apex class 'IN_MaintainController' does not exist
如 IN_MaintainController及对应的一系列object等
26、ONTAP对应CustomMetaData的元数据全部移除
An object 'ONTAP__OnTap_Permission_Objects.Order_List' of type CustomMetadata was named in package.xml, but was not found in zipped directory

 

四、其它注意

1、单独配置profile元数据为什么获取不到objectPermissions等其它项?

因为profile的权限都是关联到了具体的对象,如objectPermissions关联到了CustomObject,所以需要同时配置好相关的元数据
<types>
<members>*</members>
<name>Profile</name>
</types>

 

五、成功的截图

 

:不是所有的都可以按Metadata迁移,不能够通过Metadata进行迁移的就必须手动处理

 

posted on 2019-07-14 18:48  村_长  阅读(770)  评论(0编辑  收藏  举报

导航