You need to sign in to do that
Don't have an account?
Ben Males
Apex Class POST Method help
Hi All,
I have the below Apex code running via a button on the Contact page
I'd greatly appreciate if anyone can advise me where I've gone wrong in the above as the non-Apex version of the code is running sucessfully through Postman.
Kind regards
I have the below Apex code running via a button on the Contact page
public with sharing class auto_sendSMS { public String phone {get;set;} public auto_sendSMS(ApexPages.StandardController stdController) { Contact contact = (Contact)stdController.getRecord(); contact = [SELECT Id, phone from contact where Id = :contact.Id]; String username = 'apiUser'; String password = 'z448rcqAQ7w55ySK'; String fromID = 'Cirrus'; String dest = contact.phone; String body = 'API test'; String requestEndpoint = 'https://auto.cirrusresponse.com/auto_sendSMS.asp'; requestEndpoint += '?u=' + username; requestEndpoint += '&p=' + password; requestEndpoint += '&fromID=' + fromID; requestEndpoint += '&dest=' + dest; requestEndpoint += '&body=' + body; Http http = new http(); HttpRequest request = new HttpRequest(); request.setEndpoint(requestEndpoint); request.setMethod('POST'); HttpResponse response = http.send(request); } }I have set the remote site settings for the endpoint, but the request is never received.
I'd greatly appreciate if anyone can advise me where I've gone wrong in the above as the non-Apex version of the code is running sucessfully through Postman.
Kind regards
I have tried with the amended code and the result is the same.
If I take the code and execute via anonymous window there is nothing shown under the Debug only option either.
In the Visualforce page I have tried to add the variables to see if they are returned as expected and I only see the variable name, not the value - not sure if this would have an impact on the Apex code executing however?
Kind regards
Make sure your button looks like that /apex/vfpname?id={!Contact.Id}
Make sure your button looks like that /apex/vfpname?id={!Contact.Id}
Is this a setting I need add to the custom button itself? I looked at the button, but couldn't see where to add this code.
The button sits on the Contact record as below
Kind regards
That's custom contact deatil page button with link to visualforce page in code yes?
Correct, this is a custom button with a link to the Visualforce page as per the below:
Kind regards
Visualforce Error
System.LimitException: @future call currently not allowed
Class.auto_sendSMS.<init>: line 4, column 1
Currently receiving the above error with the revised code and modified page.
Kind regards
Visualforce Error
System.LimitException: @future call currently not allowed
Class.auto_sendSMS.<init>: line 4, column 1
Thanks