You can write Apex Batch Class
for doing the mass transfer. In the execute method you can insert the PartnerNetworkRecordConnection
object.
Below is the sample code i.e. not compiled for mass transferring the Account
object if Publish and Subscribe
is done in respective Org.
global class ShareAccount implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext BC) {
return Database.getQueryLocator([Select Id from Account]);
}
global void execute(Database.BatchableContext BC, List<sObject> scope){
//GET THE CONNECTION ID FROM PARTNERNETWORKCONNECTION WHERE THE RECORDS NEEDS TO BE SHARED CONSIDERING THE CONNECTION IS ONLY 1
List<PartnerNetworkConnection> pncList = [SELECT Id
FROM PartnerNetworkConnection
WHERE ConnectionStatus = 'Accepted' LIMIT 1]
List<PartnerNetworkRecordConnection> pnrcInsertList = new List<PartnerNetworkRecordConnection>();
if(!pncList.isEmpty()) {
//LOOP THROUGH ALL THE ACCOUNT FOR SHARING THE ACCOUNT
for(Account accObj : scope){
pnrcInsertList.add(new PartnerNetworkRecordConnection( ConnectionId = pncList[0].Id,
LocalRecordId = accObj.Id,
SendEmails = FALSE));
}
}
if(!pnrcInsertList.isEmpty()) {
insert pnrcInsertList;
}
}
global void finish(Database.BatchableContext BC){
}
}
Note: You can write the batch class for initial transfer and then you can utilize the trigger code