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

Fix sf sample issues #48

Merged
merged 4 commits into from
Jan 19, 2024
Merged
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
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();
}
}
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