+ Start a Discussion
Mayank_JoshiMayank_Joshi 

How to bulk upsert records via s2s ?

Below Trigger is working fine for single record update and insert . But for Bulk data upload ,it is giving Too many DML statements: 151at Line upsert newrecord; . 

 

Trigger trg_S2S_Account_Automation on Account(after insert,after update)
{
  List<PartnerNetworkConnection> connMap = new List<PartnerNetworkConnection>([select Id, ConnectionStatus,               ConnectionName from PartnerNetworkConnection where ConnectionStatus = 'Accepted']);
 for(Integer i =0; i< Trigger.size; i++)
  {
   Account acc = Trigger.new[i];
   String acId = acc.Id;
   for(PartnerNetworkConnection network : connMap)
  {
   String cid = network.Id;
   String status = network.ConnectionStatus;
   String connName = network.ConnectionName;
   String AccountName = acc.Name;
   Boolean Synch1 =acc.Allow_Sych__c;
   System.debug('SynchType:::'+Synch1);
   if(Synch1==True )
     {
      PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();
      newrecord.ConnectionId = cid;
      newrecord.LocalRecordId = acId;
      upsert newrecord;
   }
}

}

}

 

To resolve ,it I am trying to create a List collection type for PartnerNetworkRecordConnection and below is the trigger and it compiles succesfully . But Trigger is not working to send records via S2S connection .Below is the trigger : 

 

Trigger trg_S2S_Account_Automation on Account(after insert,after update)
{

 List<PartnerNetworkConnection> connMap = new List<PartnerNetworkConnection>([select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ConnectionStatus = 'Accepted']);
List<PartnerNetworkRecordConnection> newrecord = new List<PartnerNetworkRecordConnection> ( );
for(Integer i =0; i< Trigger.size; i++)
{
Account acc = Trigger.new[i];
String acId = acc.Id;
for(PartnerNetworkConnection network : connMap)
{
String cid = network.Id;
String status = network.ConnectionStatus;
String connName = network.ConnectionName;
String AccountName = acc.Name;
Boolean Synch1 =acc.Allow_Sych__c;
System.debug('SynchType:::'+Synch1);
if(Synch1==True )
{
//PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();
for(PartnerNetworkRecordConnection networkRecord : newrecord){
networkRecord.ConnectionId = cid;
networkRecord.LocalRecordId = acId;
upsert networkRecord;
}
}
}
}

 

Do let me know , on where I am missing . I would like to know ,How to upsert records via s2s using List<PartnerNetworkRecordConnection> as I am need to bulk upsert records via s2s .

 

Thanks in advance .