Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UpdateSObject - Added option to specify API version #33

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Frends.Salesforce.UpdateSObject/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.0] - 2022-05-11
### Added
- Initial implementation of Frends.Salesforce.UpdateSObject
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,18 @@ public async Task UpdateAccountTest()
var id = await CreateSObject("Account", _userJson);
_result.Add(new { Type = "Account", Id = id });

var newInput = new { Name = "NewName_" + _name };
var result = await Salesforce.UpdateSObject(new Input { Domain = _domain, ApiVersion = "v61.0", SObjectId = id, SObjectType = "Account", SObjectAsJson = JsonSerializer.Serialize(newInput) }, _options, _cancellationToken);

Assert.IsTrue(result.RequestIsSuccessful);
}

[TestMethod]
public async Task UpdateAccountTest_WithoutSpecifiedApiVersion()
{
var id = await CreateSObject("Account", _userJson);
_result.Add(new { Type = "Account", Id = id });

var newInput = new { Name = "NewName_" + _name };
var result = await Salesforce.UpdateSObject(new Input { Domain = _domain, SObjectId = id, SObjectType = "Account", SObjectAsJson = JsonSerializer.Serialize(newInput) }, _options, _cancellationToken);

Expand All @@ -103,6 +115,7 @@ public async Task UpdateContactTest()
var result = await Salesforce.UpdateSObject(new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectId = id,
SObjectType = "Contact",
SObjectAsJson = JsonSerializer.Serialize(
Expand Down Expand Up @@ -139,6 +152,7 @@ public async Task UpdateCaseTest()
var caseResult = await Salesforce.UpdateSObject(new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectId = caseId,
SObjectType = "Case",
SObjectAsJson = JsonSerializer.Serialize(
Expand Down Expand Up @@ -171,7 +185,7 @@ public async Task GetReturnedAccessTokenTest()
Password = _password + _securityToken,
ReturnAccessToken = true
};
var result = await Salesforce.UpdateSObject(new Input { Domain = _domain, SObjectId = id, SObjectType = "Account", SObjectAsJson = JsonSerializer.Serialize(newInput) }, options, _cancellationToken);
var result = await Salesforce.UpdateSObject(new Input { Domain = _domain, ApiVersion = "v61.0", SObjectId = id, SObjectType = "Account", SObjectAsJson = JsonSerializer.Serialize(newInput) }, options, _cancellationToken);

Assert.IsNotNull(result.Token);
}
Expand All @@ -183,6 +197,7 @@ public async Task EmptyAccessToken_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectId = "123456789",
SObjectAsJson = _userJson,
SObjectType = "Contact"
Expand All @@ -204,6 +219,7 @@ public async Task EmptyDomain_ThrowTest()
var input = new Input
{
Domain = null,
ApiVersion = "v61.0",
SObjectId = "123456789",
SObjectType = "Account"
};
Expand All @@ -224,6 +240,7 @@ public async Task EmptyId_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectId = null,
SObjectType = "Account"
};
Expand All @@ -244,6 +261,7 @@ public async Task EmptyJson_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectAsJson = null,
SObjectType = "Account"
};
Expand All @@ -264,6 +282,7 @@ public async Task EmptyType_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectId = "123456789",
SObjectType = ""
};
Expand All @@ -284,6 +303,7 @@ public async Task InvalidDomain_ThrowTest()
var input = new Input
{
Domain = "https://mycompany.my.salesforce.com",
ApiVersion = "v61.0",
SObjectId = "123456789",
SObjectAsJson = _userJson,
SObjectType = "Account"
Expand All @@ -309,6 +329,7 @@ public async Task ExampleDomain_ThrowTest()
var input = new Input
{
Domain = "https://example.my.salesforce.com",
ApiVersion = "v61.0",
SObjectId = "123456789",
SObjectAsJson = _userJson,
SObjectType = "Account"
Expand All @@ -334,6 +355,7 @@ public async Task InvalidObjectType_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectId = "123456789",
SObjectAsJson = _userJson,
SObjectType = "InvalidType"
Expand All @@ -360,6 +382,7 @@ public async Task InvalidSecretOAuth_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectId = "123456789",
SObjectAsJson = _userJson,
SObjectType = "Account"
Expand All @@ -386,6 +409,7 @@ public async Task InvalidId_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectId = "Not valid id",
SObjectAsJson = _userJson,
SObjectType = "Account"
Expand All @@ -408,6 +432,7 @@ public async Task InvalidJson_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectAsJson = "Not valid json format",
SObjectId = "123456789",
SObjectType = "Account"
Expand All @@ -429,6 +454,7 @@ public async Task NotFoundId_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectId = "123456789",
SObjectType = "Account",
SObjectAsJson = _userJson
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,20 @@ public class Input
{
/// <summary>
/// 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.
/// </summary>
/// <example>https://example.my.salesforce.com</example>
[DefaultValue(@"https://example.my.salesforce.com")]
[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 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.0</Version>
<Version>2.0.0</Version>
<Authors>Frends</Authors>
<Copyright>Frends</Copyright>
<Company>Frends</Company>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,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 + "/" + input.SObjectId);
var client = new RestClient($"{input.Domain}/services/data/{input.ApiVersion}/sobjects/{input.SObjectType}/{input.SObjectId}");
var request = new RestRequest("/", Method.Patch);
string accessToken = "";

Expand Down
Loading