Тёмный

System.QueryException: List has no rows for assignment to SObject | Salesforce troubleshooting error 

SFDC Quest
Подписаться 2,1 тыс.
Просмотров 3,1 тыс.
50% 1

Apex error 'List has no rows for assignment to SObject' | System.QueryException: List has no rows for assignment to SObject | Salesforce troubleshooting errors series
#List has no rows for assignment to SObject #troubleshooting #sfdcquest #salesforce
Topic
=======================
00:00 System.QueryException: List has no rows for assignment to SObject
Description
The following query is not returning any number of records:
select id, name from account where name ='test123'
The error "List has no rows for assignment to SObject" occurs when query doesn't return any rows.
Resolution
While a SELECT normally returns an array/list, these statements are using the shorthand syntax that assumes only one row is returned. What’s not obvious is that it also assumes that exactly one row is returned!
Although this is unlikely to occur for Contact, it is highly likely to occur for any custom objects you create, especially when a WHERE statement is used that might return zero rows, such as:
account a = [select id, name from account where name ='test123']
The above code will fail if there is no account record with the matching username. It doesn't actually return a null.
It would be safer to do the following:
account [] lstacc = [select id, name from account where name ='test123'];
It’s one of those situations for which you would not normally think of creating a test, so it’s safer to just avoid the possibility.
Please refer to the below link for information.
help.salesforce.com/s/article...
=====================================
Join us on Telegram: t.me/sfdcquest
=========================================
Learn apex 20% and code 80% is out now!! grab your copy now!!!!
👉👉👉👉amzn.to/3qYH6fs
learning apex is made easy for beginners.
===========/////////////////////====================
* Real-time scenarios with project examples.
* Step by step, know-how developers read and code requirements with value-added examples.
*20+ commonly used project requirements hands-on examples for you to try with answers.
* read and learn in less than 2 hrs.
* tips and processes to remember the syntax.
* get grip on apex concepts used 80% times.
* know why before how of the concept.
* learn how to break the requirements in coding.
* change your mindset towards coding.
* Get all the above points in one place.
Check out our book on Amazon. Link in description.
👉👉👉👉amzn.to/3qYH6fs
=============+++++++++++========================
👇👇👇👇👇👇👇👇👇👇👇
Grab your apex cheat sheet !!!!
Do you struggle with Apex syntax?
You know which concept to use but end up searching on the internet for syntax.
or
do you struggle with which concept to use when writing apex code?
if the answer is yes, this guide is for you. 100+ students found this useful when writing apex code.
Grab your copy now!!! ⏰⏰⏰⏰
rspcloudlabs.stores.instamojo...
[other than India] www.buymeacoffee.com/Sfdcques...
other products:
=============+++++++++++========================
decoding salesforce admin -
rspcloudlabs.stores.instamojo...
Apex Super Requirement one - Real-Time Requirement for practice
rspcloudlabs.myinstamojo.com/...
connect with us
======================
linktr.ee/rspcloudlabs

Опубликовано:

 

10 июн 2022

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 5   
@venkatamu1994
@venkatamu1994 Год назад
Very clear thank you
@SFDCQuest
@SFDCQuest Год назад
Glad it was helpful!
@kondalaniranjanreddy7348
@kondalaniranjanreddy7348 Год назад
I have the data in my sobject but still getting exception
@SFDCQuest
@SFDCQuest Год назад
could you please check the query you are using in the query editor and check the results. also please check if the running user has the at least one record fetched from your query. feel free to share your debug log on rspcloudlabs@gmail.com if the issue persists.
Далее
What turned out better to repeat? #tiktok
00:16
Просмотров 2,4 млн
Cabeças erguidas, galera! 🙌 Vamos pegá-la!
00:10
Salesforce Mock Interview for Experienced
40:12
Просмотров 45 тыс.
Why the secret to making millions is working LESS
33:02
Apex Triggers | EXPLAINED | Salesforce Makes Sense
53:57
Functional Interface | Lambda Expression in Java
13:56
Просмотров 138 тыс.