function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Dorian Kane 5Dorian Kane 5 

apex class auto convert lead error on deploy i cant make the deploy

System.QueryException: List has no rows for assignment to SObject 
Stack Trace: Class.MyProfilePageController.testSave: line 78, column 1

 

apex class 

Public class AutoConvertLeads
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
            Database.LeadConvert Leadconvert = new Database.LeadConvert();
            Leadconvert.setLeadId(LeadIds[0]);
            LeadStatus Leads= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
            Leadconvert.setConvertedStatus(Leads.MasterLabel);
            Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion 
            Database.LeadConvertResult Leadconverts = Database.convertLead(Leadconvert);
            System.assert(Leadconverts.isSuccess());
   }
}sf

Best Answer chosen by Dorian Kane 5
Raj VakatiRaj Vakati
The issue is coming from the MyProfilePageController apex class  .. not form the class whihc you are tryig to deploy .. 

You Have two option now 
  1. Fix the MyProfilePageController Test class 
  2. Deploy with only by running the specific test class 

All Answers

Ramesh DRamesh D
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!
 
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:
LeadStatus Leads= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
It would be safer to do the following:
LeadStatus[] Leads= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
if (Leads.size() > 0) 
 Leadconvert.setConvertedStatus(Leads[0].MasterLabel);

I hope you find the above solution helpful. If it does mark as best answer to help others too.
Thanks,
Ramesh D
Raj VakatiRaj Vakati
The issue is coming from the MyProfilePageController apex class  .. not form the class whihc you are tryig to deploy .. 

You Have two option now 
  1. Fix the MyProfilePageController Test class 
  2. Deploy with only by running the specific test class 
This was selected as the best answer
Dorian Kane 5Dorian Kane 5

Hey Raj

Thanks for your answer it is me first time on deploy apex class and i don't know how to make the "Deploy with only by running the specific test class"

Dorian Kane 5Dorian Kane 5

@Ramesh Depaiah the code you added the full code looks like this its this ok


Public class AutoConvert
{
    @InvocableMethod
    public static void LeadAssign(List<Id> LeadIds)
    {
            Database.LeadConvert Leadconvert = new Database.LeadConvert();
            Leadconvert.setLeadId(LeadIds[0]);
            LeadStatus Leads= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
            Leadconvert.setConvertedStatus(Leads.MasterLabel);
            Leadconvert.setDoNotCreateOpportunity(TRUE); //Remove this line if you want to create an opportunity from Lead Conversion 
            Database.LeadConvertResult Leadconverts = Database.convertLead(Leadconvert);
            System.assert(Leadconverts.isSuccess());
   }
}
Thanks 

Raj VakatiRaj Vakati
Select the run specific test class from the below image 

and pass your test class

User-added image