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
Kiril Vodenicharov 7Kiril Vodenicharov 7 

Illegal assignment from String to Account. Help

I have problem with my unit test class. 

@RestResource(urlMapping='/magnolia/account/*')
global with sharing class MCH_MagnoliaAccountRest {


    @HttpGet
    global static List<AccountWrapper> getAccount(){//what do you need to get ? Single row ?
        String idsParam = RestContext.request.params.get('ids');
        List<String> ids = new List<String>();
        ids = idsParam?.split(',');
        List<AccountWrapper> accountsResult = new List<AccountWrapper>();
        for(Account a : [Select 
                         	 Id,
                             mch_MCH_Login_ID__pc,
                             Type,
                             Name,
                             Description,
                             PersonMailingStreet,
                             PersonMailingPostalCode,
                             PersonMailingCountry,
                             Phone,
                             PersonEmail,
                             Website,
                             Industry,
                             mch_interests__c
                         From Account
                         WHERE Id IN :ids
                         Limit 1]){
            accountsResult.add(
                wrapAccount(a)
            );
        }
        return accountsResult;
    }
    @HttpPost
    global static String insertAccount(List<AccountWrapper> accounts){
        List<Account> accountList = new List<Account>();
        for(AccountWrapper aw : accounts){
            accountList.add(
                aw.getAccount()
            );
        }
        if(!accountList.isEmpty()){
            dmlErrorHandling(
                Database.insert(accountList, false)
            );
        }
        return 'ok';
    }
    @HttpPatch
    global static String updateAccount(List<AccountWrapper> accounts){
        List<Account> accountList = new List<Account>();
        for(AccountWrapper aw : accounts){
            accountList.add(
                aw.getAccount()
            );
        }
        if(!accountList.isEmpty()){
            dmlErrorHandling(
                Database.update(accountList, false)
            );
        }
        return 'ok';
    }
    @HttpPut//what do you need to delete ? Single row ?
    global static String deleteAccount(List<AccountWrapper> accounts){
        List<Account> accountList = new List<Account>();
        for(AccountWrapper aw : accounts){
            accountList.add(
                aw.getAccount()
            );
        }
        if(!accountList.isEmpty()){
            dmlErrorHandling(
                Database.delete(accountList, false)
            );
        }
        return 'ok';
    }

Unit test code

@isTest
public class MCH_MagnoliaAccountRestTest 
{   
    @isTest
    static Account TestGetAccount()
    {
        Account account = McH_MockupFactory.createAccount();
        if(true)
        {
            insert account;
        }
        return account;
    }
    
    @isTest 
    static void InsertAccount()
    {
        Account account = McH_MockupFactory.createAccount();
        insert account;
    }
    
    @isTest 
    static void UpdateAccount()
    {
        List<MCH_MagnoliaAccountRest.AccountWrapper> aw = new List<MCH_MagnoliaAccountRest.AccountWrapper>();
        
        Account account = McH_MockupFactory.createAccount();
        insert account;
    }
    
    @isTest 
    static void deleteAccount()
    {   
        List<MCH_MagnoliaAccountRest.AccountWrapper> aw = new List<MCH_MagnoliaAccountRest.AccountWrapper>();
        
        Account account = McH_MockupFactory.createAccount();
        insert account;
        account = MCH_MagnoliaAccountRest.deleteAccount(aw); // Here I have the error.
        delete account;
    }
}

Need help to finish it.
Best Answer chosen by Kiril Vodenicharov 7
Maharajan CMaharajan C
HI Kiril,

The deleteAccount method return type is string. And you need to pass the proper wrapper data and deleteAccount method will take care of the deletion.
 
@isTest 
    static void deleteAccount()
    {   
        List<MCH_MagnoliaAccountRest.AccountWrapper> aw = new List<MCH_MagnoliaAccountRest.AccountWrapper>();
        
        Account account = McH_MockupFactory.createAccount();
        insert account;
        String str = MCH_MagnoliaAccountRest.deleteAccount(aw); 
    }

Thanks,
Maharajan.C