function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
hjv6606hjv6606 

External API call on page load

Hello,

I am trying to accomplish the following:
  • Call an external REST API on Account page load
  • JSON response will be parsed into a table within a custom object
I have already coded the REST call in apex. How do I get this to interact with a custom object and run on page load? Do I need to use visualforce? I am having some trouble understaing how all of these elements interact, so any guidance would be helpful. Thanks!
Best Answer chosen by hjv6606
SRKSRK

no if you are using lightning 

then just create a lighitng componet 

 

<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId" access="global" > 

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

</aura:component/>

in you JS file

({
    doInit: function(component, event, helper) {
        console.log(component.get("v.recordId"));
        helper.mymethod(component);
     },
})

helper

mymethod: function(component) 
    {
var action = component.get("c.GetAccountInfo");  // call your apex class method 
            action.setParams({
                AccountId : component.get("v.recordId") // pass the paramters 
            });
            action.setCallback(this, function(a) {
                           //handel the responce
                 }
$A.enqueueAction(action);

}

All Answers

SRKSRK

So i assume from "Account page load" you mean when ever standard account page layout load ?
You are using lighting or standard ?

 

you can add a VF page or lighitng component in standard page layout and call you apex code on load of VF / lighting component

hjv6606hjv6606
That's correct, The standard account page. We are using lightning. Is there any advantage in using VF over a lightning component in this scenario?
SRKSRK

if you are in classic then you can create a VF page and use account as standard controller in that VF page, that will allow you to use that VF page to add inside standard pagelayout

 

if you are using lighitng then you can just edit the page and drag you lighitng component on right side panael 

you have to make sure your lighitng component  implement  
If your component is available for both record pages and any other type of page, implement flexipage:availableForAllPageTypes.
If your component needs the record ID, also implement the force:hasRecordId interface

SRKSRK

no if you are using lightning 

then just create a lighitng componet 

 

<aura:component implements="flexipage:availableForAllPageTypes,force:hasRecordId" access="global" > 

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>

</aura:component/>

in you JS file

({
    doInit: function(component, event, helper) {
        console.log(component.get("v.recordId"));
        helper.mymethod(component);
     },
})

helper

mymethod: function(component) 
    {
var action = component.get("c.GetAccountInfo");  // call your apex class method 
            action.setParams({
                AccountId : component.get("v.recordId") // pass the paramters 
            });
            action.setCallback(this, function(a) {
                           //handel the responce
                 }
$A.enqueueAction(action);

}

This was selected as the best answer
hjv6606hjv6606
Thank you for your detailed response. So, I will be creating a lightninig component that will define a table, then creating a JS file that will call the apex class to populate the table?
SRKSRK
yup that should solve it 
 
hjv6606hjv6606
Thank you so much for your patience and answer! Marking as solved/answered