+ Start a Discussion

Salesforce To Salesforce Connection

Hai To Salesforce,


 I have Configured  Salesforce to Salesforce from My Production to Another Production, i am using Enterprise Edition.

My connection is in Active Status,I want the functionality like, when ever account has inserted then same account should insert in to that Sandbox.I have published and subscribed the Account Object.


 i Have written following  trigger for the Autoforwarding from Prod to sandbox,



Trigger autoforwardAccount on Account(after insert)
String UserName = UserInfo.getName();
String orgName = UserInfo.getOrganizationName(); 
List<PartnerNetworkConnection> connMap = new List<PartnerNetworkConnection>(
[select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ConnectionStatus = 'Accepted']
System.debug('Size of connection map: '+connMap.size());
List<PartnerNetworkRecordConnection> prncList = new List<PartnerNetworkRecordConnection>(); 
for(Integer i =0; i< Trigger.size; i++)

Account acc = Trigger.new[i];
String acId = acc.Id;
System.debug('Value of AccountId: '+acId);
for(PartnerNetworkConnection network : connMap) 

String cid = network.Id;
String status = network.ConnectionStatus;
String connName = network.ConnectionName; 
String AccountName = acc.Name;
System.debug('Connectin Details.......Cid:::'+cid+'Status:::'+Status+'ConnName:::'+connName+'AccountName:::'+AccountName);
if(AccountName !=Null)
PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection(); 
newrecord.ConnectionId = cid;
newrecord.LocalRecordId = acId;
newrecord.SendClosedTasks = true;
newrecord.SendOpenTasks = true;
newrecord.SendEmails = true;
System.debug('Inserting New Record'+newrecord);
insert newrecord;


But when i am inserting New Record in Prod i am getting Following Exception,


Apex trigger autoforwardAccount caused an unexpected exception, contact your administrator: autoforwardAccount: execution of AfterInsert caused by: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_PARTNER_NETWORK_STATUS, invalid status for partner network operation: []: Trigger.autoforwardAccount: line 65, column 1

Error: Invalid Data. 
Review all error messages below to correct your data.


But My connection is Active status.


Please Help Me!


Haribabu Amudalapalli