You need to sign in to do that
Don't have an account?
Kiril Vodenicharov 7
Need help to finish it.
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.
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.
Thanks,
Maharajan.C