0

I'm writing an apex code where there are 2 methods and the first method will call the 2nd by passing sObject as a parameter. and below is my code.

public with sharing class MyFirstClass {

    public static void getItems(){
        List<String> getColumnNames = getColumnNames('TestAssistContact__c');
        System.debug(getColumnNames);
    }

    public static List<String> getColumnNames(sObject obj){
        List<String> x = new List<String>();
        x.add('Hi');
        return x;
    }
}

when I run this. I want to print the contents of the list that's returned. But here I get the error as below.

Method does not exist or incorrect signature: void getColumnNames(String) from the type TestAssistClass

please let me know on where am I going wrong and how can I fix it.

1 Answer 1

1

you are passing String to method. Because 'TestAssistContact__c' is String. I didn't understand what do you want to achieve with that method, but you can pass SObjectType.

public with sharing class MyFirstClass {

    public static void getItems(){
        List<String> getColumnNames = getColumnNames(TestAssistContact__c.SObjectType);
        System.debug(getColumnNames);
    }

    public static List<String> getColumnNames(SObjectType type){
        List<String> x = new List<String>();
        x.add('Hi');
        return x;
    }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .