• RAHUL MISHRA 86
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 2
    Replies
I have seen post for this error but no solution, so I am posting again in hopes of getting an answer. I am trying to send a record to a Salesforce to Salesforce connection if it meets certain parameters. However, received the error posted in the subject line. Below is the code that I am trying to execute:

trigger SimpleCaseTrigger on Case (after update) {
    // Define connection id 
    Id networkId = ConnectionHelper.getConnectionId('Connection Name'); 
    List <Case> sendToConn = New List<Case>();
    List<PartnerNetworkRecordConnection> prncList = new List<PartnerNetworkRecordConnection>();
    for (Case c : Trigger.New){
        //Test to that the case has been successfully closed and has not been sent to Connection Before
        if (c.ConnectionReceivedId == null && c.ConnectionSentID == null && c.Status == 'Successfully Closed'){
            sendToConn.add(c);
            System.debug('Case #'+ c.CaseNumber + ' added.');
        }
    }
    
    //Create Connection to send to Connection
    for (Case newCases : sendToConn){
        PartnerNetworkRecordConnection newConnection =
                    new PartnerNetworkRecordConnection(
                        ConnectionId = networkId,
                        LocalRecordId = newCases.Id,
                        SendClosedTasks = false,
                        SendOpenTasks = false,
                        SendEmails = false,
                        ParentRecordId = newCases.AccountId);
        prncList.add(newConnection);
    }
    database.insert(prncList);
    
}
 
Error: 
Apex trigger partnersync caused an unexpected exception, contact your administrator: partnersync: 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.partnersync: line 19, column 1

Code:
trigger partnersync on Partner__c (after insert,after Update) {
    Id networkId = ConnectionHelper.getConnectionId('Academy of Financial Trading 2nd Org');
    List<PartnerNetworkRecordConnection> partnerConnections =  new  List<PartnerNetworkRecordConnection>();
    
    for (Partner__c pl : trigger.new) {
        
        PartnerNetworkRecordConnection newConnection = new PartnerNetworkRecordConnection(
            
            ConnectionId = networkId,
            LocalRecordId = pl.Id,
            SendClosedTasks = false,
            SendOpenTasks = false,
            SendEmails = false,
            ParentRecordId = pl.Id);
        partnerConnections.add(newConnection);
    }
    if (partnerConnections.size() > 0 ) {
        database.insert(partnerConnections);
        
    }
    
}