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

DeleteSObject - Added option to specify API version #32

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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.DeleteSObject/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 @@ -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);
Expand All @@ -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);
}
Expand All @@ -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);
}

Expand All @@ -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);
}
Expand All @@ -129,6 +138,7 @@ public async Task EmptyAccessToken_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectId = "123456789",
SObjectType = "Contact"
};
Expand All @@ -149,6 +159,7 @@ public async Task EmptyDomain_ThrowTest()
var input = new Input
{
Domain = null,
ApiVersion = "v61.0",
SObjectId = "123456789",
SObjectType = "Account"
};
Expand All @@ -169,6 +180,7 @@ public async Task EmptyId_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectId = null,
SObjectType = "Account"
};
Expand All @@ -189,6 +201,7 @@ public async Task EmptyType_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectId = "123456789",
SObjectType = ""
};
Expand All @@ -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"
};
Expand All @@ -232,6 +246,7 @@ public async Task InvalidObjectType_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectId = "123456789",
SObjectType = "InvalidType"
};
Expand All @@ -256,6 +271,7 @@ public async Task InvalidSecretOAuth_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectId = "123456789",
SObjectType = "Account"
};
Expand All @@ -280,6 +296,7 @@ public async Task InvalidId_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectId = "Not valid id",
SObjectType = "Account"
};
Expand All @@ -301,6 +318,7 @@ public async Task NotFoundId_ThrowTest()
var input = new Input
{
Domain = _domain,
ApiVersion = "v61.0",
SObjectId = "123456789",
SObjectType = "Account"
};
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 v61.0.
/// </summary>
[DefaultValue("v61.0")]
public string ApiVersion { get; set; } = "v61.0";

/// <summary>
/// SObject id.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";

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
Loading