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

Avoiding hardcoded IDs in Apex class for API get


I created an API for an events platform to pull data of attendees. I have a SOQL query which points to the specific event but now realize that hardcoding the event ID is not *best practice*.


global with sharing class eventplatformRestResource {


    global static LIST<Registration__c> doGet(){

    RestRequest req = RestContext.request;

    RestResponse res = RestContext.response;

    LIST<Registration__c> result = [Select Id, EventName__c, FullName__c, RegistrantEmail__c FROM Registration__c WHERE Event2__c = 'a0k4z00000BdNnG'];

               return result;


How would I change the code for the platform to pull the data needed for this upcoming event AND be able to reuse this Apex class so that data for other events can be pulled?

Vishwajeet kumarVishwajeet kumar
Is Event a Platform Event ? if yes : 
Platform events cannot be queried, it can only be subscribed, which is the way to know if an event has been published. Rest resource above need to know Platform Event data i think, to query related data as the question.

You can either start the transaction as outbound to  external service from salesforce(Flow, Trigger, Process Builders) and send data using http callout
Use CometD,  to notify external client of such notifications as mentioned here ( after which external service should perfrom some queries based on platform events data.


Hi Vishwajeet,

Thank you for your reply.

No. Event is not a Platform Event. 

And I realize that the hardcoded id is not best practice. So I will revise my code.