Last active
August 29, 2015 14:16
-
-
Save jkentjnr/d6391238652e96d79323 to your computer and use it in GitHub Desktop.
Salesforce - DTOs to SObjects
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// -------------- | |
// DTO Base Class | |
global abstract class DtoBase { | |
global abstract String getSObjectName(); | |
global abstract Map<String, Object> getSObjectMap(); | |
global virtual SObject ToSObject() { | |
SObject obj = Schema.getGlobalDescribe().get(getSObjectName()).newSObject(); | |
Map<String, Object> objectMap = getSObjectMap(); | |
for (String sObjectField : objectMap.keySet()) { | |
obj.put(sObjectField, objectMap.get(sObjectField)); | |
} | |
return obj; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global class ShiftDto extends DtoBase { | |
webservice Id RecordId; | |
webservice String Version; | |
webservice DateTime StartDateTime; | |
webservice DateTime EndDateTime; | |
webservice Id UserId; | |
webservice Id FacilityId; | |
webservice Id PeriodId; | |
webservice Id ShiftActivityId; | |
global override String getSObjectName() { | |
return 'Shift__c'; | |
} | |
global override Map<String, Object> getSObjectMap() { | |
return new Map<String, Object> { | |
'Id' => this.RecordId, | |
'Version__c' => this.Version, | |
'Start_Date_Time__c' => this.StartDateTime, | |
'End_Date_Time__c' => this.EndDateTime, | |
'User__c' => this.UserId, | |
'Facility__c' => this.FacilityId, | |
'Period__c' => this.PeriodId, | |
'Shift_Activity__c' => this.ShiftActivityId | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment