My organization Having 15000 records in Accounts object, can we transfer all the records in one step?
---> Yes, you can achieve this by writing Apex class. I am giving code for this please go through once you can under stand easily.
Controller:-
global class SendOldRecord
{
public void sendrec(list<Account> ls)
{
//This list declaration for PartnerNetworkrecords
List<PartnerNetworkRecordConnection> lstShareRecords = new List<PartnerNetworkRecordConnection>();
//This list declaration for the Connections with this Organization.
List<PartnerNetworkConnection> connMap=[select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection
where ConnectionStatus = 'Accepted' and ConnectionName='Appshark Software Pvt Ltd'];
//This for is to loop all the connections
for(PartnerNetworkConnection network : connMap)
{
for(Account acc:ls)
{
//object declaration for PartnerNetwork
PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();
system.debug('Second for loop');
newrecord.ConnectionId = network.Id;
newrecord.LocalRecordId = acc.id;
newrecord.RelatedRecords = 'Contact';
newrecord.SendClosedTasks = true;
newrecord.SendOpenTasks = true;
newrecord.SendEmails = true;
//All the Records are added to the PartnerNetwork
lstShareRecords.add(newrecord);
}
}
system.debug('List\n'+lstShareRecords);
//These Records are inserted into Partnernetwork
//using lstShareRecords.
insert lstShareRecords;
}
}
in the case of bulk records , we need to handle them in Batch process,for i have implemented following batch class and pass to list of accounts at every run,
Batch Controller:-
global class RecordBatchApex implements Database.Batchable<Account>
{
global list<Account> start(Database.BatchableContext bc)
{
list<account> lstAcc = [select Id from Account];
return lstAcc;
}
global void execute(Database.BatchableContext bc,List<Account> lstAccount)
{
system.debug('*******************Execute of Batch Apex***********');
system.debug(lstAccount);
sendoldrecord od=new sendoldrecord();
od.sendrec(lstAccount);
}//BatchApex Completes
// execution with this finish method
global void finish(Database.BatchableContext BC)
{system.debug('****Finished*****');
}}
Once run that code even from System log,then you can find all the records in business partner login.
0 Comments