Sample Code:
PartnerNetworkConnection network = [ SELECT Id FROM PartnerNetworkConnection WHERE ConnectionStatus = ‘Accepted’ LIMIT 1 ];
List < PartnerNetworkRecordConnection > listConnections = new List < PartnerNetworkRecordConnection >();
PartnerNetworkRecordConnection connection = new PartnerNetworkRecordConnection();
connection.ConnectionId = network.Id;
connection.LocalRecordId = ‘0015Y00002dfRIF’;//Id of the record to be shared to the other Salesforce Org
listConnections.add( connection );
insert listConnections;
List < PartnerNetworkRecordConnection > listConnections = new List < PartnerNetworkRecordConnection >();
PartnerNetworkRecordConnection connection = new PartnerNetworkRecordConnection();
connection.ConnectionId = network.Id;
connection.LocalRecordId = ‘0015Y00002dfRIF’;//Id of the record to be shared to the other Salesforce Org
listConnections.add( connection );
insert listConnections;