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
Jan RevetJan Revet 

Not of type Custom Settings

I have a custom object namend tpdDatabase. I have an Apex class with the method below to get an instance of this object (by databasename). 

The line "tpdDatabase__c tpDatabase = tpdDatabase__c.getValues(databaseName);" produces this error:

Not of type Custom Settings

I don't quite understand what goed wrong here. Could anyone point me in the right direction? Many thanks in advance!

    public tpdDatabase__c getByDatabaseName(String databaseName) {
        
        tpdDatabase__c tpDatabase = tpdDatabase__c.getValues(databaseName);
        if (tpDatabase == null) {
        return null;
        }
        return tpDatabase; 
    }
mirkimirki
Hi,

getValues cannot be used for custom objects. Try to get the correct record with SOQL like this.

SELECT Id, Name FROM tpdDatabase__c WHERE Name = databaseName

Regards,
mirki
Jan RevetJan Revet
Thanks Mirki!
NimitNimit
Hi Jan,

getValues will not work with custom objects. It will work with Custom settings only..

To fetch record from custom object you need to use SOQL.

Select Id from tpdDatabase__c WHERE Name =: databaseName

Regards,
Nimit
Jan RevetJan Revet
Thanks Nimit!