Ive blogged about Salesforce to Salesforce before and how to programmatically pass records from 1 org to another, but I wanted to blog about specifically how to pass over certain records, such as Attachments and Tasks etc
list<PartnerNetworkRecordConnection> newrecords = new list<PartnerNetworkRecordConnection>();
List<PartnerNetworkConnection> connMap = new List<PartnerNetworkConnection>();
connMap=[select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ConnectionStatus = 'Accepted' and ConnectionName=<<connection>> LIMIT 1] ;
Account[] acc =[Select id From Account where Name = <<account>> limit 1];
Attachment[] attaches =[Select id,IsPartnerShared,Name From Attachment where Parentid=: acc[0].id and IsPartnerShared=false limit 1];
if (attaches.size() > 0){
Set<id> newfunctions = new Set<id>();
for(Attachment thisattach: attaches) {
PartnerNetworkRecordConnection newrecord = SearchFunctionUtils.addPartnerNetworkRecordConnection(connMap);
if (!Test.isRunningTest()){
newrecord.LocalRecordId = acc[0].id ;
newrecord.RelatedRecords = 'Attachment';
newrecords.add(newrecord);
}
newfunctions.add(thisattach.id);//Attachments to be uploaded
}
insert newrecords;
}
The key difference is you have to set RelatedRecords and the LocalRecordId is not the id of the Attachment but Id of the Account. There are also other standard objects which also require to use this method, which I have found are poorly documented. The best way of identifying which objects is probably by trial and error, but the Document object is another such object.
For Tasks
SendClosedTasks and SendOpenTasks properties are important.
Seefor more details
http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_objects_partnernetworkrecordconnection.htm