Skip to content

Overload methods to accept Schema.SObjectType and Schema.SObjectField #245

@CSigelmann

Description

@CSigelmann

Summary

When a custom object or field is removed from an org, it would be nice for a missed reference to be caught at compile-time. When passing strings to Query Lib, a missed reference will instead fail at runtime. Overloading Query Lib functions with Schema.SObjectType and Schema.SObjectField parameters would enable developers to be confident that their code is using existing objects and fields when it compiles.

Suggested Solution

Overload any functions that take an object type or field api name as a string to have another option to pass in Schema.SObjectType or Schema.SObjectField. For example from SOQL.Builder:

public Builder selectField(Schema.SObjectField field) {
    selectField(String.valueOf(field));
    return this;
}

and example usage:

SOQL soqlQuery = new SOQL.Builder(My_Custom_Object__c.SObjectType)
	.selectFields(new List<Schema.SObjectField>{
		My_Custom_Object__c.Id,
		My_Custom_Object__c.My_Custom_Field__c
	})
	.whereCondition(
		new Query.Condition()
			.equals(My_Custom_Object__c.Id, myId)
	)
	.build();

Alternative Solutions

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions