Access GoldFinch Objects from Salesforce Community Customer Portal
Customer Portal users most likely do not have a GoldFinch ERP license. These users will not be able to access GoldFinch managed objects and records because of this licensing issue.
It is possible to bypass this licensing issue by having developers to write Apex Rest APIs that can handle requests from the Customer Portal / Client-side, such as:
Clicking View Items (a GET Request)
Adding items in to the Shopping Cart (a POST/PUT Request)
Checking out and creating a Sales Order (a POST Request).
Pre-requirements / knowledge: Salesforce Apex, Visualforce Page, GoldFinch tables/fields structure, Javascript/JQuery/Ajax, JSON, web development experience
Here is a sample of the GET Request that can be used for the View Items functionality:
@RestResource(urlMapping='/ItemService/*')
global with sharing class ItemService {
@HttpGet
global static List<GFERP__Item__c> getItems() {
List<GFERP__Item__c> theItemList = [
SELECT Name, GFERP__Description__c, GFERP__Item_Category__r.Name, GFERP__Sales_Unit_of_Measure__r.Name, GFERP__Lot_Tracked__c, GFERP__Standard_Base_Price__c,
GFERP__Sales_Unit_of_Measure__r.GFERP__Conversion__c, GFERP__Item_Category__c, GFERP__Sales_Unit_of_Measure__r.GFERP__Unit_of_Measure__c,GFERP__Brand__c, GFERP__Maximum_Quantity__c
FROM GFERP__Item__c WHERE GFCON__On_Customer_Portal__c = true
];
return theItemList;
}
}
From a Visualforce page or an HTML document, call the GET method using the following script:
var sessionId = '{!$Api.Session_ID}';
$.ajax({
cache: false,
url: '/services/proxy',
type: 'GET',
beforeSend: function(xhr) {
xhr.setRequestHeader('SalesforceProxy-Endpoint', '{!BaseURL}/services/apexrest/ItemService');
xhr.setRequestHeader('Authorization', 'OAuth ' + sessionId);
},
success: function(data,status,xhr) {
console.log(data);
},
error: function(xhr,status,errorThrown){
console.log(errorThrown);
}
});
If the Request is successful, Item data will be returned in JSON format:
[{
"attributes": {
"type": "GFERP__Item__c",
"url": "/services/data/v49.0/sobjects/GFERP__Item__c/a0Qf4000000pYQPEA2"
},
"Id": "a0Qf4000000pYQPEA2",
"Name": "111005",
"GFERP__Description__c": "Flour, Patent M CH",
"GFERP__Item_Category__c": "a0If40000000j6qEAA",
"GFERP__Sales_Unit_of_Measure__c": "a0Pf4000001AGegEAG",
"GFERP__Lot_Tracked__c": false,
"GFERP__Standard_Base_Price__c": 0,
"GFERP__Item_Category__r": {
"attributes": {
"type": "GFERP__Item_Category__c",
"url": "/services/data/v49.0/sobjects/GFERP__Item_Category__c/a0If40000000j6qEAA"
},
"Id": "a0If40000000j6qEAA",
"Name": "Ingredients"
},
"GFERP__Sales_Unit_of_Measure__r": {
"attributes": {
"type": "GFERP__Item_Unit_of_Measure__c",
"url": "/services/data/v49.0/sobjects/GFERP__Item_Unit_of_Measure__c/a0Pf4000001AGegEAG"
},
"Id": "a0Pf4000001AGegEAG",
"Name": "LB",
"GFERP__Conversion__c": 1,
"GFERP__Unit_of_Measure__c": "a13f40000001n66AAA"
},
"GFERP__Last_Rollup_Date__c": null,
"GFERP__Safety_Stock__c": null,
"GFERP__Reorder_Quantity__c": 0,
"GFERP__Maximum_Quantity__c": null
},{
"attributes": {
"type": "GFERP__Item__c",
"url": "/services/data/v49.0/sobjects/GFERP__Item__c/a0Qf40000008vaEEAQ"
},
"Id": "a0Qf40000008vaEEAQ",
"Name": "7000",
"GFERP__Description__c": "Chocolate Cake",
"GFERP__Item_Category__c": "a0If40000000j6tEAA",
"GFERP__Sales_Unit_of_Measure__c": "a0Pf40000009J1nEAE",
"GFERP__Lot_Tracked__c": true,
"GFERP__Standard_Base_Price__c": 35,
"GFERP__Item_Category__r": {
"attributes": {
"type": "GFERP__Item_Category__c",
"url": "/services/data/v49.0/sobjects/GFERP__Item_Category__c/a0If40000000j6tEAA"
},
"Id": "a0If40000000j6tEAA",
"Name": "Misc"
},
"GFERP__Sales_Unit_of_Measure__r": {
"attributes": {
"type": "GFERP__Item_Unit_of_Measure__c",
"url": "/services/data/v49.0/sobjects/GFERP__Item_Unit_of_Measure__c/a0Pf40000009J1nEAE"
},
"Id": "a0Pf40000009J1nEAE",
"Name": "Box",
"GFERP__Conversion__c": 6,
"GFERP__Unit_of_Measure__c": "a13f40000000bsXAAQ"
},
"GFERP__Last_Rollup_Date__c": "2020-07-16",
"GFERP__Safety_Stock__c": 1,
"GFERP__Reorder_Quantity__c": 210,
"GFERP__Maximum_Quantity__c": null
}]
Here is a sample of the POST Request that can be used to add items to the Shopping Cart:
@RestResource(urlMapping='/ShoppingCartService/*')
global with sharing class ShoppingCartService {
@HttpPOST
global static String postShoppingCart() {
RestRequest req = RestContext.request;
Blob body = req.requestBody;
String cartItem = body.toString();
try {
List<User> users = [SELECT AccountId FROM User WHERE Id = :UserInfo.getUserId()];
Id accId = users[0].AccountId;
cartItemWrapper theItem = (cartItemWrapper) System.JSON.deserialize(cartItem, cartItemWrapper.class);
Shopping_Cart_Item__c newSCI = new Shopping_Cart_Item__c (
Item__c = theItem.itemId, Unit_of_Measure__c = theItem.UOMId, Price__c = theItem.unitPrice,
Quantity__c = theItem.Quantity, Tax__c = 0, Customer__c = accId
);
insert newSCI;
return newSCI.Id;
} catch (Exception e) {
return e.getMessage();
}
}
public Class cartItemWrapper {
public String itemId;
public Integer Quantity;
public Decimal unitPrice;
}
}
Here is a sample of the JSON format that is used to add Items to the Shopping Cart:
{
"itemId": "a0Wf2000008gIN6EAM",
"UOMId": "a0Vf200000EARK6EAP",
"Quantity": "4",
"unitPrice": "25.00",
"description": "Unsweetened chocolate, chopped"
}
On a Visualforce page or HTML document, attach the Item data as JSON in your POST request:
var sessionId = '{!$Api.Session_ID}';
$.ajax({
cache: false,
url: '/services/proxy',
type: 'POST',
dataType: 'json',
data: JSON.stringify({itemId: "1234567", quantity: 10, unitPrice: 19.99}),
contentType: "application/json",
beforeSend: function (xhr) {
xhr.setRequestHeader('SalesforceProxy-Endpoint', '{!BaseURL}/services/apexrest/ShoppingCartService');
xhr.setRequestHeader('Authorization', 'OAuth ' + sessionId);
},
success: function(data,status,xhr) {
console.log(data);
},
error: function(xhr,status,errorThrown){
console.log(errorThrown);
}
});
If the Request is successful, the Response will return the Shopping_cart_item__c record Id.
On a Visualforce page or HTML document, make your POST request to check out the Shopping Cart:
var sessionId = '{!$Api.Session_ID}';
$.ajax({
cache: false,
url: '/services/proxy',
type: 'POST',
dataType: 'json',
contentType: "application/json",
beforeSend: function (xhr) {
xhr.setRequestHeader('SalesforceProxy-Endpoint', '{!baseURL}/service/apexrest/GFCON/GFSalesOrderService');
xhr.setRequestHeader('Authorization', 'OAuth ' + sessionId);
},
success: function(data,status,xhr) {
console.log(data);
},
error: function(xhr,status,errorThrown){
console.log(errorThrown);
}
});
If the Request is successful, the Response will return a GFERP__Sales_Order record name and id.
Ex. “SO-1000001,a1B4p000004kAMSEA2“
Available APIs:
GET:
Get posted sales invoice (GFERP__Sales_Invoice__c) for the customer
{!baseURL}/service/apexrest/GFCON/GFInvoiceService
Get non-completed sales order (GFERP__Sales_Order__c) for the customer
{!baseURL}/service/apexrest/GFCON/GFSalesOrderService
Get sales prices (GFERP__Sales_Price_Entry__c) for the customer
{!baseURL}/service/apexrest/GFCON/GFSalesPriceService
Get items where GFCON__On_Customer_Portal__c = true
{!baseURL}/service/apexrest/GFCON/GFItemService
Get shopping cart items (GFCON__Shopping_Cart_Item__c) for the customer
{!baseURL}/service/apexrest/GFCON/GFShoppingCartService
POST:
Add items to Shopping Cart
{!baseURL}/service/apexrest/GFCON/GFShoppingCartService
Pass in data in JSON format:
{itemId: text, description: text, UOMId: text, priceEntryId: text, quantity: number, unitPrice: number }
Note:
itemId: GFERP__Item__c record Id
UOMId: GFERP__Item_Unit_of_Measure__c record Id
priceEntryId: GFERP__Sales_Price_Entry__c record Id
Checkout to create a Sales Order with all Shopping cart items
{!baseURL}/service/apexrest/GFCON/GFSalesOrderService
PUT
Update existing Items in Shopping cart
{!baseURL}/service/apexrest/GFCON/GFShoppingCartService
Pass in data in JSON format:
{cartItemId: text, newQty: number}
Note:
cartItemId: GFCON__Shopping_Cart_Item__c record Id
More info: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_exposing_data.htm
REST API Samples: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_rest_code_sample_basic.htm