Skip to content

Commit

Permalink
Update examples with new sub modules
Browse files Browse the repository at this point in the history
  • Loading branch information
aashikam committed Jul 18, 2024
1 parent dd266a7 commit 79ca25e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion build-config/resources/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ distribution = "2201.8.0"
org = "ballerinax"
name = "salesforce"
version = "@toml.version@"
export = ["salesforce", "salesforce.bulk", "salesforce.soap"]
export = ["salesforce", "salesforce.bulk", "salesforce.soap","salesforce.bulkv2", "salesforce.apex"]
license= ["Apache-2.0"]
authors = ["Ballerina"]
keywords = ["Sales & CRM/Customer Relationship Management", "Cost/Freemium"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// under the License.

import ballerina/log;
import ballerinax/salesforce;
import ballerinax/salesforce.apex;
import ballerina/lang.runtime;

// Create Salesforce client configuration by reading from environment.
Expand All @@ -26,7 +26,7 @@ configurable string refreshUrl = ?;
configurable string baseUrl = ?;

// Using direct-token config for client configuration
salesforce:ConnectionConfig sfConfig = {
apex:ConnectionConfig sfConfig = {
baseUrl,
auth: {
clientId,
Expand All @@ -38,7 +38,7 @@ salesforce:ConnectionConfig sfConfig = {

public function main() returns error? {
// Create Case using user defined APEX method
salesforce:Client baseClient = check new (sfConfig);
apex:Client baseClient = check new (sfConfig);

string|error caseId = baseClient->apexRestExecute("Cases", "POST",
{"subject" : "Item Fault!",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
// specific language governing permissions and limitations
// under the License.

import ballerinax/salesforce;
import ballerinax/salesforce.bulkv2;
import ballerina/lang.runtime;
import ballerina/io;

// Create Salesforce client configuration by reading from environment.
// Create Salesforce bulkv2 client configuration by reading from environment.
configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string refreshToken = ?;
configurable string refreshUrl = ?;
configurable string baseUrl = ?;

// Using direct-token config for client configuration
salesforce:ConnectionConfig sfConfig = {
bulkv2:ConnectionConfig sfConfig = {
baseUrl,
auth: {
clientId,
Expand All @@ -38,34 +38,34 @@ salesforce:ConnectionConfig sfConfig = {

public function main() returns error? {
// Insert contacts using a CSV file
salesforce:Client baseClient = check new (sfConfig);
bulkv2:Client baseClient = check new (sfConfig);
string csvContactsFilePath = "contacts1.csv";

//create job
salesforce:BulkCreatePayload payload = {
bulkv2:BulkCreatePayload payload = {
'object : "Contact",
contentType : "CSV",
operation : "insert",
lineEnding : "LF"
};
error|salesforce:BulkJob insertJob = baseClient->createIngestJob(payload);
error|bulkv2:BulkJob insertJob = baseClient->createIngestJob(payload);

if insertJob is salesforce:BulkJob {
if insertJob is bulkv2:BulkJob {
string[][] csvContent = check io:fileReadCsv(csvContactsFilePath);
error? response = baseClient->addBatch(insertJob.id, csvContent);
if response is error {
io:println("Error occurred while adding batch to job: ", response.message());
}
runtime:sleep(5);
//get job info
error|salesforce:BulkJobInfo jobInfo = baseClient->getJobInfo(insertJob.id, "ingest");
error|bulkv2:BulkJobInfo jobInfo = baseClient->getJobInfo(insertJob.id, "ingest");
if jobInfo is error {
io:println("Error occurred while getting job info: ", jobInfo.message());
}
runtime:sleep(5);
//close job
future<salesforce:BulkJobInfo|error> closedJob = check baseClient->closeIngestJobAndWait(insertJob.id);
salesforce:BulkJobInfo|error closedJobInfo = wait closedJob;
future<bulkv2:BulkJobInfo|error> closedJob = check baseClient->closeIngestJobAndWait(insertJob.id);
bulkv2:BulkJobInfo|error closedJobInfo = wait closedJob;
if closedJobInfo is error {
io:println("Error occurred while closing job: ", closedJobInfo.message());
}
Expand Down

0 comments on commit 79ca25e

Please sign in to comment.