Building a Real-Time Train Status Tracker with Salesforce LWC and Apex
Building a Real-Time Train Status Tracker with Salesforce LWC and Apex
Step 1: Setting Up Remote Site Settings
To begin, we need to set up remote site settings in Salesforce to allow external API calls.
- Navigate to Setup in Salesforce.
- Search for Remote Site Settings in the Quick Find box.
- Click New Remote Site.
- Enter the following details:
- Remote Site Name: TrainStatusAPI
- Remote Site URL:
https://rappid.in
- Click Save.
Step 2: Creating the Apex Class
Next, we'll create an Apex class to make an API call and fetch train details.<template>
<lightning-card title="Train Info-Running Status" variant="narrow" icon-name="custom:custom36"><div class="slds-p-around_small"><lightning-input type="text" required="true" label="Enter Train Number" onchange={handleInputChange} placeholder="e.g 12312, 12302, 12704, 12321, 12303......"></lightning-input></div><div class="slds-p-around_small slds-p-left_large"><lightning-button label="Get Train Info" variant="Brand" onclick={handleTrainInfo}></lightning-button></div><template lwc:if = {showSpinner}><lightning-spinner alternative-text="Loading"></lightning-spinner></template><template lwc:if = {showTrainDetails}><div class="slds-p-left_small"><div class="slds-text-heading_large slds-text-color_success">{trainDetails.train_name}</div><div class="slds-text-title">{trainDetails.updated_time}</div><div class="slds-p-top_x-small" style="height: 300px;"><lightning-datatablekey-field="train_name"data={trainDetails.data}columns={columns}hide-checkbox-column="true"></lightning-datatable></div></div></template></lightning-card></template>
Step 3: Creating the LWC Component
We'll now create an LWC to input the train number and display the live status.
Conclusion
By following these steps, you have successfully created a real-time train running
status tracker in Salesforce using Lightning Web Components and Apex.
This project not only demonstrates API integration but also enhances your
skills in building responsive UI components with LWC.
Call to Action
If you found this tutorial helpful, please like, share, and subscribe for more
Salesforce development content. If you have any questions or feedback,
feel free to leave a comment below.
Tags:
#Salesforce #LWC #Apex #TrainStatus #APIIntegration #SalesforceTutorial #LightningWebComponents #RealTimeData
Comments
Post a Comment