Skip to content

Commit

Permalink
Merge pull request #48 from anupama-pathirage/fixSFSampleIssues
Browse files Browse the repository at this point in the history
Fix sf sample issues
  • Loading branch information
sahanHe authored Jan 19, 2024
2 parents b944537 + 867a528 commit 2a2f30c
Show file tree
Hide file tree
Showing 17 changed files with 16 additions and 16 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,21 @@ salesforce:Client salesforce = check new ({
token: salesforceAccessToken
}
});

mysql:Client mysql = check new (host, user, password, database, port);

public function main() returns error? {
stream<ProductRecieved, error?> streamOutput = mysql->query(
`SELECT name, unitType, currencyISO, productId FROM products WHERE processed = false`);
ProductRecieved[] productsRecieved = check from ProductRecieved items in streamOutput
select items;
foreach ProductRecieved prductRecieved in productsRecieved {
record {|ProductRecieved value;|}|error? productRecieved = streamOutput.next();
while productRecieved !is error|() {
Product product = {
Name: prductRecieved.name,
Product_Unit__c: prductRecieved.unitType,
CurrencyIsoCode: prductRecieved.currencyISO
Name: productRecieved.value.name,
Product_Unit__c: productRecieved.value.unitType,
CurrencyIsoCode: productRecieved.value.currencyISO
};
_ = check salesforce->create("Product2", product);
_ = check mysql->execute(
`UPDATE products SET processed = true WHERE productId = ${prductRecieved.productId}`);
`UPDATE products SET processed = true WHERE productId = ${productRecieved.value.productId}`);
productRecieved = streamOutput.next();
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ configurable string toNumber = ?;
listener salesforce:Listener sfdcEventListener = new ({
username: salesforceListenerConfig.username,
password: salesforceListenerConfig.password,
channelName: "/data/ContactChangeEvent"});
channelName: "/data/ContactChangeEvent"
});

final twilio:Client twilio = check new ({
twilioAuth: {
Expand Down
2 changes: 1 addition & 1 deletion servicenow-case-to-salesforce-case/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ syncdata = "resources/syncdata"
# ServiceNow configuration
# ==========================
servicenowInstance = "<servicenow-instance-id>"
serviceNowInstance = "<servicenow-instance-id>"
serviceNowUsername = "<servicenow-username>"
serviceNowPassword = "<servicenow-password>"
Expand Down
8 changes: 4 additions & 4 deletions servicenow-case-to-salesforce-case/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ballerina/time;
import ballerina/url;
import ballerinax/salesforce as sf;

configurable string servicenowInstance = ?;
configurable string serviceNowInstance = ?;
configurable string syncData = ?;
configurable string serviceNowUsername = ?;
configurable string serviceNowPassword = ?;
Expand Down Expand Up @@ -36,10 +36,10 @@ public function main() returns error? {
check io:fileWriteString(syncData, check time:civilToString(fetchPeriod.now));
}
function fetchCasesFromServiceNow(string fetchFrom, string fetchTill) returns CaseData[]|error {
http:Client servicenow = check new (string `https://${servicenowInstance}.service-now.com/api/sn_customerservice`);
string serviceNowCredentials = check mime:base64Encode(serviceNowUsername + ":" + serviceNowPassword, "UTF-8").ensureType();
http:Client serviceNow = check new (string `https://${serviceNowInstance}.service-now.com/api/sn_customerservice`);
string serviceNowCredentials = check mime:base64Encode(string `${serviceNowUsername}:${serviceNowPassword}`, "UTF-8").ensureType();
string query = string `sys_created_onBETWEENjavascript:gs.dateGenerate(${fetchFrom})@javascript:gs.dateGenerate(${fetchTill})`;
record {CaseData[] result;} caseResponse = check servicenow->/case(
record {CaseData[] result;} caseResponse = check serviceNow->/case(
headers = {"Authorization": "Basic " + serviceNowCredentials},
sysparm_query = check url:encode(query, "UTF-8")
);
Expand Down
4 changes: 2 additions & 2 deletions shopify-customer-to-salesforce-customer/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import ballerina/regex;
import ballerinax/salesforce as sf;

configurable sf:ConnectionConfig salesforceConfig = ?;
sf:Client salesforce = check new (salesforceConfig);
final sf:Client salesforce = check new (salesforceConfig);

service /salesforce_bridge on new http:Listener(9090) {
resource function post customers(@http:Payload ShopifyCustomer shopifyCustomer) returns error? {
resource function post customers(ShopifyCustomer shopifyCustomer) returns error? {
string firstName = shopifyCustomer.first_name ?: regex:split(shopifyCustomer.email, "@")[0];
string lastName = shopifyCustomer.last_name ?: "";
Address? shopifyAddress = shopifyCustomer.default_address;
Expand Down

0 comments on commit 2a2f30c

Please sign in to comment.