0

I want to get the user related events based on userid I'm trying to retrieve the event details. Here my query is:

List<Event> events = [SELECT Subject,StartDateTime,EndDateTime FROM Event WHERE OwnerId =:userinfo.getUserId()];

I'm trying to expose through REST API. How can I pass the UserId to RestRequest like here

String OwnerId =req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);

but how to link those two? For checking I'm using workbench by passing the user id I'm getting the event details related to that user but it won't display anything.

  • Are you just trying to set up a REST endpoint that will find the Event records owned by a specified user? – Adrian Larson Nov 4 '16 at 16:17
  • yes,that's the requirement – chandra Nov 4 '16 at 16:18
1

You just need to change your query to use the string you parsed out.

String ownerId = req.requestURI.substringAfterLast('/');
List<Event> events = [SELECT ... FROM Event WHERE OwnerId = :ownerId];

Then you would need to make sure you hit an endpoint that does indeed terminate with /<some_user_id>.

  • Thank you so much Adrian it works properly but it returns only one event details how to retrieve all events related to that particular userid – chandra Nov 4 '16 at 16:28
  • Are you sure there is more than one Event for the specified User? Are you sure the User you're running the query as can access those records? – Adrian Larson Nov 4 '16 at 16:29
  • yes just now i created two events for a user based on that user id i'm getting only one event how to overcome this.i want to retrieve all. – chandra Nov 4 '16 at 16:35

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.