Dynamic Scale for Currency Field in Salesforce?

Dynamic Scale for Currency Field in Salesforce?

On March 10, 2025, Posted by , In Apex,Salesforce, With Comments Off on Dynamic Scale for Currency Field in Salesforce?

Question

How to Correctly Create a Transaction Security Policy via the Tooling API?

I am attempting to create a Transaction Security Policy using the Tooling API, but I’m facing challenges with the JSON structure. I’ve tried several variations, but none seem to work. Below are my attempts and the errors I encountered:

Attempt 1

JSON:

{
    "FullName": "SL_Credential_Stuffing_Ev",
    "Metadata": {
        "active": true,
        "apexClass": "MyClass",
        "action": {
            "block": false,
            "endSession": false,
            "freezeUser": false,
            "notifications": [
                {
                    "inApp": false,
                    "sendEmail": false,
                    "user": "bill@salesforcexox.com"
                }
            ],
            "twoFactorAuthentication": false
        }
    }
}

Error

{
    "message": "Missing required field - EventName",
    "errorCode": "FIELD_INTEGRITY_EXCEPTION",
    "fields": []
}

Attempt 2 (Added eventName inside Metadata)

JSON:

{
    "FullName": "SL_Credential_Stuffing_Ev",
    "Metadata": {
        "eventName": "CredentialStuffingEventStore",
        "active": true,
        "apexClass": "MyClass",
        "action": {
            "block": false,
            "endSession": false,
            "freezeUser": false,
            "notifications": [
                {
                    "inApp": false,
                    "sendEmail": false,
                    "user": "bill@salesforcexox.com"
                }
            ],
            "twoFactorAuthentication": false
        }
    }
}

Error

{
    "message": "Cannot deserialize instance of complexvalue from VALUE_STRING value CredentialStuffingEventStore or request may be missing a required field",
    "errorCode": "JSON_PARSER_ERROR"
}

My Questions:

  1. What is the correct JSON structure for creating a Transaction Security Policy using the Tooling API?
  2. How should the EventName field be included to avoid these errors?
  3. Are there any fully working examples of a Transaction Security Policy created via the Tooling API?

Answer

Creating a Transaction Security Policy through the Tooling API involves sending a POST request to the /services/data/vXX.0/tooling/sobjects/TransactionSecurityPolicy/ endpoint. The JSON payload for creating the policy should include the correct format and parameters. Here’s an example of how the JSON structure should look:

{
  "MasterLabel": "Example Policy",
  "Description": "This is a sample Transaction Security Policy created via Tooling API.",
  "PolicyAction": "LOCKOUT", 
  "ConditionLogic": "AND",
  "Conditions": [
    {
      "Field": "UserIp",
      "Operator": "IN",
      "Value": "192.168.1.0/24"
    },
    {
      "Field": "UserAgent",
      "Operator": "CONTAINS",
      "Value": "Mobile"
    }
  ],
  "Enabled": true
}

Here’s a breakdown of the fields:

  • MasterLabel: A label for the policy.
  • Description: A description of what the policy does.
  • PolicyAction: Defines the action taken if the conditions are met (e.g., LOCKOUT, ALERT).
  • ConditionLogic: Defines how conditions should be evaluated (AND or OR).
  • Conditions: An array of conditions to be met (e.g., IP address range, user agent string).
  • Enabled: A flag to enable or disable the policy.

In the example above, the policy locks out users who attempt to log in from a specific IP range and also have a “Mobile” user agent.

Troubleshooting Tips:

  1. Check the API version: Ensure that you’re using the correct version of the Tooling API that supports Transaction Security Policies.
  2. Correct Object Types: Make sure you’re passing the right object type for each field (for example, the “UserIp” field should contain valid IP address ranges).
  3. Enable the Feature: Ensure that the Transaction Security feature is enabled in your Salesforce org before creating policies.
  4. Validate Condition Operators: Check that the operators (e.g., IN, CONTAINS) are correctly used for the fields you are targeting.

By ensuring these points, you should be able to create a Transaction Security Policy using the Tooling API.

Summary

To create a Transaction Security Policy using the Tooling API, you need to send a POST request to the /services/data/vXX.0/tooling/sobjects/TransactionSecurityPolicy/ endpoint with the appropriate JSON structure. The JSON should include fields like MasterLabel, Description, PolicyAction, ConditionLogic, Conditions, and Enabled.

Example JSON includes conditions like checking the user’s IP range and user agent. Troubleshooting tips include verifying the correct API version, using the proper object types for each field, enabling the Transaction Security feature in your Salesforce org, and ensuring correct condition operators are used.

Real-Time Project-Based Salesforce Course

Our Salesforce training provides a comprehensive and immersive learning experience, giving you the necessary skills to excel in the CRM industry. The program covers vital areas such as Salesforce Admin, Developer, and AI, combining thorough theoretical knowledge with practical, hands-on experience. Through live projects and assignments, you’ll gain the expertise to address complex business challenges with Salesforce solutions. Our expert instructors are committed to helping you develop both technical proficiency and valuable industry insights.

In addition to technical training, our Salesforce training in Dubai offers personalized mentorship, exam preparation guidance, and interview readiness to ensure you stand out in a competitive job market. You’ll have access to detailed study resources, real-world project exposure, and continuous support throughout your learning journey. By the time you complete the course, you’ll be fully prepared for certification exams and equipped with the practical skills and problem-solving abilities that employers look for. Start your Salesforce career with us and open the door to exciting career opportunities! Enroll for FREE Demo!

Comments are closed.