You need to sign in to do that
Don't have an account?

Avoiding hardcoded IDs in Apex class for API get
Hi.
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*.
@RestResource(urlMapping='/eventplatformList/*')
global with sharing class eventplatformRestResource {
@HttpGet
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?
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
OR
Use CometD, to notify external client of such notifications as mentioned here (https://developer.salesforce.com/docs/atlas.en-us.platform_events.meta/platform_events/platform_events_subscribe_cometd.htm) after which external service should perfrom some queries based on platform events data.
Thanks
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.