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.

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;
}
  • 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? – Xtremefaith Oct 10 '14 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.