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
RajnisfRajnisf 

need a help for test class

trigger tocallout on Opportunity (after insert, after update) {
    Set<id> accountids = new Set<id>();
    
  for (Opportunity op : Trigger.new) {
  accountIds.add(op.AccountId);    
  }
  
  Map<Id, Account> accountMap = new Map<Id, Account>([SELECT ia_crm__IntacctID__c FROM Account WHERE Id IN :accountIds]);
    String sName;

    for (Opportunity op : Trigger.new){
    if(op.Account.ia_crm__IntacctID__c != null){
    sName = accountMap.get(op.AccountId).ia_crm__IntacctID__c;
}
    if (op.stagename == 'Contract Signed' && sName  != null && (op.CC__c != null || op.Routing_Number__c != null)) {
           if (OpportunityTriggerHandlerclass.ShowRun == true) {
            OpportunityTriggerHandlerclasshandler = new  OpportunityTriggerHandlerclass(); 
        handler.sendCardToTP(op);
      }
    }
  }
}

pls help for the test class...not able to cover..

sName = accountMap.get(op.AccountId).ia_crm__IntacctID__c;

{ if (OpportunityTriggerHandlerclass.ShowRun == true) { OpportunityTriggerHandlerclasshandler = new OpportunityTriggerHandlerclass(); handler.sendCardToTP(op); }

 
Best Answer chosen by Rajnisf
Devanshu soodDevanshu sood
@isTest
private class CalloutClassTest {


 @isTest static void testCalloutPaymentr() {
      
       Account acc = new Account(name = 'test', ia_crm__Sync_With_Intacct__c = false ,Phone = '33333344444', 
 billingstreet = '4th avenue', billingcity = 'tampa',billingstate = 'FL',ia_crm_Intacctid='1232,'  billingcountry = 'United States', BillingPostalCode = '11001', Description = 'javascript :: null');
 insert acc;

      Opportunity opp = new Opportunity(
      Accountid = acc.id,
      Name = 'Prasadam',       
     CloseDate = Date.parse('06/06/2021'),                
      StageName = 'Contract Signed',                       
      Success__c = 'false',                      
      Routing_Number__c = '123',
      CC__c = '5446886522351236' );
      insert opp;
            
          
          
          Test.startTest();
          acc.ia_crm__Sync_With_Intacct__c = true;
          
          
          update acc; 
          Test.stopTest();   
    }

      @isTest static void testCalloutPayment() {
      
       Account acc = new Account(name = 'test', ia_crm__Sync_With_Intacct__c = false ,Phone = '33333344444', ,ia_crm_Intacctid='1232',
 billingstreet = '4th avenue', billingcity = 'tampa',billingstate = 'FL',  billingcountry = 'United States', BillingPostalCode = '11001', Description = 'javascript :: null');
 insert acc;

      Opportunity opp = new Opportunity(
      Accountid = acc.id,
      Name = 'Prasadam',       
     CloseDate = Date.parse('06/06/2021'),                
      StageName = 'Contract Signed',                       
   Success__c = 'false',                      
      Routing_Number__c = '123',
      CC__c = '5446886522351236' );
      insert opp;
          Test.startTest();
          
          opp.Success__c = 'true';  
          
          update opp; 
          Test.stopTest();     
             
    }

try the following code

All Answers

Devanshu soodDevanshu sood
In order to cover this line, you will need to satisfy the if condition on line 12.
Insert a new Account and Opportunity and relate them by giving Account Id in the opportunity field "AccountId". Also, insert the field value of "ia_crm__IntacctID__c" so that it satisfies the If condition.
Hope it helps you.
edelrabeedelrabe

To cover lines 12-14 you have to set Account.ia_crm__IntacctID__c field before you create an opportunity.
Move the line 

acc.ia_crm__IntacctID__c ='C1123';
to the top of test method, where you're creating the account.
Devanshu soodDevanshu sood
@isTest
private class CalloutClassTest {


 @isTest static void testCalloutPaymentr() {
      
       Account acc = new Account(name = 'test', ia_crm__Sync_With_Intacct__c = false ,Phone = '33333344444', 
 billingstreet = '4th avenue', billingcity = 'tampa',billingstate = 'FL',ia_crm_Intacctid='1232,'  billingcountry = 'United States', BillingPostalCode = '11001', Description = 'javascript :: null');
 insert acc;

      Opportunity opp = new Opportunity(
      Accountid = acc.id,
      Name = 'Prasadam',       
     CloseDate = Date.parse('06/06/2021'),                
      StageName = 'Contract Signed',                       
      Success__c = 'false',                      
      Routing_Number__c = '123',
      CC__c = '5446886522351236' );
      insert opp;
            
          
          
          Test.startTest();
          acc.ia_crm__Sync_With_Intacct__c = true;
          
          
          update acc; 
          Test.stopTest();   
    }

      @isTest static void testCalloutPayment() {
      
       Account acc = new Account(name = 'test', ia_crm__Sync_With_Intacct__c = false ,Phone = '33333344444', ,ia_crm_Intacctid='1232',
 billingstreet = '4th avenue', billingcity = 'tampa',billingstate = 'FL',  billingcountry = 'United States', BillingPostalCode = '11001', Description = 'javascript :: null');
 insert acc;

      Opportunity opp = new Opportunity(
      Accountid = acc.id,
      Name = 'Prasadam',       
     CloseDate = Date.parse('06/06/2021'),                
      StageName = 'Contract Signed',                       
   Success__c = 'false',                      
      Routing_Number__c = '123',
      CC__c = '5446886522351236' );
      insert opp;
          Test.startTest();
          
          opp.Success__c = 'true';  
          
          update opp; 
          Test.stopTest();     
             
    }

try the following code
This was selected as the best answer
RajnisfRajnisf
The flow is when the stagename is contract signed,
field on Account  ia_crm__Sync_With_Intacct__c  = true  (was false)
then this field ia_crm_Intacctid will get updated with the value.
 
RajnisfRajnisf
not able to cover them yet...
Devanshu soodDevanshu sood
then try to insert value in  op.Account.ia_crm_Intacctid.
 
Devanshu soodDevanshu sood
try to debug sName and check if there is any value.
 
Devanshu soodDevanshu sood
are you able to cover line 13 
 
sflearningsflearning
no.. value of  op.Account.ia_crm_Intacctid is null
sflearningsflearning
code not covered
edelrabeedelrabe
Please post your trigger and test class with appropriate formatting
sflearningsflearning
Thanks a lot!! Actually there was a flow on opportunity stage ... where other mandatory fields were not covered in the test class...