Skip to main content
1 risposta
  1. 24 lug 2024, 16:17

    Hi,

     

    try this approach this will help you.

     

     To achieve the desired functionality, you'll need to create a custom action in Salesforce that allows users to scan the tag_id, look up the corresponding asset_id, and then update the bin_id in the Asset object. Here are the steps to implement this solution: 

     

    Step 1: Create a Visualforce Page or Lightning Component

     

    <apex:page controller="TagScanController">

    <apex:form>

    <apex:pageBlock title="Scan Tag">

    <apex:pageBlockSection>

    <apex:inputText value="{!tagId}" label="Tag ID" />

    <apex:commandButton value="Submit" action="{!updateBinId}" />

    </apex:pageBlockSection>

    </apex:pageBlock>

    </apex:form>

    </apex:page>

    Step 2: Create the Apex Controller

    public class TagScanController {

    public String tagId { get; set; }

    public void updateBinId() {

    if (String.isNotBlank(tagId)) {

    // Lookup the asset_id using tag_id

    Tracking_Tag__c tag = [SELECT Asset_Id__c FROM Tracking_Tag__c WHERE Tag_Id__c = :tagId LIMIT 1];

    if (tag != null) {

    // Get the current Bin ID from the Asset

    Bin_Assets__c asset = [SELECT Bin_Id__c FROM Bin_Assets__c WHERE Id = :tag.Asset_Id__c LIMIT 1];

    if (asset != null) {

    // Update the Bin ID in the Asset

    asset.Bin_Id__c = 'NEW_BIN_ID'; // Replace 'NEW_BIN_ID' with the desired Bin ID

    update asset;

    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Bin ID updated successfully.'));

    } else {

    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Asset not found.'));

    }

    } else {

    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Tag not found.'));

    }

    } else {

    ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Tag ID cannot be blank.'));

    }

    }

    }

    Step 3: Add the Action to the Bin Record Page

    Add the Visualforce page or Lightning component to the Bin record page layout to make it easily accessible.

     

    Thanks

    Bablu Pandit

0/9000