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
Harsha ShriHarsha Shri 

Help in test class for updating field method

Hi All,
I need help in test class.
I have written a method for external object that sync all fields when ever I add custom fields into it. I am sharing my code please help me to write a test class for this method
global class dataSourceCon extends datasource.connection{
override global List<DataSource.Table> method1() 
    {
        
        List<DataSource.Table> extObj = new List<DataSource.Table>();

        for(ext_obj1__c Obj : 
            [SELECT Id, Name, Description__c, Name_Col__c, Label_Plu__c, Label_Sin__c, 
                (SELECT Id, Name, External_Ta__c, Data_Type__c, Decimal_Places__c, Desc__c,
                    Field_Label__c, Filtera__c, Len__c, ReferenceTarFld__c, RefTo__c, Sort__c
                    FROM External_Col__r
                )
              FROM ext_obj1__c LIMIT 50
            ])
        {
            
            List<DataSource.Column> colu_Obj = new List<DataSource.Column>();
            
            // Standard fields
            colu_Obj.add(DataSource.Column.url('DisplayUrl'));
            colu_Obj.add(DataSource.Column.text('ExternalId',255));
            
            //Custom fields 
            for(Exter_Field__c cusField : Obj.External_Col__r)
            {
                
                colu_Obj.add(setupCustomFieldData(cusField));
            }

            // Table Data
            extObj.add(setupTableData(Obj, colu_Obj));  
        }

        return extObj;
    }   
}
Please help me in writing test class for this. I am new to test class and I am struggling 

Thank in Advance

 
Best Answer chosen by Harsha Shri
Gokula KrishnanGokula Krishnan
Hi Harsha,

Try this,
@isTest(SeeAllData = True)
public class dataSourceConTest {
    @isTest
    static void testMeth(){
        Test.StartTest();
        	dataSourceCon dc = new dataSourceCon();
         	dc.method1();
        Test.stopTest();
    }
	
}
Regards,
Gokula Krishnan

If it helps you, please mark is as best answer, so it will be helpful for other developers.

All Answers

Gokula KrishnanGokula Krishnan
Hi Harsha,

Try this,
@isTest(SeeAllData = True)
public class dataSourceConTest {
    @isTest
    static void testMeth(){
        Test.StartTest();
        	dataSourceCon dc = new dataSourceCon();
         	dc.method1();
        Test.stopTest();
    }
	
}
Regards,
Gokula Krishnan

If it helps you, please mark is as best answer, so it will be helpful for other developers.
This was selected as the best answer
Amit Singh 1Amit Singh 1
Hi Harsh,

You need to create Test Data into Test class you can not use SeeAllData to true . Do insert the test data into the test class and then Call you class method using the above code.