function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Moving account records from one salesforce org to another salesforce org through Apex



i need to transfer the records from one salesforce org to another salesforce org  through apex. 


IF i click on accounts tab in visuvalforce page, all the accounts of the org are displayed , and there is an option like


move to my orgi, if user click on this button  i need to move all the account records to his salesforce account tab.


i am looking for workaround to achieve this one. Its very urgent to me.



Thank you in advance!



Best Regards,




you can look in to salesforce to salesforce feature .. and the respective  objects involved in this.. you can acheive this by enabling salesforce to salesforce.....some help from here


Hi Kiran,


Thank you for quick response.


I gone through the Salesforce to salesforce connection procedure.


How can i automate the above procedure with creating connecton with the target and accepring connection from


input org automatically and sharing records through apex clss itself.


How can i achieve above one!


Thanks in advance!


Best Regards,




go through the complete documentation of salesforce to salesforce .. that will give you complete idea..


Here is the code just change accordingly


Trigger AutoforwardLead on Lead(after update)
String UserName = UserInfo.getName();
String orgName = UserInfo.getOrganizationName();
List<PartnerNetworkConnection> connMap = new List<PartnerNetworkConnection>
([select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ConnectionStatus = 'Accepted']);
List<PartnerNetworkRecordConnection> prncList = new List<PartnerNetworkRecordConnection>();
for(Integer i =0; i< Trigger.size; i++)
Lead ld =[i];
String lId = ld.Id;
for(PartnerNetworkConnection network : connMap)
String cid = network.Id;
String status = network.ConnectionStatus;
String connName = network.ConnectionName;
if(ld.OwnerId == '00540000001Rt67')
PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();
newrecord.ConnectionId = cid;
newrecord.LocalRecordId = lId;
newrecord.SendClosedTasks = true;
newrecord.SendOpenTasks = true;
newrecord.SendEmails = true;
System.debug('Inserting New Record'+newrecord);
insert newrecord;