This question is equal to the parts of C # and Salesforce, maybe solutions from both sides are possible. Suggestions are welcome!
I am writing a generic class to read Salesforce data. The signature is as follows:
public abstract class SalesforceReader<SalesforceObjectType, RecordType> where SalesforceObjectType: sObject
This allows me to use this code later:
List<RecordType> records = new List<RecordType>(); QueryResult queryResult = service.query(query); foreach (sObject rawRecord in queryResult.records) records.Add(ConvertRecord((SalesforceObjectType)rawRecord)); ... public abstract RecordType ConvertRecord(SalesforceObjectType record);
The plan is to write an implementation of this class that knows how to parse, for example, a Salesforce Lead object in RecordType , which can be the main object[] , and Dictionary<string, value> or a fully -defined struct, as I choose later.
So far, I am very pleased with my brilliant elegant solution. My Codey award is as good as winning. Then I try to write an implementation. This definition does not fit:
class LeadReader: SalesforceReader<Lead, object[]>
Compiler Result:
The type 'SalesforceExtractor.Salesforce.Lead' cannot be used as type parameter 'SalesforceObjectType' in the generic type or method 'SalesforceUtilities.SalesforceReader<SalesforceObjectType,RecordType>'. There is no implicit reference conversion from 'SalesforceExtractor.Salesforce.Lead' to 'SalesforceUtilities.Salesforce.sObject'.
Bummer. I must have a where SalesforceObjectType: sObject in the abstract class, so I can use sObjects, but since the conversion is not implicit, it is not enough for the implementation class.
Do I need to kiss my neat little goodbye decision, or is there a way to save that? This is my first Salesforce project, so if I need to take a different approach, please let me know.
For a bad movie / MST 3K buffs there:
Where "must" and "cannot" occur on the chart?