Skip to content

Commit

Permalink
Merge pull request #1 from intrudir/main
Browse files Browse the repository at this point in the history
Add getApexMethod bambda
  • Loading branch information
intrudir authored Dec 30, 2024
2 parents bb67019 + c7b8efb commit 1e098ee
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
56 changes: 56 additions & 0 deletions CustomColumn/Proxy/HTTP/SalesForce/GetApexMethod.bambda
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/**
* Extracts the "method" value from either the query string (GET requests) or JSON in the request body (POST requests).
* This avoids dependencies on external libraries.
# Author: Jonathan Conesa
**/

if (requestResponse.finalRequest().path().contains("/api/apex/execute")) {
try {
// Check the HTTP method (GET or POST)
String httpMethod = requestResponse.finalRequest().method();

if (httpMethod.equalsIgnoreCase("GET")) {
// Extract the full URL
String url = requestResponse.finalRequest().url();

// Locate the start of the query string
int queryStartIndex = url.indexOf("?");
if (queryStartIndex != -1) {
String queryString = url.substring(queryStartIndex + 1); // Extract query string
String[] params = queryString.split("&"); // Split into individual parameters

for (String param : params) {
if (param.startsWith("method=")) {
// Extract and return the value of the "method" parameter
return param.substring(7); // Skip "method="
}
}
return "Error: 'method' key not found in query string";
} else {
return "Error: No query string found in URL";
}
} else if (httpMethod.equalsIgnoreCase("POST")) {
// Extract the request body as a string
String requestBody = requestResponse.finalRequest().bodyToString().trim();

// Ensure the body contains the "method" key
if (requestBody.contains("\"method\":\"")) {
int methodStartIndex = requestBody.indexOf("\"method\":\"") + 10; // Skip past "method":" length
int methodEndIndex = requestBody.indexOf("\"", methodStartIndex);

// Extract and return the "method" value
return requestBody.substring(methodStartIndex, methodEndIndex);
} else {
return "Error: 'method' key not found in body";
}
} else {
return "Error: Unsupported HTTP method " + httpMethod;
}
} catch (Exception e) {
// Return error details in case of an exception
return "Error: Exception while processing - " + e.getMessage();
}
}

// Return empty string if the request doesn't match the target criteria
return "";
7 changes: 6 additions & 1 deletion CustomColumn/Proxy/HTTP/SalesForce/README.md
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@

# SalesForce Custom Column Bambdas

## GetApexMethod
Extracts the `method` value from calls to `api/apex/execute` when its passed in via query string in GET or JSON in POST.

![getApexMethod](images/image.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1e098ee

Please sign in to comment.