S2S
trigger trgOnBankS2SExample on Bank__c (after Insert) {
List<Contact>lstCon = new List<Contact>();
lstCon =[Select Id from Contact where id='0039000000mi2am'];
List<PartnerNetworkConnection> lstPnC = new List<PartnerNetworkConnection>();
lstPnC = [select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ContactId =:lstCon[0].id and ConnectionStatus='Accepted'];
List<PartnerNetworkRecordConnection> recordConnectionToInsert = new List<PartnerNetworkRecordConnection> ();
for (Bank__C BObj : Trigger.new){
PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();
newrecord.ConnectionId = lstPnC[0].Id;
newrecord.LocalRecordId = BObj .id;
recordConnectionToInsert.add(newrecord);
}
if (recordConnectionToInsert.size() > 0){
System.debug('>>> Sharing ' + recordConnectionToInsert.size() + ' records');
insert recordConnectionToInsert;
}
}
List<Contact>lstCon = new List<Contact>();
lstCon =[Select Id from Contact where id='0039000000mi2am'];
List<PartnerNetworkConnection> lstPnC = new List<PartnerNetworkConnection>();
lstPnC = [select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ContactId =:lstCon[0].id and ConnectionStatus='Accepted'];
List<PartnerNetworkRecordConnection> recordConnectionToInsert = new List<PartnerNetworkRecordConnection> ();
for (Bank__C BObj : Trigger.new){
PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();
newrecord.ConnectionId = lstPnC[0].Id;
newrecord.LocalRecordId = BObj .id;
recordConnectionToInsert.add(newrecord);
}
if (recordConnectionToInsert.size() > 0){
System.debug('>>> Sharing ' + recordConnectionToInsert.size() + ' records');
insert recordConnectionToInsert;
}
}
Comments
Post a Comment