dynamic row actions javascript

<script type="text/javascript">
  // Define KYC_COLUMNS
  const KYC_COLUMNS = [
    {
      fieldName: "legalEntity",
      type: "customText",
      label: "Legal Entity",
      typeAttributes: {
        rowId: { fieldName: "id" },
        label: { fieldName: "legalEntityText" },
        content: { fieldName: "legalEntity" },
        hideHelpComponent: true,
        showUrl: { fieldName: "showUrl" }
      }
    },
    {
      label: "Booking Location",
      fieldName: "bookingLocation"
    },
    {
      label: "Stage",
      fieldName: "stage"
    },
    {
      label: "Status",
      fieldName: "status"
    },
    {
      type: "action",
      typeAttributes: {
        rowActions: { fieldName: "dynamicActions" }
      }
    }
  ];

  // Example raw data
  const rawData = [
    {
      id: '1',
      legalEntity: 'Entity A',
      bookingLocation: 'NYC',
      stage: 'Stage 1',
      status: 'Active'
    },
    {
      id: null,
      legalEntity: 'Entity B',
      bookingLocation: 'LA',
      stage: 'Stage 2',
      status: 'Pending'
    },
    {
      id: '3',
      legalEntity: 'Entity C',
      bookingLocation: 'SF',
      stage: 'Stage 3',
      status: 'Inactive'
    }
  ];

  // Add dynamicActions based on rowId presence
  const enrichedData = rawData.map(row => {
    let actions = [];

    if (!row.id) {
      actions.push({ label: 'OnbLE', name: 'onbLE' });
    } else {
      actions.push({ label: 'Edit', name: 'edit' });
      actions.push({ label: 'Delete', name: 'delete' });
    }

    return {
      ...row,
      dynamicActions: actions
    };
  });

  // Output to console
  console.log("Columns:", KYC_COLUMNS);
  console.log("Data with dynamic actions:", enrichedData);
</script>

public static List searchLegalEntities(String caseId, String searchTerm) {
    // Get the account ID from the Case
    Case c = [SELECT Id, AccountId FROM Case WHERE Id = :caseId LIMIT 1];

    // Sanitize search term
    String safeTerm = String.escapeSingleQuotes(searchTerm);

    // SOSL must search across multiple objects or fields, so we include NAME field
    List> searchResults = Search.query(
        'FIND \'' + safeTerm + '*\' IN NAME FIELDS RETURNING Legal_Entity__c(Id, Name, company_name__c)'
    );

    // Filter by company_name__c after SOSL if needed
    List entities = (List) searchResults[0];

    // Filter only those matching the Case's Account
    return entities.where(e => e.company_name__c == c.AccountId);
}





public static String filterJsonResultsByAccount(String caseId, String serializedResults) {
    // Get the AccountId from the Case
    Case c = [SELECT Id, AccountId FROM Case WHERE Id = :caseId LIMIT 1];

    // Deserialize the JSON string to a list of maps
    List<Object> rawList = (List<Object>) JSON.deserializeUntyped(serializedResults);
    List<Map<String, Object>> filtered = new List<Map<String, Object>>();

    for (Object obj : rawList) {
        Map<String, Object> entry = (Map<String, Object>) obj;

        // Check if IdentifierField matches the Case's AccountId
        if (entry.containsKey('IdentifierField') && entry.get('IdentifierField') != null) {
            String idField = (String) entry.get('IdentifierField');
            if (idField == c.AccountId) {
                filtered.add(entry);
            }
        }
    }

    // Return the filtered list as a JSON string
    return JSON.serialize(filtered);
}
dynamic row actions javascript dynamic row actions javascript Reviewed by dasfrogpractice on 07:57 Rating: 5

No comments:

Theme images by mariusFM77. Powered by Blogger.
Youtube Channel Image
Dasfrog Subscribe To watch more Salesforce Training
Subscribe