You need to sign in to do that
Don't have an account?
sfdc007
[{"message":"Session expired error
Hi,
I need help on the following requirement as follows,
I have a visualforce page where i have a button in it , when i click the button it is calling my REST API apex class where i am passing the opportunity id and it should display
but when i click on the button i am getting the following error as follows
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]
Let me know what i should do to resove it , i need to display the opportunity record alone on clik of that button through rest api
Help me pls
Thanks in Advance
I need help on the following requirement as follows,
I have a visualforce page where i have a button in it , when i click the button it is calling my REST API apex class where i am passing the opportunity id and it should display
but when i click on the button i am getting the following error as follows
[{"message":"Session expired or invalid","errorCode":"INVALID_SESSION_ID"}]
Let me know what i should do to resove it , i need to display the opportunity record alone on clik of that button through rest api
MY VF PAGE : <apex:page controller="getservice2"> <apex:form > <apex:commandButton action="{!getResult}" value="REST API" id="theButton"/> <br/><br/> {!myresponse} </apex:form> </apex:page>
MY REST API CLASS : @RestResource(urlMapping='/opportunity/*') global with sharing class MyRestResource { @HttpGet global static opportunity doGet() { RestRequest req = RestContext.request; RestResponse res = RestContext.response; //String opportunityId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1); opportunity result = [SELECT Id, Name,Account.name,owner.name FROM opportunity WHERE Id = '00628000004KwQ0']; return result; } @HttpPost global static String doPost(String name, String phone, String website) { opportunity opportunity = new opportunity(); opportunity.Name = name; insert opportunity; return opportunity.Id; } }
MY APEX CLASS WHERE MY REST API CONTTOLLER IS REFERRED : public class getservice2 { public String myresponse{get;set;} public Pagereference getResult() { HttpRequest req = new HttpRequest(); Http http = new Http(); req.setMethod('GET'); String url = 'https://ap2.salesforce.com/services/apexrest/opportunity'; req.setEndpoint(url); HTTPResponse resp = http.send(req); myresponse=resp.getBody(); return null; } }
Help me pls
Thanks in Advance
Try with the below updated code
Controller Class with REST request
Visualforce page
All Answers
Try with the below updated code
Controller Class with REST request
Visualforce page