You need to sign in to do that
Don't have an account?
Steve F
List has no rows for assignment
Hi guys, I am new to APEX, and I am trying to create a class to access via REST.
Please let me know what I am doing wrong here:
I am going by this sample:
https://youtu.be/C64pLdXmEoo
Any help is appreciated,
Thank you.
Steve
Please let me know what I am doing wrong here:
@isTest(SeeAllData = true) @RestResource(urlMapping='/v1/cases/*') global with sharing class REST_getCases_V1 { @HttpGet global static Case doGet() { RestRequest req = RestContext.request; RestResponse res = RestContext.response; String caseId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1); Case result = [select CaseNumber, status from case where CaseNumber = :caseId]; <<---Line 14 return result; } }
error: System.QueryException: List has no rows for assignment to SObject Class.REST_getCases_V1.doGet: line 14, column 1
I am going by this sample:
https://youtu.be/C64pLdXmEoo
Any help is appreciated,
Thank you.
Steve
Let us know if this will help u
All Answers
First, does caseId have a value?
Second, use Case[] result.
Third...what's line14?
This error comes when you query doesn't return any rows.
Updated your code.
1) No need to seeAllData here
2) Make sure will pass valid case number
3) Update your code like below
I tested above code in my developer org which is working fine
NOTE:- please pass the valid case number for result
Let us know if this will help you
Just for testing I modified the query and removed the where but I still only get one record back.
Let us know if this will help u
So how do I access this from the outside? Like using postman? How do I authenticate to access my class? Do I need to write a new class to login? Do you have any samples?
Steve