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 😛
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.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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; }
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0