• Przemek
  • NEWBIE
  • 0 Points
  • Member since 2009

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies

 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: trigger.new)   {
        SSV_ID.add(ssv.id);
    }
   
    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) {
            accid.add(v.case__r.Network__r.Organizer__c);
            SSVAccount.put(v.id, v.case__r.Network__r.Organizer__c);
            AccountSSV.put(v.case__r.Network__r.Organizer__c, v.id);
        }
    
   
        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: trigger.new)   {
                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('network.id: ' +network.id);
               
               
                newrecord.ConnectionId = network.Id;   
               
                system.debug('partner network status is: ' +network.ConnectionStatus);
                system.debug('parnter connection name ' + network.connectionName);
              
                for (SSV__c v: trigger.new) {
                    if (network.AccountId == SSVAccount.get(v.id)) {
                        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 = v1.id;
                    newrecord.SendEmails = true;
                    //newrecord.RelatedRecords = 'VSV__c';
                    forwardedSSV.add(newrecord);
                }
            }
                   
            try {          
                insert forwardedSSV;
            } catch (exception e) {
                for (SSV__c s: trigger.new) {
                    //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 );
        
        //Test.startTest();
        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 ' + organizer.name);
            
            if (organizer!=null) {
                
            
                Account member = new Account(
                    Name = 'member1');
                
                insert member;
                
                
                Network__c n = new Network__c(
                    Organizer__c = organizer.id,
                    Member__c = member.id);
                    
                insert n;
                
                system.debug('Organizer on the network ' + n.Organizer__c);
                
                Case c = new Case(
                    Status ='New',
                    Origin = 'Phone',
                    Network_ID__c = n.id,
                    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= : c.id];
                
                system.debug('case id ' + c.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 = Member.id);
                
                insert l;
                
                SSV__c s1 = new SSV__c(
                    Visit_Start__c = datetime.now(),
                    Visit_End__c = datetime.now(),
                    Case__c = c.id,
                    Landmark__c = l.id
                    );
                
                insert s1;
               

 

 

 

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

 

 

20090921204715.339:Trigger.SSV_share: line 58, column 17: network.id: 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

  • September 21, 2009
  • Like
  • 0