This file contains hidden or 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
| public static List<Database.UpsertResult> upsertListSObjectsWithExternalIdNoAllOrNothingErrorExampleFix() { | |
| /* To resolve the System.TypeException: DML on generic List<SObject> only allowed for insert, update or delete" | |
| error, dynamically instantiate the List of SObject to a list of a concrete SObject type. | |
| */ | |
| Account a = new Account( | |
| Name = 'Example Company', | |
| External_Id__c = 'ExampleCompany' | |
| ); | |
This file contains hidden or 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
| public static List<Database.UpsertResult> upsertListSObjectsWithExternalIdWithAllOrNothingErrorExample() { | |
| List<SObject> records = new List<SObject>(); | |
| Account a = new Account( | |
| Name = 'Example Company', | |
| External_Id__c = 'ExampleCompany' | |
| ); | |
| records.add(a); | |
This file contains hidden or 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
| public List<Database.upsertResult> upsertWorkaround(String sobjectType, List<SObject> recordsToUpsert, Schema.SObjectField externalIdField, Boolean allOrNothing) { | |
| if (sobjectType == 'Account') { | |
| return Database.upsert((List<Account>) recordsToUpsert, externalIdField, allOrNothing); | |
| } | |
| if (sobjectType == 'Contact') { | |
| return Database.upsert((List<Contact>) recordsToUpsert, externalIdField, allOrNothing); | |
| } | |
| } |
This file contains hidden or 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
| public List<Database.upsertResult> upsertWorkaround(String sobjectType, List<SObject> recordsToUpsert, Schema.SObjectField externalIdField, Boolean allOrNothing) { | |
| if (sobjectType == 'Account') { | |
| return Database.upsert((List<Account>) recordsToUpsert, externalIdField, allOrNothing); | |
| } | |
| if (sobjectType == 'Contact') { | |
| return Database.upsert((List<Contact>) recordsToUpsert, externalIdField, allOrNothing); | |
| } | |
| // etc |
This file contains hidden or 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
| async function main() { | |
| await ping(); | |
| // Other code here is executed without a callback function. | |
| } | |
| main(); |
This file contains hidden or 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
| Select count() | |
| from Account | |
| where <predicate> |
This file contains hidden or 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
| Select Id, | |
| Name, | |
| ... | |
| from Account | |
| where <predicate> |
This file contains hidden or 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
| public Batch CreateAttachmentBatch(CreateAttachmentBatchRequest request) | |
| { | |
| String requestTxtFileCSVContents = "Name,ParentId,Body" + Environment.NewLine; | |
| requestTxtFileCSVContents += request.FilePath + "," + request.ParentId + ",#" + request.FilePath; | |
| using (MemoryStream memoryStream = new MemoryStream()) | |
| { | |
| using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true)) | |
| { | |
| byte[] requestTxtFileCSVContentsBytes = UTF8Encoding.UTF8.GetBytes(requestTxtFileCSVContents); |
This file contains hidden or 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
| /// <summary> | |
| /// Tests attaching a file to the specified "AttachmentParentId" record. | |
| /// </summary> | |
| [TestMethod] | |
| public void AttachFileTest() | |
| { | |
| String parentId = ConfigurationManager.AppSettings["AttachmentParentId"]; | |
| Assert.IsTrue(String.IsNullOrWhiteSpace(parentId) == false, "The AttachmentParentId app setting is blank. Please specify the id of a salesforce record to attach an attachment file."); |
This file contains hidden or 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
| // records populated | |
| List<SObject> records = ...; | |
| Set<Id> recordIds = new Set<Id>(); | |
| for (SObject record : records) { | |
| recordIds.add(record.Id); | |
| } |