Skip to content

Commit

Permalink
Added option to specify API version
Browse files Browse the repository at this point in the history
  • Loading branch information
FrendsSarlinS committed Aug 19, 2024
1 parent ae5b69c commit 5ba3329
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Frends.Salesforce.CreateSObject/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<dynamic>(body);
_result.Add(new { Type = "Account", Id = obj.id });
}

[TestMethod]
public async Task CreateAccountTest_WithoutSpecifiedApiVersion()
{
var input = new Input
{
Expand Down Expand Up @@ -107,6 +126,7 @@ public async Task CreateContactTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectAsJson = json,
SObjectType = "Contact"
};
Expand All @@ -126,6 +146,7 @@ public async Task CreateCaseTest()
var accountInput = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectAsJson = _userJson,
SObjectType = "Account"
};
Expand All @@ -148,6 +169,7 @@ public async Task CreateCaseTest()
var caseInput = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectAsJson = json,
SObjectType = "Case"
};
Expand All @@ -166,6 +188,7 @@ public async Task GetReturnedAccessTokenTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectAsJson = _userJson,
SObjectType = "Account"
};
Expand Down Expand Up @@ -195,6 +218,7 @@ public async Task EmptyAccessToken_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectAsJson = _userJson,
SObjectType = "Contact"
};
Expand All @@ -215,6 +239,7 @@ public async Task EmptyDomain_ThrowTest()
var input = new Input
{
Domain = null,
ApiVersion = "v61.0",
SObjectAsJson = _userJson,
SObjectType = "Account"
};
Expand All @@ -235,6 +260,7 @@ public async Task EmptyJson_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectAsJson = null,
SObjectType = "Account"
};
Expand All @@ -255,6 +281,7 @@ public async Task EmptyType_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectAsJson = _userJson,
SObjectType = ""
};
Expand All @@ -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"
};
Expand All @@ -298,6 +326,7 @@ public async Task InvalidObjectType_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectAsJson = _userJson,
SObjectType = "InvalidType"
};
Expand All @@ -322,6 +351,7 @@ public async Task InvalidSecretOAuth_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectAsJson = _userJson,
SObjectType = "Account"
};
Expand All @@ -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"
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ public class Input
[DisplayFormat(DataFormatString = "Text")]
public string Domain { get; set; }

/// <summary>
/// The API version to use when making requests to Salesforce.
/// If left empty, the default value is the v61.0.
/// </summary>
[DefaultValue("v61.0")]
public string ApiVersion { get; set; } = "v61.0";

/// <summary>
/// SObject structure as json.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Version>1.0.1</Version>
<Version>2.0.0</Version>
<Authors>Frends</Authors>
<Copyright>Frends</Copyright>
<Company>Frends</Company>
Expand Down

0 comments on commit 5ba3329

Please sign in to comment.