diff --git a/Frends.Salesforce.CreateSObject/CHANGELOG.md b/Frends.Salesforce.CreateSObject/CHANGELOG.md index 0c54ed6..1b00047 100644 --- a/Frends.Salesforce.CreateSObject/CHANGELOG.md +++ b/Frends.Salesforce.CreateSObject/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.CreateSObject/Frends.Salesforce.CreateSObject.Tests/UnitTests.cs b/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject.Tests/UnitTests.cs index 06979ca..d40ab67 100644 --- a/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject.Tests/UnitTests.cs +++ b/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject.Tests/UnitTests.cs @@ -78,6 +78,25 @@ public async Task TestCleanUp() [TestMethod] public async Task CreateAccountTest() + { + var input = new Input + { + Domain = _domain, + ApiVersion = "v61.0", + SObjectAsJson = _userJson, + SObjectType = "Account" + }; + + var result = await Salesforce.CreateSObject(input, _options, _cancellationToken); + Assert.IsTrue(result.RequestIsSuccessful); + + var body = JsonConvert.SerializeObject(result.Body); + var obj = JsonConvert.DeserializeObject(body); + _result.Add(new { Type = "Account", Id = obj.id }); + } + + [TestMethod] + public async Task CreateAccountTest_WithoutSpecifiedApiVersion() { var input = new Input { @@ -107,6 +126,7 @@ public async Task CreateContactTest() var input = new Input { Domain = _domain, + ApiVersion = "v61.0", SObjectAsJson = json, SObjectType = "Contact" }; @@ -126,6 +146,7 @@ public async Task CreateCaseTest() var accountInput = new Input { Domain = _domain, + ApiVersion = "v61.0", SObjectAsJson = _userJson, SObjectType = "Account" }; @@ -148,6 +169,7 @@ public async Task CreateCaseTest() var caseInput = new Input { Domain = _domain, + ApiVersion = "v61.0", SObjectAsJson = json, SObjectType = "Case" }; @@ -166,6 +188,7 @@ public async Task GetReturnedAccessTokenTest() var input = new Input { Domain = _domain, + ApiVersion = "v61.0", SObjectAsJson = _userJson, SObjectType = "Account" }; @@ -195,6 +218,7 @@ public async Task EmptyAccessToken_ThrowTest() var input = new Input { Domain = _domain, + ApiVersion = "v61.0", SObjectAsJson = _userJson, SObjectType = "Contact" }; @@ -215,6 +239,7 @@ public async Task EmptyDomain_ThrowTest() var input = new Input { Domain = null, + ApiVersion = "v61.0", SObjectAsJson = _userJson, SObjectType = "Account" }; @@ -235,6 +260,7 @@ public async Task EmptyJson_ThrowTest() var input = new Input { Domain = _domain, + ApiVersion = "v61.0", SObjectAsJson = null, SObjectType = "Account" }; @@ -255,6 +281,7 @@ public async Task EmptyType_ThrowTest() var input = new Input { Domain = _domain, + ApiVersion = "v61.0", SObjectAsJson = _userJson, SObjectType = "" }; @@ -275,6 +302,7 @@ public async Task InvalidDomain_ThrowTest() var input = new Input { Domain = "https://mycompany.my.salesforce.com", + ApiVersion = "v61.0", SObjectAsJson = _userJson, SObjectType = "Account" }; @@ -298,6 +326,7 @@ public async Task InvalidObjectType_ThrowTest() var input = new Input { Domain = _domain, + ApiVersion = "v61.0", SObjectAsJson = _userJson, SObjectType = "InvalidType" }; @@ -322,6 +351,7 @@ public async Task InvalidSecretOAuth_ThrowTest() var input = new Input { Domain = _domain, + ApiVersion = "v61.0", SObjectAsJson = _userJson, SObjectType = "Account" }; @@ -347,6 +377,7 @@ public async Task InvalidJson_ThrowTest() var input = new Input { Domain = _domain, + ApiVersion = "v61.0", SObjectAsJson = "Not valid json format", SObjectType = "Account" }; diff --git a/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject/CreateSObject.cs b/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject/CreateSObject.cs index 72a60e0..ec92dc5 100644 --- a/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject/CreateSObject.cs +++ b/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject/CreateSObject.cs @@ -31,7 +31,7 @@ CancellationToken cancellationToken if (string.IsNullOrWhiteSpace(input.SObjectAsJson)) throw new ArgumentNullException("Json 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); + var client = new RestClient($"{input.Domain}/services/data/{input.ApiVersion}/sobjects/{input.SObjectType}"); var request = new RestRequest("/", Method.Post); string accessToken = ""; diff --git a/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject/Definitions/Input.cs b/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject/Definitions/Input.cs index 406d8c5..9d3e005 100644 --- a/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject/Definitions/Input.cs +++ b/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject/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 the v61.0. + /// + [DefaultValue("v61.0")] + public string ApiVersion { get; set; } = "v61.0"; + /// /// SObject structure as json. /// diff --git a/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject.csproj b/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject.csproj index 865a4b3..c16a921 100644 --- a/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject.csproj +++ b/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject/Frends.Salesforce.CreateSObject.csproj @@ -2,7 +2,7 @@ net6.0 - 1.0.1 + 2.0.0 Frends Frends Frends