function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

INVALID_PARTNER_NETWORK_STATUS though connection has "accepted" status - possible bug?

 I'm getting the same error both in the test class and while inserting a record from the user interface:


System.DmlException: Insert failed. First exception on row 0; first error: INVALID_PARTNER_NETWORK_STATUS, invalid status for partner network operation


The trigger is to forward custom object SSV to a connection on insert. The connection is found on related object. It has "aceepted" status and the SSV is published and subscribed. The test class queries the data base for an accepted connection so it cannot have other status. I also checked the status in the date base, querying by the connectionId and it is for sure accepted.


What's more interested the behaviour had been already tested and the error didn't occur before.


The trigger is:


    List<String> SSV_ID = new LIst<String>();
    List<SSV__c> visits = new List<SSV__c>();

    for (SSV__c ssv:   {
    visits = [select id, Case__r.Network__c, case__r.Network__r.Organizer__c, case__r.Network__r.Member__c,
            Landmark__c, case__r.Network__r.Organizer__r.BAW__c, case__r.Network__r.Organizer__r.AAW__c,
            Visit_Start__c, Visit_End__c from SSV__C where id in: SSV_ID];
    system.debug('ssv, i.e. visits: ' + visits.size());
    if (trigger.isInsert) {
        List<String> accid = new List<String>(); //related accounts id
        Map<String, String> SSVAccount = new Map<String, String>();
        Map<String, String> AccountSSV = new Map<String, String>();
        List<VSV__c> RelatedVSV = new List<VSV__c>();

        //RelatedVSV = [select id, SSV__c from VSV__c where SSV__c in: SSV_ID for update];
        system.debug('Organizer ' + visits[0].case__r.Network__r.Organizer__c);
        for (SSV__c v: visits) {
            SSVAccount.put(, v.case__r.Network__r.Organizer__c);
        List<PartnerNetworkConnection> connections = new List<PartnerNetworkConnection>();
        connections = [select Id, ConnectionStatus, AccountId, ConnectionName from PartnerNetworkConnection
        where AccountId in: accid];
        if (connections.size()<1) {
            for (SSV__c ssv:   {
                ssv.adderror('No S2S connection found to the related Organizer. Please, establish connection, publish necessary data and try again!');
        } else {
            system.debug('Jestem w else');
            List<PartnerNetworkRecordConnection> forwardedSSV = new List<PartnerNetworkRecordConnection>();
            List<SSV__c> VIS = new List<SSV__c>();
            for(PartnerNetworkConnection network : connections) { //for All partner accounts whose SSVs have been modified
                PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();
                system.debug(' ';
                newrecord.ConnectionId = network.Id;   
                system.debug('partner network status is: ' +network.ConnectionStatus);
                system.debug('parnter connection name ' + network.connectionName);
                for (SSV__c v: {
                    if (network.AccountId == SSVAccount.get( {
                        if (network.connectionStatus!='Accepted') {
                            v.adderror('No accepted connection found to the related Organizer. Please, establish connection, publish necessary data and try again');
                        } else {
                            VIS.add(v); // only SSV under current AccountId
                for (SSV__c v1 : VIS) {
                    newrecord.LocalRecordId =;
                    newrecord.SendEmails = true;
                    //newrecord.RelatedRecords = 'VSV__c';
            try {          
                insert forwardedSSV;
            } catch (exception e) {
                for (SSV__c s: {
                    //s.adderror('The record(s) cannot be saved! Please check that the SSV is published to the related account and subscribed by it.');
                    system.debug('Im the error: ' +e);
                    system.debug('forwardedSSV[0].ConnectionId: ' +forwardedSSV[0].ConnectionId);




 ------------The test method is:--------------


 static testMethod void test_ssvCreate() {
        Account a = new Account(Name = 'Test');
        Account org2 = new Account(Name = 'ABC', BAW__c =120, AAW__c=60 );
        List<PartnerNetworkConnection> connections = [select id, AccountId, ConnectionStatus
            from PartnerNetworkConnection where  (connectionStatus='Accepted' and AccountId!=null)];

        system.debug('connection ' + connections.size());
        if (connections.size()>0) {
            Account organizer = [select id, name from Account where id = :connections[0].AccountId];
            system.debug('organizer name ' +;
            if (organizer!=null) {
                Account member = new Account(
                    Name = 'member1');
                insert member;
                Network__c n = new Network__c(
                    Organizer__c =,
                    Member__c =;
                insert n;
                system.debug('Organizer on the network ' + n.Organizer__c);
                Case c = new Case(
                    Status ='New',
                    Origin = 'Phone',
                    Network_ID__c =,
                    Ext_Contact_ID__c = '123c',
                    Ext_Account_ID__c = '456a');
                insert c;
                Case testc = [select id, Network__c, Network__r.Organizer__c from case where id= :];
                system.debug('case id ' +;
                system.debug('Network on the case ' + c.Network__c);
                system.debug('Organizer on the case ' + testc.Network__r.Organizer__c);
                Landmark__c l = new Landmark__c(
                    Name = 'test',
                    countrycode__c = 'pl',
                    DisplayName__c = 'displaytest',
                    Account__c =;
                insert l;
                SSV__c s1 = new SSV__c(
                    Visit_Start__c =,
                    Visit_End__c =,
                    Case__c =,
                    Landmark__c =
                insert s1;




 --------- The test result is: ------------------------



20090921204715.339:Trigger.SSV_share: line 58, column 17: 04P800000009ZtCEAU
20090921204715.339:Trigger.SSV_share: line 63, column 17: partner network status is: Accepted
20090921204715.339:Trigger.SSV_share: line 64, column 17: parnter connection name ABC Manufacturing Corporation
20090921204715.339:Trigger.SSV_share: line 66, column 17: SelectLoop:LIST:SOBJECT:SSV__c
20090921204715.339:Trigger.SSV_share: line 77, column 17: SelectLoop:LIST:SOBJECT:SSV__c
20090921204715.339:Trigger.SSV_share: line 86, column 17: Insert: LIST:SOBJECT:PartnerNetworkRecordConnection
20090921204715.339:Trigger.SSV_share: line 86, column 17: DML Operation executed in 38 ms
20090921204715.339:Trigger.SSV_share: line 88, column 14: SelectLoop:LIST:SOBJECT:SSV__c
20090921204715.339:Trigger.SSV_share: line 90, column 18: Im the error: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_PARTNER_NETWORK_STATUS, invalid status for partner network operation
20090921204715.339:Trigger.SSV_share: line 91, column 18: forwardedSSV[0].ConnectionId: 04P800000009ZtCEAU



I too got the same error 

Did you find any solution for that?

If so,Please help  me.


Chirag MehtaChirag Mehta

I'm also getting the same error, Where you able to find any solution?


Any body who has been able to solve this problem


You might check to see if a valid template is attached to your connection.  See error description:




     The specified partner network status is invalid for the specified template field. 


Or possibly the record you are attempting to share is not being accepted by the target org,