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
Sai chandra 2Sai chandra 2 

How can I include a tab that calls an apex class

You basically have to create a VF Page with you apex class as the controller.
You then set up your code to run at load, and end up in re-directing the user to where you want them to end when done...

Sample VF Code:
<apex:page standardController="Accodnt"
  <apex:sectionHeader title="Auto-Running Apex Code"/>
  <apex:outputPanel >
      You tried calling Apex Code from a tab.  If you see this page, something went wrong.  You should have
      been redirected somewhere.

And the Apex would look something like this:

public class SomeApexController{

    // Code we will invoke on page load.
    public PageReference autoRun() 
        Do stuff...

        // Redirect the user back to the original page
        PageReference pageRef = new PageReference('/' + somewhere);
        return pageRef;

Good luck!
Sai chandra 2Sai chandra 2

But my Apex class looks some what different

public class AnimalsCallouts {
    public static HttpResponse makeGetCallOut(){
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        HttpResponse response = http.send(request);
        // If the request is successful, parse the JSON response.
        if (response.getStatusCode() == 200) {
            // Deserializes the JSON string into collections of primitive data types.
            Map<String, Object> results = (Map<String, Object>) JSON.deserializeUntyped(response.getBody());
            // Cast the values in the 'animals' key as a list
            List<Object> animals = (List<Object>) results.get('animals');
            System.debug('Received the following animals:');
            for (Object animal: animals) {
        return response;
    public static HttpResponse makePostCallout() {
        Http http = new Http();
        HttpRequest request = new HttpRequest();
            request.setHeader('Content-Type', 'application/json;charset=UTF-8');
            request.setBody('{"name":"mighty moose"}');
            HttpResponse response = http.send(request);
            // Parse the JSON response
            if (response.getStatusCode() != 201) {
                System.debug('The status code returned was not expected: ' +
                    response.getStatusCode() + ' ' + response.getStatus());
            } else {
            return response;

For this what is the VF page code need to be written
There is no PageReference in this code


Can you explain what you are trying to do here?
When the user clicks on a tab - you want this code to run - but what does the user see after it runs? Should he be navigated back home?
Should there be some kind of confirmation that the task has been completed? I assume that would be required, as otherwise the user may think nothing happened...

Sai chandra 2Sai chandra 2
If we debug that code we will be getting JSON response
I need to get that JSON response when I click on the tab
Do you mean you want to get that Jason response on the screen?
Sai chandra 2Sai chandra 2
Yes I need that JSON response on the screen