0

I added the following VF page

<apex:page standardController="Account" extensions="createaccount" title="Test">
    <apex:outputText value="{makePostCallout}"/>
</apex:page>

this is my apex class

public class createaccount {
    public static HttpResponse makePostCallout() {
        Http http = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://xxxxx.azure-api.net/xxxxxxxxx');
        request.setMethod('POST');
        request.setHeader('Content-Type', 'application/json;charset=UTF-8');
        // Set the body as a JSON object
        request.setBody('{{"system_id": "xyz"}}');
        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 {
            System.debug(response.getBody());
            }
        return response;
    }
}

in the developer console, I get the error

unknown constructor

Also When I go to create a custom button in Account object, I do not see this appearing in the drop-down list

0

With all changes suggested by sebastian(except outputtext to button), you need to have a constructor with standardcontroller, then only you'll be able to see VF button while creating button on object.

Like below -

public createaccount(ApexPages.StandardController stdController) {
        
}
1
  • 1
    I did not realize this was a standard controller. Good catch. – Sebastian Kessel Jul 16 '20 at 3:36
0

apex:outputText is not for buttons, it is for text.

Use apex:commandButton for a button

Also, This is visualforce, not LWC. You must use the "curly-bang" method.

Instead of {makePostCallout}, write {!makePostCallout}

So, in summary, your code should read

<apex:page standardController="Account" extensions="createaccount" title="Test">
    <apex:commandButton value="{!makePostCallout}"/>
</apex:page>
1
  • He is creating a button in configuration level(not on VF page) – Ysr Shk Jul 16 '20 at 3:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.