+ Start a Discussion

Test Class :getting error : System.StringException: Invalid id: 11110 please help me to resolve



trigger getmanager on Opp__c ( before update){
Set<Id> id= new Set<Id>();
Set<String> empid=new Set<String>();
Set<String> mngid=new Set<String>();
List<Opp__c> OppyLocation = new List<Opp__c>();

for (Opp__c opp:trigger.old){
  id.add(trigger.newmap.get(opp.id).Current_Year_Rep__c );
for (HR__c empnum: [select Employee_Number__c from HR__c where  id  in :id ]){
 for (Contact con: [select Employee_Id__c,Reports_To_Employee_Id__c from contact where Employee_Id__c in:empid]){
    mngid.add(con.Reports_To_Employee_Id__c );
 for (HR__c empnu: [select Employee_Number__c,Name from HR__c where Employee_Number__c in: mngid]){

      for (Opp__c opp:trigger.new){
     system.debug('emp:'+ empnu.id );
     system.debug('emp:'+ empnu.Name );



Test class:

Public Class  getmanagerTest {
public static testmethod void test() {
List<Contact> con= new List<Contact>();  
  con .add(new contact(lastname='te1',Employee_Id__c='11110',Reports_To_Employee_Id__c='11111'));      
  con .add(new contact(lastname='te2',Employee_Id__c='11111',Reports_To_Employee_Id__c='11112'));      
 List <HR__c> rec=new List<HR__c>();
 rec.add(new HR__c( Name='kalai',Employee_Number__c='11110'));
 rec.add(new HR__c(Name='Raj',Employee_Number__c='11111'));
      Opp__c r = new Opp__c(Name= 'opp1' ,Current_Year_Rep__c='11110');
      insert r;





If the Employee_Id__c is a field of type ID, its value should be a valid ID value (a 18 length String).

You can create a Employee object and set the id to the field Employee_id__c of Contact