• Siddharth . 2
  • NEWBIE
  • -2 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 3
    Replies
Error:System.QueryException: List has no rows for assignment to SObject

Stack Trace:
Class.AccountManager.getAccount: line 10, column 1
Class.AccountManagerTest.TestGetById: line 19, column 1

Account ManagerClass:

@RestResource(urlMapping='/Accounts/*/contacts')
global with sharing class AccountManager {
    
    @HttpGet
    global static Account getAccount(){
        
        RestRequest request=RestContext.request;
        string AccountId=request.requestURI.substringBetween('Accounts','contacts');
        
        Account accountdetails = [Select Id,name,(Select Id,Name from Contacts) from Account where Id=:AccountId LIMIT 1];
        return accountdetails;
    }

}

AccountManagerTest:

@isTest
public class AccountManagerTest {
    

 @isTest static void TestGetById(){
        
        Account testaccount = new Account(name='TestAccount');
            insert testaccount;
        Contact objContact = new Contact(LastName ='TestContact',AccountId=testaccount.Id);
         insert objContact;
        id recordid=testaccount.Id;
        
        Restrequest request=new Restrequest();
        request.requestURI='https://ap8.lightning.force.com/services/apexrest/Account/'+recordid+'/contact';
        request.httpMethod='GET';
        
        RestContext.request=request;
        
        Account thisAccount=AccountManager.getAccount();
        //Verify the results
        System.assert(thisAccount!= null);
        System.assertEquals('TestAccount', thisAccount.Name);

        
        
    }

}
Greetings to all,

I am seeking assistance with an issue I've encountered. Within my current setup, I have an LWC component that functions as a screen component within a flow. This flow is called from another LWC component using the Lightning Flow feature. This entire system is hosted within the LWR Experience Cloud site.

While everything appears to function correctly when accessing this component within the Experience Builder, a problem arises once the site is published. Upon attempting to access the component in the published site, the following error emerges:

Something went wrong with the "LWC_Demo" screen component on the "Report Adhoc Hours" flow. Contact your Salesforce admin about this error. LWR3008: Error loading https://demo.develop.my.site.com/volunteers/webruntime/component/latest/prod/en-US/c%2FlookUpWrapper

On examining the Network calls in chrome, I can see the difference between the Experience Builder and the live site are

Experience Builder: https://demo.develop.live-preview.salesforce-experience.com/volunteers/webruntime/component/latest/prod/en-US/c%2FlookUpWrapper

Live Site: https://demo.develop.my.site.com/volunteers/webruntime/component/latest/prod/en-US/c%2FlookUpWrapper


While the component's JavaScript scripts are successfully retrieved and rendered in the live preview, attempting to do so in the published site results in the subsequent detailed error:
 
GET https://demo.my.site.com/volunteers/webruntime/component/latest/prod/en-US/c%2FlookUpWrapper net::ERR_ABORTED 404 (Not Found)

Refused to execute script from 'https://demo.develop.my.site.com/volunteers/webruntime/component/latest/prod/en-US/c%2FlookUpWrapper' because its MIME type ('text/html') is not executable, and strict MIME type checking is enabled.

 
I've undertaken the following measures:
a) Relaxed the CSP setting.
b) Added the site to CSP trusted sites.
c) Enabled CORS.
d) Disabled Lightning Locker.
e) Exposed the LWC component to communities with the specified targets.

  <apiVersion>57.0</apiVersion>
    <isExposed>true</isExposed>
    <targets>
        <target>lightning__AppPage</target>
        <target>lightning__RecordPage</target>
        <target>lightning__HomePage</target>
        <target>lightning__FlowScreen</target>
        <target>lightningCommunity__Page</target>
        <target>lightningCommunity__Default</target>
        <target>lightningCommunity__Page_Layout</target>
    </targets>


What else needed to be checked? I would greatly appreciate any insights or suggestions on resolving this matter.

Note: It was working a while back not sure what has changed resulting in this failure.
Error:System.QueryException: List has no rows for assignment to SObject

Stack Trace:
Class.AccountManager.getAccount: line 10, column 1
Class.AccountManagerTest.TestGetById: line 19, column 1

Account ManagerClass:

@RestResource(urlMapping='/Accounts/*/contacts')
global with sharing class AccountManager {
    
    @HttpGet
    global static Account getAccount(){
        
        RestRequest request=RestContext.request;
        string AccountId=request.requestURI.substringBetween('Accounts','contacts');
        
        Account accountdetails = [Select Id,name,(Select Id,Name from Contacts) from Account where Id=:AccountId LIMIT 1];
        return accountdetails;
    }

}

AccountManagerTest:

@isTest
public class AccountManagerTest {
    

 @isTest static void TestGetById(){
        
        Account testaccount = new Account(name='TestAccount');
            insert testaccount;
        Contact objContact = new Contact(LastName ='TestContact',AccountId=testaccount.Id);
         insert objContact;
        id recordid=testaccount.Id;
        
        Restrequest request=new Restrequest();
        request.requestURI='https://ap8.lightning.force.com/services/apexrest/Account/'+recordid+'/contact';
        request.httpMethod='GET';
        
        RestContext.request=request;
        
        Account thisAccount=AccountManager.getAccount();
        //Verify the results
        System.assert(thisAccount!= null);
        System.assertEquals('TestAccount', thisAccount.Name);

        
        
    }

}