• SFDC Tortoise
  • NEWBIE
  • 20 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 6
    Replies

Hi everyone,

i'm getting the following error after the system checks the challenge:
"Challenge Not yet complete... here's what's wrong: 
There was an unexpected error in your org which is preventing this assessment check from completing: System.QueryException: List has no rows for assignment to SObject"

Apex class

@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');
        system.debug(accountId);
        Account objAccount=[SELECt id, name,(select id, name from Contacts) from Account
                           where id=:accountId limit 1];
        return objAccount;
    }

}

Test class

@isTest
private class AccountManagerTest {
    static testMethod void testMethod1(){
        Account objAccount = new Account(Name='Test Account');
        insert objAccount;
        
        Contact objContact = new Contact(LastName= 'test Contact',
                                        AccountId = objAccount.Id);
        insert objContact;
        
        Id recordID = objAccount.Id;
        
        RestRequest request = new RestRequest();
        request.requestURI = 'https://cunning-moose-pmifqd-dev-ed.my.salesforce.com/services/apexrest/Accounts/' +
                    recordId + 'contacts';
        request.httpMethod = 'GET';
        RestContext.request = request;
        
        Account thisAccount = AccountManager.getAccount();
        
        System.assert(thisAccount!= null);
        system.assertEquals('Test Account', thisAccount.Name);
        
    }
         

}

Can somebody help me with this?
Thank you,




 Use Case:
whenever a new transaction is perforned successfully then update the customer object balance field based on --
if transaction type= deposit,
then balance = balance+amount;

if transaction type= withdraw,
then balance = balance-amount; 
 
 Note- Customer and Transaction have lookup detail relationship

I have a Vf page which display account object records. In this vf page each and every record have a button called Edit. If we click on Edit button it should be take us to detailed edit page respected record. For more clearance see my pictures which i uploded. 
User-added image
User-added image

To achive this process, I have developed following VF page.

<apex:page Controller="Redirect_Main2" action="{!Redirect_Main}">
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockTable value="{!accs}" var="a" >
                <apex:column value="{!a.Id}"/>
                <apex:column value="{!a.Name}"/>
                <apex:column value="{!a.Phone}"/>
                <apex:column value="{!a.Industry}"/>
                <apex:column id="two">
                    <apex:commandButton value=" Edit " onclick="window.open('/{!a.id}')" reRender="two"/>
<!--/e?retURL=%2F{!a.id}&_CONFIRMATIONTOKEN=VmpFPSxNakF4Tmkwd055MHlPVlF3T1Rvek5qb3dPQzQ0TnpaYSxvTFl3eklmdmNBcjl6RlVDeDRWUnBtLE9XWTJNbU01&common.udd.actions.ActionsUtilORIG_URI=%2F{!a.id}%2Fe')" reRender="two"/>
   -->             </apex:column>
            </apex:pageBlockTable>
        </apex:pageBlock>
    </apex:form>
</apex:page>
Controller:
public class Redirect_Main2 {

   public List<Account> accs { get; set; }
    public PageReference Redirect_Main(){
        accs = [select id,name,phone,Industry from account];       
        return null;
     }
}
 


But this is taking me to detailed page of the record but not edit page. Please tell me neccessary actions which i need to take.

Thanking you
KS Kumaar