• Rahul Sharma 390
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies

Class----------->
public class InvestmentSettingAura {
    
    @auraEnabled
    public static Investment_Settings__c getInvSetting(){
        
        List<Investment_Settings__c> InvSettingList = [SELECT Id,AutoBid__c,Investor__c,Max_AutoBid_Percentage__c,Maximum_exposure_to_1_Seller__c,
                                                       Maximum_Auto_Bid_Amount__c,Maximum_exposure_to_1_Customer__c,
                                                       Maximum_Credit_Grade_for_AutoBids__c
                                                       FROM Investment_Settings__c
                                                       WHERE Investor__c =:UserInfo.getUserId()];
        
        if(InvSettingList.size()>0){
            Investment_Settings__c invSet =new Investment_Settings__c();
            invSet = InvSettingList.get(0);
            return invSet;
        }
        else
            return null;
    }    
    
    @AuraEnabled 
    public static List<String>  autoBidGrade(){
        List<String> options = new List<String>();
        Schema.DescribeFieldResult fieldResult = Investment_Settings__c.Maximum_Credit_Grade_for_AutoBids__c.getDescribe();
        for (Schema.PicklistEntry f : fieldResult.getPicklistValues())
            options.add(f.getLabel());
        return options;
    }
    
    @AuraEnabled 
    public static string  saveInvestmentSettings(String invObj){
        Investment_Settings__c invSet =new Investment_Settings__c();
        invSet = (Investment_Settings__c)JSON.deserialize(invObj, Investment_Settings__c.class);
        //invSet = invObj;
        SavePoint sp = Database.setSavepoint();           //[is covering in test class]
        
        try{
            update invSet;
            return 'Success';
        }
        catch(Exception e){
            Database.rollback(sp);
            return 'Error : '+ e.getMessage();
        }
    }
}

Test Class ------------>

@isTest
public class InvestmentSettingAuraTest {  
     public static testMethod void testInvestmentSetting1(){
          Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator']; 
        user u = [select id from user where name='TMC Admin'];
         
        Investment_Settings__c invset = new Investment_Settings__c();
        invset.CurrencyIsoCode = 'SGD';
        invset.AutoBid__c = true;
        invset.Investor__c = u.id;
        insert invset;
        Investment_Settings__c invset1 = new Investment_Settings__c();
         invset1.Id= invset.Id;
        invset.CurrencyIsoCode = 'SGD';
        invset.AutoBid__c = true;
        invset.Investor__c = u.id;
        update invset;
        
        InvestmentSettingAura.getInvSetting();
        InvestmentSettingAura.autoBidGrade();
        InvestmentSettingAura.saveInvestmentSettings('invObj');
    }
}

my class ------>

public without sharing class AllBeatMaps {
   
    public list<Beat_Map__c> bmapList {get;set;}
    public list<User> salesRepList {get;set;}
    public String pageTitle {get;set;}
    public String querytype {get;set;}
   
    public AllBeatMaps(){
     pageTitle='SELECT BEAT MAP';
     String salesRep = 'Sales Rep';
     querytype = apexpages.currentPage().getParameters().get('type');
     String query1 = 'SELECT Id,Name,Beat_Definition__c FROM Beat_Map__c';
     String query2 = 'SELECT Id,Name,Userrole.Name FROM User WHERE UserRole.Name=';
     
     if(querytype!=null && querytype.trim().length()>0){
      if(querytype=='beatmap'){
       bmapList = Database.query(query1);
      }
      if(querytype=='salesrep'){
       pageTitle = 'SELECT SALES REP';
       query2+='\''+salesRep+'\'';
       salesRepList=Database.query(query2); 
      }
     }
    }
   
}

Test Class ---------->

@isTest
public class AllBeatMapsTest {
    public static testmethod void allbeatmptest(){
        profile SalesRep = [Select Id FROM Profile Where Name= 'Sales Representative'];
        userRole urp = new UserRole(Name = 'Sales Rep');
        insert urp;
        User ur = new User(UserRoleid=urp.Id,ProfileId = SalesRep.Id,Alias = 'hfsre',Country='India',Email='defo1@urturiurain.com',EmailEncodingKey='UTF-8', LastName='oiuriuterh', LanguageLocaleKey='en_US',LocaleSidKey='en_US',TimeZoneSidKey='America/Los_Angeles', UserName='wdjhfgb@b.com');
        insert ur;
 
        system.runAs(ur){
        list<User> usa = new list<User>();
        usa.add(ur);
           
            Beat_Map__c bm = new Beat_Map__c();
            bm.Beat_Definition__c = 'Gurugram Sector 14,17,21,23';
            insert bm;
            list<Beat_Map__c> bmc = new list<Beat_Map__c>();
            bmc.add(bm);
  PageReference pageRef = Page.AllBeatMaps;
  Beat_Map__c bcc = new Beat_Map__c();
  bcc.Beat_Definition__c = 'Gurugram Sector 45,17,21,23';
  insert bcc;
  
   Test.setCurrentPage(pageRef);
   pageRef.getParameters().put('id',bcc.id);
           
            AllBeatMaps obh = new AllBeatMaps();
           
 }
}
           
          
         
           
        }
   
 

Class----------->
public class InvestmentSettingAura {
    
    @auraEnabled
    public static Investment_Settings__c getInvSetting(){
        
        List<Investment_Settings__c> InvSettingList = [SELECT Id,AutoBid__c,Investor__c,Max_AutoBid_Percentage__c,Maximum_exposure_to_1_Seller__c,
                                                       Maximum_Auto_Bid_Amount__c,Maximum_exposure_to_1_Customer__c,
                                                       Maximum_Credit_Grade_for_AutoBids__c
                                                       FROM Investment_Settings__c
                                                       WHERE Investor__c =:UserInfo.getUserId()];
        
        if(InvSettingList.size()>0){
            Investment_Settings__c invSet =new Investment_Settings__c();
            invSet = InvSettingList.get(0);
            return invSet;
        }
        else
            return null;
    }    
    
    @AuraEnabled 
    public static List<String>  autoBidGrade(){
        List<String> options = new List<String>();
        Schema.DescribeFieldResult fieldResult = Investment_Settings__c.Maximum_Credit_Grade_for_AutoBids__c.getDescribe();
        for (Schema.PicklistEntry f : fieldResult.getPicklistValues())
            options.add(f.getLabel());
        return options;
    }
    
    @AuraEnabled 
    public static string  saveInvestmentSettings(String invObj){
        Investment_Settings__c invSet =new Investment_Settings__c();
        invSet = (Investment_Settings__c)JSON.deserialize(invObj, Investment_Settings__c.class);
        //invSet = invObj;
        SavePoint sp = Database.setSavepoint();           //[is covering in test class]
        
        try{
            update invSet;
            return 'Success';
        }
        catch(Exception e){
            Database.rollback(sp);
            return 'Error : '+ e.getMessage();
        }
    }
}

Test Class ------------>

@isTest
public class InvestmentSettingAuraTest {  
     public static testMethod void testInvestmentSetting1(){
          Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator']; 
        user u = [select id from user where name='TMC Admin'];
         
        Investment_Settings__c invset = new Investment_Settings__c();
        invset.CurrencyIsoCode = 'SGD';
        invset.AutoBid__c = true;
        invset.Investor__c = u.id;
        insert invset;
        Investment_Settings__c invset1 = new Investment_Settings__c();
         invset1.Id= invset.Id;
        invset.CurrencyIsoCode = 'SGD';
        invset.AutoBid__c = true;
        invset.Investor__c = u.id;
        update invset;
        
        InvestmentSettingAura.getInvSetting();
        InvestmentSettingAura.autoBidGrade();
        InvestmentSettingAura.saveInvestmentSettings('invObj');
    }
}

my class ------>

public without sharing class AllBeatMaps {
   
    public list<Beat_Map__c> bmapList {get;set;}
    public list<User> salesRepList {get;set;}
    public String pageTitle {get;set;}
    public String querytype {get;set;}
   
    public AllBeatMaps(){
     pageTitle='SELECT BEAT MAP';
     String salesRep = 'Sales Rep';
     querytype = apexpages.currentPage().getParameters().get('type');
     String query1 = 'SELECT Id,Name,Beat_Definition__c FROM Beat_Map__c';
     String query2 = 'SELECT Id,Name,Userrole.Name FROM User WHERE UserRole.Name=';
     
     if(querytype!=null && querytype.trim().length()>0){
      if(querytype=='beatmap'){
       bmapList = Database.query(query1);
      }
      if(querytype=='salesrep'){
       pageTitle = 'SELECT SALES REP';
       query2+='\''+salesRep+'\'';
       salesRepList=Database.query(query2); 
      }
     }
    }
   
}

Test Class ---------->

@isTest
public class AllBeatMapsTest {
    public static testmethod void allbeatmptest(){
        profile SalesRep = [Select Id FROM Profile Where Name= 'Sales Representative'];
        userRole urp = new UserRole(Name = 'Sales Rep');
        insert urp;
        User ur = new User(UserRoleid=urp.Id,ProfileId = SalesRep.Id,Alias = 'hfsre',Country='India',Email='defo1@urturiurain.com',EmailEncodingKey='UTF-8', LastName='oiuriuterh', LanguageLocaleKey='en_US',LocaleSidKey='en_US',TimeZoneSidKey='America/Los_Angeles', UserName='wdjhfgb@b.com');
        insert ur;
 
        system.runAs(ur){
        list<User> usa = new list<User>();
        usa.add(ur);
           
            Beat_Map__c bm = new Beat_Map__c();
            bm.Beat_Definition__c = 'Gurugram Sector 14,17,21,23';
            insert bm;
            list<Beat_Map__c> bmc = new list<Beat_Map__c>();
            bmc.add(bm);
  PageReference pageRef = Page.AllBeatMaps;
  Beat_Map__c bcc = new Beat_Map__c();
  bcc.Beat_Definition__c = 'Gurugram Sector 45,17,21,23';
  insert bcc;
  
   Test.setCurrentPage(pageRef);
   pageRef.getParameters().put('id',bcc.id);
           
            AllBeatMaps obh = new AllBeatMaps();
           
 }
}
           
          
         
           
        }