Skip to content

Conversation

@TrangOul
Copy link
Contributor

@TrangOul TrangOul commented Oct 3, 2025

Fixes #911 . Skips saving the ID of the record if it doesn’t have one.

The try approach seems to run about ≈ 40×-50× faster than querying the Schema:

if (record.getSObjectType().getDescribe().fields.getMap().containsKey('Id')) {
	this.logEntryEvent.RecordId__c = record.Id
}

and ≈ 6×-7× faster than cached version of the Schema:

private static final Map<String, Boolean> CACHED_SOBJECT_NAME_TO_HAS_ID_FIELD = new Map<String, Boolean>();
private static Boolean getHasIdField(Schema.SObjectType sobjectType) {
	final String sobjectName = sobjectType.toString();
	if (CACHED_SOBJECT_NAME_TO_HAS_ID_FIELD.containsKey(sobjectName)) {
		return CACHED_SOBJECT_NAME_TO_HAS_ID_FIELD.get(sobjectName);
	}
	final Boolean hasIdField = sobjectType.getDescribe().fields.getMap().containsKey('Id');
	CACHED_SOBJECT_NAME_TO_HAS_ID_FIELD.put(sobjectName, hasIdField);
	return hasIdField;
}

(...)

if (this.getHasIdField(record.getSObjectType())) {
	this.logEntryEvent.RecordId__c = record.Id
}

@TrangOul TrangOul requested a review from jongpie as a code owner October 3, 2025 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support logging Platform Event SObjects

1 participant