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
Timothy SmithTimothy Smith 

Illegal Assignment Errors

I am receiving some Illegal Assignment Errors.  Big question is why on the Phone number fields 'Data Type Phone Number' am I receiving the Illegal Assignment error from Integer to String?  My code is below, thank you in advance.
 
@isTest
private class ContactDNCOpportunityTest {
       
    private static testMethod void testCloseOpps(){
        //Create Account
        
        Account newAcc = FlowTestUtils.createHouseholdAccount();
    		insert newAcc;  
        
        
       //Create Contacts
           List<Contact> conList = new List<Contact> {
		new Contact(FirstName='test1',LastName='tester',AccountId = newAcc.Id, Email = 'test1@testing.com', Phone = 1234567891, Phone_Status__c = 'Do Not Call'),  //Has Phone Number - Do not call, Closed Opp
        new Contact(FirstName='test2',LastName='tester',AccountId = newAcc.Id, Email = 'test2@testing.com'), //Blank No Numbers  Closed Opp
        new Contact(FirstName='test3',LastName='tester',AccountId = newAcc.Id, Email = 'test3@testing.com', Normalized_Work_Phone__c = 1234567891,Work_Phone_Status__c = 'Active'), // Has Work Number, Active, Do Not Close Opp
		new Contact(FirstName='test4',LastName='tester',AccountId = newAcc.Id, Email = 'test4@testing.com', Phone = 1234567891, Phone_Status__c = 'Active'), //Has Phone Number, Active, Do not Close Opp
        new Contact(FirstName='test5',LastName='tester',AccountId = newAcc.Id, Email = 'test5@testing.com', Normalized_Mobile_Phone__c = 1234567891, Mobile_Phone_Status__c = 'Do Not Call'), //Has mobile number, DNC, Close Opp      
        new Contact(FirstName='test6',LastName='tester',AccountId = newAcc.Id, Email = 'test6@testing.com', Normalized_Work_Phone__c = 1234567891, Work_Phone_Status__c = 'Do Not Call') //Has Worknumber DNC is checked
            };	
                
            insert conList;
       
        
        
        Test.startTest();
            Opportunity opptest1 = new Opportunity(Name = 'Opp1', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test1']);
            insert opptest1;
        Test.stopTest();   
        
        
        System.assertEquals('Closed', opptest1.StageName);
                
            
        Test.startTest();
     		Opportunity opptest2 = new Opportunity(Name = 'Opp2', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test2']);
            insert opptest2;
        Test.stopTest();   
        
        System.assertEquals('Closed', opptest2.StageName);
            
         Test.startTest();
     		Opportunity opptest3 = new Opportunity(Name = 'Opp3', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test3']);
            insert opptest3;
         Test.stopTest();   
        
        System.assertEquals('Closed', opptest3.StageName);
            
         Test.startTest();
      		Opportunity opptest4 = new Opportunity(Name = 'Opp4', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test4']);
            insert opptest4;
         Test.stopTest();   
        
        System.assertNotEquals('Closed', opptest4.StageName);
            
         Test.startTest();
      		Opportunity opptest5 = new Opportunity(Name = 'Opp5', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test5']);
            insert opptest5;
         Test.stopTest();   
        
        System.assertEquals('Closed', opptest5.StageName);
            
         Test.startTest();
      		Opportunity opptest6 = new Opportunity(Name = 'Opp6', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test6']);
            insert opptest6;
         Test.stopTest();   
        
        System.assertEquals('Closed', opptest6.StageName);
            
                                                   
         Test.startTest();
  			Opportunity opptest7 = new Opportunity(Name = 'Opp7', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today());    
            insert opptest7;
         Test.stopTest();   
        
        System.assertEquals('Closed', opptest7.StageName);
        };

             
    }

My Errors:
User-added image
CharuDuttCharuDutt
Hi Timothy
The Error Is Coming Becaue Of The Phone Field Is Type Of String And Your Entering In Integer Format And Not String Format
Correction  Phone = '0123456789'
Cause Sometime You Want The Phone mber In Paticular Format Like '+00 123456789'  OR '(785) 241-6200' Can Only Done In String Type

Please Mark It As best Answer If It Helps
Thank You!
Timothy SmithTimothy Smith
Thank you, the phone numbers are good now.  I just can't understand why I'm getting the List to Id error.  I'm wondering if there is antoher format/syntax for me to access that field.
 
CharuDuttCharuDutt
Hii Timothy
Try Below Code
Changes Are In Bold
@isTest
private class ContactDNCOpportunityTest {
       
    private static testMethod void testCloseOpps(){
        //Create Account
        
        Account newAcc = FlowTestUtils.createHouseholdAccount();
            insert newAcc;  
        
        
       //Create Contacts
           List<Contact> conList = new List<Contact> {
        new Contact(FirstName='test1',LastName='tester',AccountId = newAcc.Id, Email = 'test1@testing.com', Phone = '1234567891', Phone_Status__c = 'Do Not Call'),  //Has Phone Number - Do not call, Closed Opp
        new Contact(FirstName='test2',LastName='tester',AccountId = newAcc.Id, Email = 'test2@testing.com'), //Blank No Numbers  Closed Opp
        new Contact(FirstName='test3',LastName='tester',AccountId = newAcc.Id, Email = 'test3@testing.com', Normalized_Work_Phone__c = '1234567891',Work_Phone_Status__c = 'Active'), // Has Work Number, Active, Do Not Close Opp
        new Contact(FirstName='test4',LastName='tester',AccountId = newAcc.Id, Email = 'test4@testing.com', Phone = 1234567891, Phone_Status__c = 'Active'), //Has Phone Number, Active, Do not Close Opp
        new Contact(FirstName='test5',LastName='tester',AccountId = newAcc.Id, Email = 'test5@testing.com', Normalized_Mobile_Phone__c = '1234567891', Mobile_Phone_Status__c = 'Do Not Call'), //Has mobile number, DNC, Close Opp      
        new Contact(FirstName='test6',LastName='tester',AccountId = newAcc.Id, Email = 'test6@testing.com', Normalized_Work_Phone__c = '1234567891', Work_Phone_Status__c = 'Do Not Call') //Has Worknumber DNC is checked
            };    
                
            insert conList;
       
        
        
      Test.startTest();
            Opportunity opptest1 = new Opportunity(Name = 'Opp1', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test1'].Id);
            insert opptest1;
        Test.stopTest();   
        
        
        System.assertEquals('Closed', opptest1.StageName);
                
            
        Test.startTest();
             Opportunity opptest2 = new Opportunity(Name = 'Opp2', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test2'].Id);
            insert opptest2;
        Test.stopTest();   
        
        System.assertEquals('Closed', opptest2.StageName);
            
         Test.startTest();
             Opportunity opptest3 = new Opportunity(Name = 'Opp3', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Primary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test3'].Id);
            insert opptest3;
         Test.stopTest();   
        
        System.assertEquals('Closed', opptest3.StageName);
            
         Test.startTest();
              Opportunity opptest4 = new Opportunity(Name = 'Opp4', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test4'].Id);
            insert opptest4;
         Test.stopTest();   
        
        System.assertNotEquals('Closed', opptest4.StageName);
            
         Test.startTest();
              Opportunity opptest5 = new Opportunity(Name = 'Opp5', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test5'].Id);
            insert opptest5;
         Test.stopTest();   
        
        System.assertEquals('Closed', opptest5.StageName);
            
         Test.startTest();
              Opportunity opptest6 = new Opportunity(Name = 'Opp6', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today(), Secondary_Contact__c = [SELECT Id FROM Contact WHERE FirstName = 'test6'].Id);
            insert opptest6;
         Test.stopTest();   
        
        System.assertEquals('Closed', opptest6.StageName);
            
                                                   
         Test.startTest();
              Opportunity opptest7 = new Opportunity(Name = 'Opp7', AccountId = newACC.id, StageName = 'Ready to Call/Schedule', CloseDate = Date.today());    
            insert opptest7;
         Test.stopTest();   
        
        System.assertEquals('Closed', opptest7.StageName);
        }
    }
Please Like If It Helps
Thank You!

 
CharuDuttCharuDutt
Hi Timothy 
Please Close Your Query By Marking It As Best Answer 
So It Helps Others In Future
Thank You!