Show More Show Less
View Video Transcript
0:07
Hello everyone. In this video, we are
0:09
going to see how to find
0:12
test classes in Salesforce org.
0:15
If you are an architect or an admin or a
0:18
Salesforce developer or a consultant
0:20
who is working on a project and then if
0:22
you wanted to find out the test classes
0:24
in a Salesforce org,
0:26
then you can make use of this video as a
0:29
reference.
0:30
I'm going to show two options. One using
0:33
an IDE like VS Code or Cursor.
0:38
If you are an Apex developer
0:41
or a consultant and then if you wanted
0:43
to
0:44
uh run a simple Apex uh
0:48
script so that uh
0:50
you can find out uh the test classes,
0:52
then I have uh
0:54
Apex uh script for your reference that
0:57
can be executed in your Salesforce org
0:59
to find out the test classes in a
1:01
Salesforce org.
1:03
Okay, the first step is uh
1:05
use this package.xml
1:07
in your IDE and then retrieve all the
1:10
Apex classes.
1:14
So, I created
1:18
a Salesforce project using VS Code
1:22
with uh manifest.
1:24
And in the package.xml,
1:27
I am trying to retrieve all the Apex
1:29
classes. You can right click here,
1:31
select retrieve source in manifest from
1:34
org so that it will be
1:36
able to pull all the Apex classes in
1:39
your org.
1:42
Next thing is we have to go to testing
1:44
here
1:48
and then expand text explorer
1:51
under local namespace and under
1:53
unpackaged metadata, you will be able to
1:56
find out all the
1:58
unmanaged uh
2:00
uh Apex uh test classes here.
2:04
If you are using uh Lightning Web
2:06
Component, then the Lightning Web
2:07
Component related test the unit testing
2:10
for Lightning Web Component JavaScript
2:12
will be available will be available
2:14
under LWC tests.
2:16
If you have uh
2:18
managed packages in your Salesforce org,
2:21
then
2:22
similar to local uh namespace, you will
2:25
be able to see multiple uh
2:27
um namespaces
2:30
based on the number of packages you have
2:32
installed in your Salesforce org.
2:35
And their related Apex test classes will
2:38
be available for your reference.
2:41
This is the best uh solution which I
2:43
would recommend.
2:46
The next uh solution is uh
2:50
Apex code or a script.
2:53
Using this uh SOQL I'm
2:55
I'm getting ID, name, and body from Apex
2:58
class object or entity where status is
3:01
active.
3:03
Next, I'm iterating the
3:06
now the clan the Salesforce Apex classes
3:08
which are retrieved.
3:10
And then
3:11
I'm with the Apex class body, I'm making
3:16
it as lower uh lower case because this
3:19
contains uh
3:21
method in the Apex uh code is
3:24
case-sensitive.
3:25
And then I'm checking whether it
3:27
contains at is test.
3:30
Let's say apart from test class in a
3:32
normal controller or an handler class,
3:35
if somebody mentioned at is test, even
3:38
that class will also be referenced as a
3:41
test class in as per this Apex script.
3:43
So, this is not 100% accurate, but the
3:46
accuracy will be
3:48
uh closer to 90 or 95
3:51
based on
3:52
the development that has been done in
3:54
the Salesforce org. If no one used at is
3:57
tested in handler or controller
4:00
or
4:01
other Apex classes and if it is used
4:04
only in the test classes, then the
4:06
accuracy will be 100% here.
4:10
I'm adding it to the test classes. So,
4:12
this is the test classes list.
4:14
And then using a system.debug statement,
4:17
I'm able to
4:19
display the class name. So, if I run
4:22
this code,
4:43
So, you
4:45
Okay.
4:46
So, if I click debug only, I will be
4:48
able to find out all the Apex uh test
4:50
classes.
4:59
Please check the video description. In
5:01
the video description, I have shown my
5:03
blog post. From the blog post, you
5:05
should be able to get the sample
5:07
package.xml
5:08
as well as the sample Apex script for
5:11
your reference.
5:22
I hope it was helpful.
5:34
Thank you for watching.
5:51
>> Mhm.
#Science
