• EswarForce
  • NEWBIE
  • 25 Points
  • Member since 2017

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies
Hi 
 I am facing error for writting test class ...I have written tesst class and its code covearge is 85%.when i am migrating its showing following error 

AddChildProductTesttestMethod1System.TypeException: Invalid id value for this SObject type: 00328000018OaaVAAS 
Stack Trace: Class.AddChildProduct.addParentAccount: line 31, column 1 Class.AddChildProductTest.testMethod1: line 20, column 1
public class AddChildProduct {
  
  @AuraEnabled
  public static List<Product__c> getContacts() {
  List<Product__c> totalList = new List<Product__c>();
  for(Product__c cc : [SELECT id,name,PictureUpload__c,Tag_Price__c from Product__c limit 2000  ]){
  totalList.add(cc);
        }   
      return totalList;
  }
    
  @AuraEnabled
 public static List <Product__c> fetchAccount(String searchKeyWord) {
  String searchKey = searchKeyWord + '%';
  List <Product__c> returnList = new List <Product__c> ();
  List <Product__c> lstOfAccount = [select id,name,PictureUpload__c,Tag_Price__c from Product__c where Name LIKE: searchKey];
 
  for (Product__c acc: lstOfAccount) {
   returnList.add(acc);
  }
  return returnList;
 }
               

 
  @AuraEnabled
  public static void addParentAccount(String ParentId , List<String> lstOfContactIds){
    list<Product__c> lstContacts = new list<Product__c>();
    for(string sContactId : lstOfContactIds){
        Product__c oContact = new Product__c();
        oContact.Id = sContactId;
        oContact.Contact__c = ParentId;
        lstContacts.add(oContact);
   }
   update lstContacts;
 }
}
 
@istest
 private class AddChildProductTest
 {
   @istest private static void testMethod1()
   {

     Product__c a1 = new Product__c();
     a1.name='hello raja';
     
     insert a1;
      account acc = new account(name= 'test');
      insert acc;
      contact c1 = new contact(accountId= acc.id, LastName = 'test1');
     insert c1;
     
   List<string> contactIds = new List<string>{c1.id};
  
   AddChildProduct.getContacts();
   AddChildProduct.fetchAccount('hello raja');
   AddChildProduct.addParentAccount(c1.id, contactIds);
   }
   }

 
Hi All

How can i improve my code coverage of my controller
public class SampleRollupSummary {  
    
    public static void rollupContacts(list<Sales__c> lstOfconts){
        
        system.debug('==lstOfconts== : '+lstOfconts);
        
        set<id> accIds = new set<id>();
        
        list<Contact> updLstOfAccs = new list<Contact>();      
        
         double  totalAmount = 0;
        
        for(Sales__C con : lstOfconts){
            
            accIds.add(con.Customer_Name__c);
            
        }
        
        system.debug('==accIds==:'+accIds);
        
        list<Contact> lstAccs = [select id,Total_Sale__c,(select id,Sold_Price__c from Sales__r) from Contact where id in : accIds];
        
        
        
        for(Contact acc : lstAccs){
            
            
            
            for(Sales__c cpr : acc.Sales__r){
                
                totalAmount = totalAmount + cpr.Sold_Price__c ;
                
            }
            
            acc.Total_Sale__c= totalAmount;
            
            updLstOfAccs.add(acc);
            
        }
        
        if(updLstOfAccs.size() > 0){
            
            update updLstOfAccs;
            
        }
        
        
        
        
        
    }
    
    
    
}
 
@isTest
public with sharing class SampleRollupSummaryTest 
{ 
    static testmethod void validateStandardController()
    {
    Contact con  = new Contact(LastName = 'abc');
    Sales__c pro = new Sales__c();
    pro.sold_price__c=123;
   
     
    insert pro;
 
    insert con;
     
     
  
        
        
     
     }  
  
  
   
}

 
Hi All,

I have created this below Aura enabled method
@AuraEnabled
    public static Map<Account,List<Contact>> test(String ZipVal, String fldVal)
    {
        Map<Account,List<Contact>> mp = new Map<Account,List<Contact>>();
        Account acc = new Account();
        acc = [select id from Account limit 1];
        mp.put(acc,new list<Contact>());
        mp.get(acc).add([select id from Contact limit 1]);
        return mp;
    }

But in Js Controller it is not able to get the value. The response is coming as error. 
Is map of object and list of object like - Map<Account,List<Contact>> not supported in lightning component?
Hi 
 I am facing error for writting test class ...I have written tesst class and its code covearge is 85%.when i am migrating its showing following error 

AddChildProductTesttestMethod1System.TypeException: Invalid id value for this SObject type: 00328000018OaaVAAS 
Stack Trace: Class.AddChildProduct.addParentAccount: line 31, column 1 Class.AddChildProductTest.testMethod1: line 20, column 1
public class AddChildProduct {
  
  @AuraEnabled
  public static List<Product__c> getContacts() {
  List<Product__c> totalList = new List<Product__c>();
  for(Product__c cc : [SELECT id,name,PictureUpload__c,Tag_Price__c from Product__c limit 2000  ]){
  totalList.add(cc);
        }   
      return totalList;
  }
    
  @AuraEnabled
 public static List <Product__c> fetchAccount(String searchKeyWord) {
  String searchKey = searchKeyWord + '%';
  List <Product__c> returnList = new List <Product__c> ();
  List <Product__c> lstOfAccount = [select id,name,PictureUpload__c,Tag_Price__c from Product__c where Name LIKE: searchKey];
 
  for (Product__c acc: lstOfAccount) {
   returnList.add(acc);
  }
  return returnList;
 }
               

 
  @AuraEnabled
  public static void addParentAccount(String ParentId , List<String> lstOfContactIds){
    list<Product__c> lstContacts = new list<Product__c>();
    for(string sContactId : lstOfContactIds){
        Product__c oContact = new Product__c();
        oContact.Id = sContactId;
        oContact.Contact__c = ParentId;
        lstContacts.add(oContact);
   }
   update lstContacts;
 }
}
 
@istest
 private class AddChildProductTest
 {
   @istest private static void testMethod1()
   {

     Product__c a1 = new Product__c();
     a1.name='hello raja';
     
     insert a1;
      account acc = new account(name= 'test');
      insert acc;
      contact c1 = new contact(accountId= acc.id, LastName = 'test1');
     insert c1;
     
   List<string> contactIds = new List<string>{c1.id};
  
   AddChildProduct.getContacts();
   AddChildProduct.fetchAccount('hello raja');
   AddChildProduct.addParentAccount(c1.id, contactIds);
   }
   }