From 3d90c1aec169423aa83c1963660b9c1af86b2ad3 Mon Sep 17 00:00:00 2001 From: FrendsSarlinS Date: Mon, 19 Aug 2024 14:50:50 +0300 Subject: [PATCH 1/2] Added option to specify API version --- Frends.Salesforce.DeleteSObject/CHANGELOG.md | 4 +++ .../UnitTests.cs | 26 ++++++++++++++++--- .../Definitions/Input.cs | 7 +++++ .../DeleteSObject.cs | 2 +- .../Frends.Salesforce.DeleteSObject.csproj | 2 +- 5 files changed, 35 insertions(+), 6 deletions(-) diff --git a/Frends.Salesforce.DeleteSObject/CHANGELOG.md b/Frends.Salesforce.DeleteSObject/CHANGELOG.md index 5088c5e..35fe83f 100644 --- a/Frends.Salesforce.DeleteSObject/CHANGELOG.md +++ b/Frends.Salesforce.DeleteSObject/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [2.0.0] - 2024-08-19 +### Added +- Salesforce API version number can now be specified in input. + ## [1.0.1] - 2022-05-27 ### Changed - Fix for issue with referencing result-object in other elements. diff --git a/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject.Tests/UnitTests.cs b/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject.Tests/UnitTests.cs index cd7196f..b08f277 100644 --- a/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject.Tests/UnitTests.cs +++ b/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject.Tests/UnitTests.cs @@ -56,6 +56,15 @@ public async Task TestInitialize() [TestMethod] public async Task DeleteAccountTest() + { + var id = await CreateSObject("Account", _userJson); + var result = await Salesforce.DeleteSObject(new Input { Domain = _domain, ApiVersion = "v61.0", SObjectId = id, SObjectType = "Account" }, _options, _cancellationToken); + + Assert.IsTrue(result.RequestIsSuccessful); + } + + [TestMethod] + public async Task DeleteAccountTest_WithoutSpecifiedApiVersion() { var id = await CreateSObject("Account", _userJson); var result = await Salesforce.DeleteSObject(new Input { Domain = _domain, SObjectId = id, SObjectType = "Account" }, _options, _cancellationToken); @@ -74,7 +83,7 @@ public async Task DeleteContactTest() }); var id = await CreateSObject("Contact", json); - var result = await Salesforce.DeleteSObject(new Input { Domain = _domain, SObjectId = id, SObjectType = "Contact" }, _options, _cancellationToken); + var result = await Salesforce.DeleteSObject(new Input { Domain = _domain, ApiVersion = "v61.0", SObjectId = id, SObjectType = "Contact" }, _options, _cancellationToken); Assert.IsTrue(result.RequestIsSuccessful); } @@ -96,10 +105,10 @@ public async Task DeleteCaseTest() var caseId = await CreateSObject("Case", json); - var caseResult = await Salesforce.DeleteSObject(new Input { Domain = _domain, SObjectId = caseId, SObjectType = "Case" }, _options, _cancellationToken); + var caseResult = await Salesforce.DeleteSObject(new Input { Domain = _domain, ApiVersion = "v61.0", SObjectId = caseId, SObjectType = "Case" }, _options, _cancellationToken); Assert.IsTrue(caseResult.RequestIsSuccessful); - var accountResult = await Salesforce.DeleteSObject(new Input { Domain = _domain, SObjectId = accountId, SObjectType = "Account" }, _options, _cancellationToken); + var accountResult = await Salesforce.DeleteSObject(new Input { Domain = _domain, ApiVersion = "v61.0", SObjectId = accountId, SObjectType = "Account" }, _options, _cancellationToken); Assert.IsTrue(accountResult.RequestIsSuccessful); } @@ -117,7 +126,7 @@ public async Task GetReturnedAccessTokenTest() Password = _password + _securityToken, ReturnAccessToken = true }; - var result = await Salesforce.DeleteSObject(new Input { Domain = _domain, SObjectId = id, SObjectType = "Account" }, options, _cancellationToken); + var result = await Salesforce.DeleteSObject(new Input { Domain = _domain, ApiVersion = "v61.0", SObjectId = id, SObjectType = "Account" }, options, _cancellationToken); Assert.IsNotNull(result.Token); } @@ -129,6 +138,7 @@ public async Task EmptyAccessToken_ThrowTest() var input = new Input { Domain = _domain, + ApiVersion = "v61.0", SObjectId = "123456789", SObjectType = "Contact" }; @@ -149,6 +159,7 @@ public async Task EmptyDomain_ThrowTest() var input = new Input { Domain = null, + ApiVersion = "v61.0", SObjectId = "123456789", SObjectType = "Account" }; @@ -169,6 +180,7 @@ public async Task EmptyId_ThrowTest() var input = new Input { Domain = _domain, + ApiVersion = "v61.0", SObjectId = null, SObjectType = "Account" }; @@ -189,6 +201,7 @@ public async Task EmptyType_ThrowTest() var input = new Input { Domain = _domain, + ApiVersion = "v61.0", SObjectId = "123456789", SObjectType = "" }; @@ -209,6 +222,7 @@ public async Task InvalidDomain_ThrowTest() var input = new Input { Domain = "https://mycompany.my.salesforce.com", + ApiVersion = "v61.0", SObjectId = "123456789", SObjectType = "Account" }; @@ -232,6 +246,7 @@ public async Task InvalidObjectType_ThrowTest() var input = new Input { Domain = _domain, + ApiVersion = "v61.0", SObjectId = "123456789", SObjectType = "InvalidType" }; @@ -256,6 +271,7 @@ public async Task InvalidSecretOAuth_ThrowTest() var input = new Input { Domain = _domain, + ApiVersion = "v61.0", SObjectId = "123456789", SObjectType = "Account" }; @@ -280,6 +296,7 @@ public async Task InvalidId_ThrowTest() var input = new Input { Domain = _domain, + ApiVersion = "v61.0", SObjectId = "Not valid id", SObjectType = "Account" }; @@ -301,6 +318,7 @@ public async Task NotFoundId_ThrowTest() var input = new Input { Domain = _domain, + ApiVersion = "v61.0", SObjectId = "123456789", SObjectType = "Account" }; diff --git a/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject/Definitions/Input.cs b/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject/Definitions/Input.cs index a527724..9a51438 100644 --- a/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject/Definitions/Input.cs +++ b/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject/Definitions/Input.cs @@ -16,6 +16,13 @@ public class Input [DisplayFormat(DataFormatString = "Text")] public string Domain { get; set; } + /// + /// The API version to use when making requests to Salesforce. + /// If left empty, the default value is v61.0. + /// + [DefaultValue("v61.0")] + public string ApiVersion { get; set; } = "v61.0"; + /// /// SObject id. /// diff --git a/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject/DeleteSObject.cs b/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject/DeleteSObject.cs index f955182..9805a9e 100644 --- a/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject/DeleteSObject.cs +++ b/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject/DeleteSObject.cs @@ -33,7 +33,7 @@ CancellationToken cancellationToken if (string.IsNullOrWhiteSpace(input.SObjectId)) throw new ArgumentNullException("Id cannot be empty."); if (string.IsNullOrWhiteSpace(input.SObjectType)) throw new ArgumentNullException("Type cannot be empty."); - var client = new RestClient(input.Domain + "/services/data/v54.0/sobjects/" + input.SObjectType + "/" + input.SObjectId); + var client = new RestClient($"{input.Domain}/services/data/{input.ApiVersion}/sobjects/{input.SObjectType}/{input.SObjectId}"); var request = new RestRequest("/", Method.Delete); string accessToken = ""; diff --git a/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject.csproj b/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject.csproj index d454de1..905e60f 100644 --- a/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject.csproj +++ b/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject.csproj @@ -2,7 +2,7 @@ net6.0 - 1.0.1 + 2.0.0 Frends Frends Frends From 8f024f96b9ada9fa79aacc0cf87b18544685556e Mon Sep 17 00:00:00 2001 From: FrendsSarlinS Date: Mon, 19 Aug 2024 15:12:54 +0300 Subject: [PATCH 2/2] Typo fixed --- .../Frends.Salesforce.DeleteSObject/Definitions/Input.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject/Definitions/Input.cs b/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject/Definitions/Input.cs index 9a51438..6350222 100644 --- a/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject/Definitions/Input.cs +++ b/Frends.Salesforce.DeleteSObject/Frends.Salesforce.DeleteSObject/Definitions/Input.cs @@ -9,7 +9,7 @@ public class Input { /// /// Salesforce Domain. - /// /services/data/v52.0/query will be added automatically, so the domain is enough. + /// /services/data/versionnumber/query will be added automatically, so the domain is enough. /// /// https://example.my.salesforce.com [DefaultValue(@"https://example.my.salesforce.com")]