+ Start a Discussion
hisalesforcehisalesforce 

test coverage problem for salesforce to salesforce connection


Testclass
public class TestSendOpportunity{ public static testMethod void testBatchClass() { Account myaccount=new Account(name='Account name'); insert myaccount; Account acount=new Account(name='test'); insert acount; Account acc=[Select id from account where name='ABC' limit 1]; RecordType rcc=[SELECT id FROM RecordType where name='Managed Service']; Opportunity opp=new opportunity(name='test1',Accountid=acount.id); opp.distributor__c=acc.id; insert opp; List<PartnerNetworkConnection> connMap=[select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection where ConnectionStatus = 'Accepted' and connectionname='ACA']; List<PartnerNetworkRecordConnection> lstShareRecords= new List<PartnerNetworkRecordConnection>(); for(PartnerNetworkConnection network : connMap) { PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection(); newrecord.ConnectionId = network.Id; newrecord.LocalRecordId = opp.accountid; newrecord.SendClosedTasks =false; newrecord.SendOpenTasks = false; newrecord.SendEmails = false; lstShareRecords.add(newrecord); } insert lstshareRecords; List<Opportunity> lstopp=new List<Opportunity>(); lstopp.add(opp); System.debug('HaHa list of Opportunity'+opp); SendOpportunity sendopp=new SendOpportunity();
public class SendOpportunity
{
List<Id> OpportunitySharingId=new List<ID>();
        public void sendrec(list<Opportunity> Opp)
        {
            Account act=new Account();
            
            act=[Select id from account where name='ACA' limit 1];
           
            List<PartnerNetworkRecordConnection> lstShareRecords = new List<PartnerNetworkRecordConnection>();
            
            List<PartnerNetworkConnection> connMap=[select Id, ConnectionStatus, ConnectionName from PartnerNetworkConnection
                    where ConnectionStatus = 'Accepted' and connectionname='ACA'  ];
     
            List<Opportunity> opportunitysharing=new List<Opportunity>();
           List<PartnerNetworkRecordConnection> allRecordShared=[select Id, Status, ConnectionId, LocalRecordId from PartnerNetworkRecordConnection where status='Sent'
             //This is the reason of my test coverage...
Since opportunity created in test class status ='Pending' so it is pulling coverage low                                            ];
          
           
              for(Opportunity o:Opp)
              {
                  for(PartnerNetworkRecordConnection PNRC:allRecordShared)
                      {
                          if(o.AccountId==PNRC.LocalRecordID)
                              {
                                      opportunitysharing.add(o);
                                      OpportunitySharingId.add(o.id);
                              
                              }
                      }
              
              }   
              
      List<PartnerNetworkRecordConnection> recordConns = new List<PartnerNetworkRecordConnection>([select Id, Status, 
      ConnectionId, LocalRecordId from PartnerNetworkRecordConnection where LocalRecordId in :OpportunitySharingId]);

      
                    for(PartnerNetworkConnection network : connMap) 
                    {    
                        for(Opportunity O:opportunitysharing)
                        {
                        //object declaration for PartnerNetwork
                        PartnerNetworkRecordConnection newrecord = new PartnerNetworkRecordConnection();
                       
                        newrecord.ConnectionId = network.Id;
                        newrecord.LocalRecordId = o.id;  
                        newrecord.ParentRecordId=o.accountid;
                        newrecord.SendClosedTasks =false;
                        newrecord.SendOpenTasks = false;
                        newrecord.SendEmails = false;
                        //All the Records are added to the PartnerNetwork
                        lstShareRecords.add(newrecord);
                        }
                   }
              
            
              insert lstShareRecords;
        }
}

 

sendopp.sendrec(lstopp); }

  List<PartnerNetworkRecordConnection> allRecordShared=[select Id, Status, ConnectionId, LocalRecordId from PartnerNetworkRecordConnection where status='Sent'

From this line:

allRecordshared is empty since Account shared in test class status is pending .

Because somebody has to accept it and since its a test class Noboby will accept.

 

How to make allrecordshared status ='sent'

 

Pleas help me....

alaschgarialaschgari

I'd love to know that, too!