Skip to content

Instantly share code, notes, and snippets.

View megasmack's full-sized avatar
☁️

Steve Schrab megasmack

☁️
View GitHub Profile
@megasmack
megasmack / B2BCheckout.cls
Last active August 1, 2025 22:45
APEX Method to update cartDeliveryGroups
public without sharing class B2BCheckout {
@AuraEnabled
public static CartDeliveryGroup setPickupInformation(String notes, String pickupTime, Id cartDeliveryGroupId) {
CartDeliveryGroup cartDeliveryGroup = [
SELECT Id, DeliveryMethodId
FROM CartDeliveryGroup
WHERE Id =: cartDeliveryGroupId
];
Datetime desiredDeliveryDate = Datetime.valueOfGmt(pickupTime.replace('T', ' '));
cartDeliveryGroup.ShippingInstructions = notes;
@megasmack
megasmack / addItemsWithCustomFieldToCart.js
Created July 16, 2025 18:15
Add Item(s) to Cart with Custom Fields using the commerce/cartApi in Salesforce Core Commerce
// Using add itemS to cart from the commerce/cartApi
import { addItemsToCart } from "commerce/cartApi";
// Set up an array as a payload.
const payload = [{
productId: this.productId,
quantity: this.quantity,
type: "Product"
}];
@megasmack
megasmack / fetchCommerceUrl.js
Created July 13, 2025 13:06 — forked from nocrates/fetchCommerceUrl.js
From B2BCommerce (Commerce on Core) for Salesforce, using the LWC (Lightning Web Component) within the LWR, this gist will call a commerce-api URL with the session credentials of the running user.
/* Returns a promise */
fetchCommerceUrl(url) {
let apiver = 'v64.0';
let commercebase = '/webruntime/api/services/data/' + apiver + '/commerce';
let fullurl = commercebase + url;
console.log('Begin fetchCommerceUrl on ', fullurl);
return fetch(fullurl, {
method: 'GET',
@megasmack
megasmack / input-patterns.md
Last active September 24, 2025 13:38
HTML Input patterns

HTML Pattern Reg Ex input patterns

Zip Code

pattern="/^\d{5}(?:-\d{4})?$/"

Email Address

pattern="[^@\s]+@[^@\s]+\.[^@\s]+"

@megasmack
megasmack / log.js
Last active July 10, 2025 16:38
LWC Commerce get API Methods Available.
import checkoutApi from "commerce/checkoutApi";
import cartApi from "commerce/cartApi";
console.log("cartApi:", cartApi);
console.log("cartApi keys:", Object.keys(cartApi));
// Optional: Log function names individually
Object.keys(cartApi).forEach((key) => {
console.log(`cartApi[${key}] =`, cartApi[key]);
});
@megasmack
megasmack / viewTransition.js
Created April 17, 2025 13:58
A startViewTransition wrapper method.
/**
* Wraps the startViewTransition to check avialability and reduced motion settings.
* Usage: await viewTransition(() => {this.showElement = true});
* @param {Function} callback - callback to function that triggers the animation.
* @returns {Promise<unknown>} - Finish transition.
*/
export const viewTransition = (callback) => {
return new Promise((resolve) => {
const mediaQuery = window.matchMedia('(prefers-reduced-motion)');
const isReducedMotion = mediaQuery.matches;
@megasmack
megasmack / SEO-Social-Media-Experience-Cloud.md
Last active January 22, 2024 14:27
SEO and Social Media Meta Tag Setup for Experience Cloud Sites

SEO and Social Media Meta Tag Setup for Experience Cloud Sites

About Meta Tags

Meta Tags are HTML tags hidden within the header of a web page. These tags contain information about your page. For example: a title, a brief description, and images.

When a social media channel receives a URL, behind the scenes it goes to this URL to try and gather information about this page. While most channels do their best to figure out what title or image to display from the page itself, we can be more explicit by setting up meta tags. If these meta tags are present, the channel will use them first.

Setting up Meta Tags in Salesforce Communities

@megasmack
megasmack / README.md
Last active June 2, 2023 19:01
Salesforce VSCode LWC Snippets

Salesforce VSCode LWC Snippets

Some handy VSCode snippets I've found helpful for LWC development in Salesforce.

@megasmack
megasmack / browserNotificationsExample.js
Created April 26, 2023 18:57
LWC Browser Notifications
import { LightningElement } from 'lwc';
export default class BrowserNotificationsExample extends LightningElement {
connectedCallback() {
this.initPushNotifications();
}
// Modified from: https://levelup.gitconnected.com/creating-browser-notification-in-javascript-79e91bfb76c8
initPushNotifications() {
@megasmack
megasmack / daylightsavings.js
Created March 27, 2023 20:39
Daylight Savings JavaScript Test
const stdTimezoneOffset = (date) => {
const jan = new Date(date.getFullYear(), 0, 1);
const jul = new Date(date.getFullYear(), 6, 1);
return Math.max(jan.getTimezoneOffset(), jul.getTimezoneOffset());
};
const isDstObserved = (date) => date.getTimezoneOffset() < stdTimezoneOffset(date);
const offset = start.getTimezoneOffset();
const start = new Date(start.getTime() - (offset*60*1000));