4

So I want to create handler classes for different Objects with my SF org, specifically for some of the custom objects. For instance I have a Global__c object that stores global settings in encrypted text fields for things like credentials to 3rd party logins.

My hope is to have a reusable way of fetching data as needed. I am new to SF so any education about this request would be helpful, even if that includes saying this is a dumb request :P

So far I have this:

public virtual class Global_Settings {

    public static Global__C g;

    /**
     * CONSTRUCTOR
     */
    public Global_Settings(){
        this(g);
    }

    /**
     * GET A GLOBAL BY NAME
     * Fetch Global__c by Name field
     * @example Globals.get(<Name>)
     * @author  Nick Worth
     */
    public get( String name ){
        Global_Settings.g = [SELECT Id, Name, Value__c FROM Global__c WHERE Name = :name];
        return g;
    }

}

At the moment I'm getting this error when attempting to deploy to sandbox:

1. classes/Globals.cls -- Error: Invalid constructor name: get (line 30)

Apparently its not recognizing my constructor even though it is clearly there. I thought maybe it wasn't allowed to be empty so I added this(g) but still no progress.

Potentially this class and others like it would have utility like methods in here specific to the object. So in addition to my constructor issue I'm curious about this approach, potential problems, benefits, etc.

Thank you.

1 Answer 1

3

Your method is missing the return type and so it is being interpreted as a constructor named get as opposed to a method on the class named get. Add the return type of Global__c and it should compile just fine.

public Global__c get( String name ){
    Global_Settings.g = [SELECT Id, Name, Value__c FROM Global__c WHERE Name = :name];
    return g;
}
1
  • Ah! Thanks for the quick response, that worked great. In addition is this concept a good practice in SF? Or is there some potential roadblocks or issues I may be running into? Commented Oct 10, 2014 at 20:25

You must log in to answer this question.

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