+ Start a Discussion
aklkkaklkk 

please give ma solution because i am not able to cover the test class code

hi all , i am not able to write to cover code palease suppot me 
trigger soluation on gole__c(before insert,before update){
    set<string> SetAgentIds = new Set<string>();
    Map<string,string> MapSalesAgentsWithNpn = new Map<string,String>();
    for(gole__c sales:trigger.new){
            if(sales.Writing_Agent_ID__c!=null){
                SetAgentIds.add(sales.Writing_Agent_ID__c);
            }
    }
    if(SetAgentIds.size()>0){
        for(Agent__c SalsAgent:[select id,AWN__c,NPN__c  from Agent__c where AWN__c IN:SetAgentIds]){
                MapSalesAgentsWithNpn.put(SalsAgent.AWN__c,SalsAgent.NPN__c);
        
        }
    }
    
    for(gole__c sales:trigger.new){
      if(MapSalesAgentsWithNpn.containsKey(sales.Writing_Agent_ID__c)){
                  sales.Writing_Agent_NPN__c=MapSalesAgentsWithNpn.get(sales.Writing_Agent_ID__c);
      }
    }
    
 
}
Shubham NandwanaShubham Nandwana
Hi aklkk,
For a trigger, minimum 1% code coverage is required which can be attained easily by writing a simple test case.
Please check the below code, it will be useful:
@isTest
private class TestTrigger {
  @isTest static void TestGoleTrigger() {
  //First insert record for your Writing Agent(assuming it is an object) and get its record id.
  WritingAgent__c wa=new WritingAgent();
  wa.Name='ABC';
  Database.SaveResult saveStatus = Database.insert(wa, false);
  Id writingAgentId = saveStatus.getId();

 //Now create a object of gole and add Writing_Agent_ID__c as above field
  gole__c gole=new gole__c();
  gole.Name='ABC';
  gole.Writing_Agent_ID__c=writingAgentId;

  insert gole;
  }
    
}
Above I filled only name fields, you can fill your fields accordingly.
You can also refer to https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_triggers .
Hope my answer helps, select it as a best answer if it does. 

Shubham Nandwana.
AppPerfect Corp.
salesforce@appperfect.com
408-252-4100
http://www.appperfect.com/services/salesforce/
Salesforce Development & Operations Experts