Skip to main content
Removed extra "I am' in question; cleaned up code formatting; added 'apex' and 'unit-test' tags
Source Link

In my simple use case I am t I am unable to get code coverage for Account and URL fields any suggestions. In the URL field I am appending string what I get from the form to the URL field. Here's the code for my apex class and test class::

public static string saveRecord(Deal__c itemd){
        string url = 'https://www.amazon.com/s/p-';
         map<string,string> info = new map<string,string>();
            List<Account> results = [SELECT id FROM Account WHERE Account_ID__c = : itemd.Seller_ID__c];
            if (results.size() != 0){
                itemd.Account__c  = results.get(0).id;
                itemd.SPM_ID__c  = url + itemd.Sears_Item_SPM_or_A__c; 
                   try{  
            insert itemd;
            //return itemd.id;
            info.put('status','success');
            info.put('message',itemd.id);
        }catch(exception e) { 
system.debug('-------getMessage-----------'+e.getMessage());
}

TEST CLASS::
 @isTest
private class Create_Deal_Test{

  static testMethod void test_saveRecord_UseCase1(){

      Account itdAct = new Account() ;
       itdAct.Name = '123Cycles';
       itdAct.Account_ID__c = '12332';
            insert itdAct;
      Deal__c itmd = new Item_Deal__c(Seller_ID__c='1234',Email__c = '[email protected]', price__c = 23211, Category__c = 'vert', Item_Description__c = 'Itemdescription' );
            itmd.Account__c = itdAct.Id;
            itmd.SPM_ID__c = 'www.amazon.com';
      
    insert itmd;
      Create_Deal.saveRecord(itmd);

  }
}
public without sharing class Create_Deal{
   public static string saveRecord(Deal__c itemd){
        string url = 'https://www.amazon.com/s/p-';
        map<string,string> info = new map<string,string>();
        List<Account> results = [SELECT id FROM Account WHERE Account_ID__c = : itemd.Seller_ID__c];
        if (results.size() != 0){
            itemd.Account__c  = results.get(0).id;
            itemd.SPM_ID__c  = url + itemd.Sears_Item_SPM_or_A__c; 
            try{  
               insert itemd;
               //return itemd.id;
               info.put('status','success');
               info.put('message',itemd.id);
            } catch(exception e) { 
               system.debug('-------getMessage-----------'+e.getMessage());
            }

TEST CLASS::

@isTest
private class Create_Deal_Test{
   static testMethod void test_saveRecord_UseCase1(){
      Account itdAct = new Account() ;
      itdAct.Name = '123Cycles';
      itdAct.Account_ID__c = '12332';
      insert itdAct;
      Deal__c itmd = new Item_Deal__c(Seller_ID__c='1234',Email__c = '[email protected]', price__c = 23211, Category__c = 'vert', Item_Description__c = 'Itemdescription' );
      itmd.Account__c = itdAct.Id;
      itmd.SPM_ID__c = 'www.amazon.com';
      insert itmd;
      Create_Deal.saveRecord(itmd);
   }
}

In my simple use case I am t I am unable to get code coverage for Account and URL fields any suggestions. In the URL field I am appending string what I get from the form to the URL field. Here's the code for my apex class and test class::

public static string saveRecord(Deal__c itemd){
        string url = 'https://www.amazon.com/s/p-';
         map<string,string> info = new map<string,string>();
            List<Account> results = [SELECT id FROM Account WHERE Account_ID__c = : itemd.Seller_ID__c];
            if (results.size() != 0){
                itemd.Account__c  = results.get(0).id;
                itemd.SPM_ID__c  = url + itemd.Sears_Item_SPM_or_A__c; 
                   try{  
            insert itemd;
            //return itemd.id;
            info.put('status','success');
            info.put('message',itemd.id);
        }catch(exception e) { 
system.debug('-------getMessage-----------'+e.getMessage());
}

TEST CLASS::
 @isTest
private class Create_Deal_Test{

  static testMethod void test_saveRecord_UseCase1(){

      Account itdAct = new Account() ;
       itdAct.Name = '123Cycles';
       itdAct.Account_ID__c = '12332';
            insert itdAct;
      Deal__c itmd = new Item_Deal__c(Seller_ID__c='1234',Email__c = '[email protected]', price__c = 23211, Category__c = 'vert', Item_Description__c = 'Itemdescription' );
            itmd.Account__c = itdAct.Id;
            itmd.SPM_ID__c = 'www.amazon.com';
      
    insert itmd;
      Create_Deal.saveRecord(itmd);

  }
}

In my simple use case I am unable to get code coverage for Account and URL fields any suggestions. In the URL field I am appending string what I get from the form to the URL field. Here's the code for my apex class and test class::

public without sharing class Create_Deal{
   public static string saveRecord(Deal__c itemd){
        string url = 'https://www.amazon.com/s/p-';
        map<string,string> info = new map<string,string>();
        List<Account> results = [SELECT id FROM Account WHERE Account_ID__c = : itemd.Seller_ID__c];
        if (results.size() != 0){
            itemd.Account__c  = results.get(0).id;
            itemd.SPM_ID__c  = url + itemd.Sears_Item_SPM_or_A__c; 
            try{  
               insert itemd;
               //return itemd.id;
               info.put('status','success');
               info.put('message',itemd.id);
            } catch(exception e) { 
               system.debug('-------getMessage-----------'+e.getMessage());
            }

TEST CLASS::

@isTest
private class Create_Deal_Test{
   static testMethod void test_saveRecord_UseCase1(){
      Account itdAct = new Account() ;
      itdAct.Name = '123Cycles';
      itdAct.Account_ID__c = '12332';
      insert itdAct;
      Deal__c itmd = new Item_Deal__c(Seller_ID__c='1234',Email__c = '[email protected]', price__c = 23211, Category__c = 'vert', Item_Description__c = 'Itemdescription' );
      itmd.Account__c = itdAct.Id;
      itmd.SPM_ID__c = 'www.amazon.com';
      insert itmd;
      Create_Deal.saveRecord(itmd);
   }
}
Source Link
Laxman
  • 243
  • 3
  • 14

Test class code coverage for lookup field and URL field

In my simple use case I am t I am unable to get code coverage for Account and URL fields any suggestions. In the URL field I am appending string what I get from the form to the URL field. Here's the code for my apex class and test class::

public static string saveRecord(Deal__c itemd){
        string url = 'https://www.amazon.com/s/p-';
         map<string,string> info = new map<string,string>();
            List<Account> results = [SELECT id FROM Account WHERE Account_ID__c = : itemd.Seller_ID__c];
            if (results.size() != 0){
                itemd.Account__c  = results.get(0).id;
                itemd.SPM_ID__c  = url + itemd.Sears_Item_SPM_or_A__c; 
                   try{  
            insert itemd;
            //return itemd.id;
            info.put('status','success');
            info.put('message',itemd.id);
        }catch(exception e) { 
system.debug('-------getMessage-----------'+e.getMessage());
}

TEST CLASS::
 @isTest
private class Create_Deal_Test{

  static testMethod void test_saveRecord_UseCase1(){

      Account itdAct = new Account() ;
       itdAct.Name = '123Cycles';
       itdAct.Account_ID__c = '12332';
            insert itdAct;
      Deal__c itmd = new Item_Deal__c(Seller_ID__c='1234',Email__c = '[email protected]', price__c = 23211, Category__c = 'vert', Item_Description__c = 'Itemdescription' );
            itmd.Account__c = itdAct.Id;
            itmd.SPM_ID__c = 'www.amazon.com';
      
    insert itmd;
      Create_Deal.saveRecord(itmd);

  }
}