---
schema_version: "1"
id: 5a21411c8d4fff3ab2c454331fd6564ba20e631a4389f8c267fee29142b54743
title: Dynamically Assign Buyer Groups by Using Apex Logics
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/commerce/264-0-0/comm_buyer_groups_using_apex_logics.md
canonical_url: https://help.salesforce.com/s/articleView?id=commerce.comm_buyer_groups_using_apex_logics.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: d749b7827b6a7ae2a7c88918d845e68f507e85687a912854b3baaff1155c6e91
description: Dynamically assign guest and authenticated buyers to buyer groups for a B2B store by using custom Apex logics. When buyers visit the store pages, the Apex logic adds them to a buyer group based on the defined criteria. Assigning buyers dynamically when they visit a storefront ensures timely, personalized shopping experiences including targeted product visibility, pricing, and promotions, without manual intervention.
products:
  - Commerce
  - B2B Commerce
release: "264"
---
# Dynamically Assign Buyer Groups by Using Apex Logics

Dynamically assign guest and authenticated buyers to buyer groups for a B2B store by using custom Apex logics. When buyers visit the store pages, the Apex logic adds them to a buyer group based on the defined criteria. Assigning buyers dynamically when they visit a storefront ensures timely, personalized shopping experiences including targeted product visibility, pricing, and promotions, without manual intervention.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;"><a href="https://help.salesforce.com/s/articleView?id=commerce.comm_editions.htm&amp;language=en_US" target="_blank">View supported editions</a>.</td></tr></tbody></table>

[Which Salesforce Commerce Product Do I Have?](https://help.salesforce.com/s/articleView?id=commerce.comm_what_product.htm&language=en_US)

![Important](https://sf-zdocs-cdn-prod.zoominsoftware.com/tdta-commerce-comm-264-0-0-production-enus/d863e308-482a-4dfa-8d20-2a94737d394a/images/icon_important.png)

Important For D2C stores, this feature works only if you've configured a custom checkout experience.

1. In the navigation sidebar, select a store from the **Store** dropdown.
2. Select **Settings** | **Store**.
3. Click the **Buyer Access** tab.
4. Enable Buyer Group Extension.
5. In the Buyer Group Extension tile, click **Select Provider**. Choose a provider and select your custom Apex class.
6. Click **Next** and then confirm your selection.
7. To change or remove the provider, use the dropdown menu on the extension tile.
    
    The Apex logic runs each time a shopper visits a page in your store and assigns them to a buyer group based on the criteria you’ve defined.

#### See Also

- [BuyerGroupEvaluationService Class](https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_CommerceBuyGrp_BuyerGroupEvaluationService.htm)
- [Considerations for Buyer Group Extension](https://help.salesforce.com/s/articleView?id=commerce.comm_buyer_group_extensibility_considerations.htm&release=264.0.0&type=5 "As you turn on buyer group extension, keep these considerations in mind.")
- [Add Accounts to a Buyer Group for a B2B Store](https://help.salesforce.com/s/articleView?id=commerce.comm_add_buyer_accounts_to_buyer_group.htm&release=264.0.0&type=5 "To give multiple accounts access to the same store, price books, and entitlements, create a buyer group and add the accounts.")
- [Associate a Buyer Group with a B2B Store](https://help.salesforce.com/s/articleView?id=commerce.comm_buyer_groups.htm&release=264.0.0&type=5 "Product prices and the products that buyers can access depend on the price books and the entitlement policies assigned to the buyer group. When you create a store, a default buyer group is assigned to the store.")
- [Shopper Buyer Groups and Accounts Data Limits Groups](https://developer.salesforce.com/docs/commerce/salesforce-commerce/guide/b2b-b2c-comm-data-model-shopper-buyer-groups-accounts-limits.html)
- [Considerations for Market and Buyer Group Setup for B2B Commerce Stores](https://help.salesforce.com/s/articleView?id=commerce.comm_market_considerations.htm&release=264.0.0&type=5 "As you set up your market and buyer groups, keep these considerations in mind.")
- [Configure Custom Checkout for a B2B Store](https://help.salesforce.com/s/articleView?id=commerce.comm_custom_checkout.htm&release=264.0.0&type=5 "Custom checkout gives you more control over your store’s checkout configuration. You can use third-party apps instead of Salesforce’s native merchant services for payments, tax, and shipping. Or, you can extend native merchant services using custom checkout. You can design your own checkout page in Experience Builder with preset layouts, custom sections, and components. For B2B stores, custom checkout is the only option for configuring checkout.")
- [Considerations for the Salesforce CDN](https://help.salesforce.com/s/articleView?id=platform.community_builder_cdn_considerations.htm&language=en_US)
- [Considerations for Salesforce Edge Network](https://help.salesforce.com/s/articleView?id=xcloud.domain_name_edge_network_considerations.htm&language=en_US)