• sohail najmi
  • NEWBIE
  • 0 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 5
    Replies
Following are the code:



@isTest
public class TestDataUtil {
  // need to set as golobal list, can be access within class
       List<Account> lstAccount = new List<Account>(); 
       List<Product2> lstProducts = new List<Product2>();
       List<Order> lstOrders = new List<Order>();


  public static List<Account> createTestRecordsAccount(Integer numRecords) {
        List<Account> accts = new List<Account>();
        for(Integer i=0;i<numRecords;i++) {
            Account acco = new Account(Name='TestAccount'+i, Phone = '123456789'+i, Fax = '123455677'+i);
            accts.add(acco);
        }
            insert accts;
          return accts;
    }

 public static List<Product2> createTestRecordsProducts(Integer numRecords) {
      List<Product2> lstProducts = new List<Product2>();
         for(Integer i=0;i<numRecords;i++) {
              Product2 prod = new Product2(Name = 'Example Product '+i,
                                        Description = 'This is the Product description.'+i,
                                        ProductCode = 'EX1234'+i,
                                        StockKeepingUnit = 'EX5678'+i,
                                        Family = 'Example Product Family'+i,
                                        QuantityUnitOfMeasure = 'inches'+i,
                                        DisplayUrl = 'https://www.DisplayUrl.com/'+i,
                                        ExternalId = 'ID #1234'+i
                                        );
                   lstProducts.add(prod);}
                    insert lstProducts;    
              return lstProducts;
     }
     
     public static List<Order> createTestOrder(Integer numRecords, Boolean ifInsert) {
          List<Order> lstOrders = new List<Order>();
         List<Account> accts =  TestDataUtil.createTestRecordsAccount(numRecords);
         List<Pricebook2> pBook =  TestDataUtil.createTestPricebook(numRecords, ifInsert);

         for(Integer i=0;i<numRecords;i++) {
          Order ordo = new Order(Name = 'Test Order ',
                                Status = 'Draft',
                                EffectiveDate = system.today(),
                                EndDate = system.today() + 4,
                                AccountId = accts[i].id,
                                Pricebook2Id =  pBook[i].Id,
                                ShippingStreet  = 'shipping Address shipping Street   );
           lstOrders.add(ordo);
                insert lstOrders;
          return lstOrders;
     }



Question:
I have added  List  'lstAccount, lstProducts, lstOrders' as golobal. 

Now adding method and returning the List where needed. 

On 'createTestOrder' method i am calling   'createTestRecordsAccount  & createTestPricebook' again. 

Is there anyway i can save the list in these golobal list 'lstAccount, lstProducts',   MEANS where-ever i need data from these method firstly i'll check the list (lstAccount..size() >0 && lstAccount !=null). 

If lstAccount.size>0, means i have the data, so no need to call 'createTestRecordsAccount ' method again. saving dml iteration. 
    
  like following: 

  public static List<Account> createTestRecordsAccount(Integer numRecords) {
        List<Account> accts = new List<Account>();
        for(Integer i=0;i<numRecords;i++) {
            Account acco = new Account(Name='TestAccount'+i, Phone = '123456789'+i, Fax = '123455677'+i);
            accts.add(acco);
        }
            insert accts;

lstAccount.add(acco);  /// saving in golobal LIST ... (how to save it)?
          return accts;
    }  



​​​​​​​Thanks in advance ...... 
I am new to salesforce and writing unit-test for ServiceParameters class.

I have tried to get coverage from AccountName method but faild.


Following are the Method:

public without sharing class ServiceParameters {
    
    public Id OrderId {get;set;}
    public Id PackageTypeId{ get; set; }
    public Id ShipperId{ get; set; }
    public Id ShipFromId{ get; set; }
---
---
--
    public Custom_Object_c ShipFromAddress {set;get;}
    public Custom_Object_c ShipperAddress {set;get;}
    public Order CurrentOrder {get;set;}
    public Account AccountDetail {set;get;}

    public String AccountName {
        get {
            return this.AccountDetail != null && String.isNotEmpty(this.AccountDetail.Name) ? this.AccountDetail.Name : '';
        }    
    }
    public String AccountPhoneNo {
        get {
            return this.AccountDetail != null && String.isNotEmpty(this.AccountDetail.Phone) ? this.AccountDetail.Phone : '';
        }    
    }

    public String ShipFromPhoneNo {
        get {
            return this.ShipFromAddress != null && String.isNotEmpty(this.ShipFromAddress.ShipGuruApp__Phone_Number__c) ? this.ShipFromAddress.ShipGuruApp__Phone_Number__c : '';
        }    
    }

    public String ShipperName {
        get {
            return this.ShipperAddress != null && String.isNotEmpty(this.ShipperAddress.Name) ? this.ShipperAddress.Name : '';
        }    
    }


.................. ...................................................

So far i have done.

@isTest
private  class ServiceParametersTest {
    @isTest static void testServiceParametersTest() {
             ServiceParameters SP = new ServiceParameters();.
            Account AccountDetail = new Account(Name = 'john');
       String Namess = SP.AccountName(AccountDetail.Name);    // showing error message (Method does not exist or incorrect signature: void AccountName(String) )



How to start the unit test ....
If anyone helps ... THanks in Advance...
User-added imageI have lookup field name 'Courier Service' with default lookup showing name(here auto-number). But i want to show field other than name. 

How this is going to be ?? 

Thanks in Advance. 

 
Lookup
I have lookup field name 'Courier Service' with default lookup showing name(here auto-number). But i want to show field other than name. 

How this is going to be ?? 

Thanks in Advance. 
Required Scenario:
-User add one record with [name, address, favorite(checkbox[checked])].
-User can add many record without favorite[checked]
-On adding new record if user apply favorite[checked] and save, user will be prompt with error message, you already marked favorite a record.

I have applied validation rule: IF( Set_Primary__c ,(TRUE), (Set_Primary__c) )
following rule are working if there is already a record with favorite[ checked] . means not allowing to add for 2nd time.

When i am adding data for first time, error message show, not allowing me to add data. Need to know what iam missing ??

Thanks.



 
Following are the code:



@isTest
public class TestDataUtil {
  // need to set as golobal list, can be access within class
       List<Account> lstAccount = new List<Account>(); 
       List<Product2> lstProducts = new List<Product2>();
       List<Order> lstOrders = new List<Order>();


  public static List<Account> createTestRecordsAccount(Integer numRecords) {
        List<Account> accts = new List<Account>();
        for(Integer i=0;i<numRecords;i++) {
            Account acco = new Account(Name='TestAccount'+i, Phone = '123456789'+i, Fax = '123455677'+i);
            accts.add(acco);
        }
            insert accts;
          return accts;
    }

 public static List<Product2> createTestRecordsProducts(Integer numRecords) {
      List<Product2> lstProducts = new List<Product2>();
         for(Integer i=0;i<numRecords;i++) {
              Product2 prod = new Product2(Name = 'Example Product '+i,
                                        Description = 'This is the Product description.'+i,
                                        ProductCode = 'EX1234'+i,
                                        StockKeepingUnit = 'EX5678'+i,
                                        Family = 'Example Product Family'+i,
                                        QuantityUnitOfMeasure = 'inches'+i,
                                        DisplayUrl = 'https://www.DisplayUrl.com/'+i,
                                        ExternalId = 'ID #1234'+i
                                        );
                   lstProducts.add(prod);}
                    insert lstProducts;    
              return lstProducts;
     }
     
     public static List<Order> createTestOrder(Integer numRecords, Boolean ifInsert) {
          List<Order> lstOrders = new List<Order>();
         List<Account> accts =  TestDataUtil.createTestRecordsAccount(numRecords);
         List<Pricebook2> pBook =  TestDataUtil.createTestPricebook(numRecords, ifInsert);

         for(Integer i=0;i<numRecords;i++) {
          Order ordo = new Order(Name = 'Test Order ',
                                Status = 'Draft',
                                EffectiveDate = system.today(),
                                EndDate = system.today() + 4,
                                AccountId = accts[i].id,
                                Pricebook2Id =  pBook[i].Id,
                                ShippingStreet  = 'shipping Address shipping Street   );
           lstOrders.add(ordo);
                insert lstOrders;
          return lstOrders;
     }



Question:
I have added  List  'lstAccount, lstProducts, lstOrders' as golobal. 

Now adding method and returning the List where needed. 

On 'createTestOrder' method i am calling   'createTestRecordsAccount  & createTestPricebook' again. 

Is there anyway i can save the list in these golobal list 'lstAccount, lstProducts',   MEANS where-ever i need data from these method firstly i'll check the list (lstAccount..size() >0 && lstAccount !=null). 

If lstAccount.size>0, means i have the data, so no need to call 'createTestRecordsAccount ' method again. saving dml iteration. 
    
  like following: 

  public static List<Account> createTestRecordsAccount(Integer numRecords) {
        List<Account> accts = new List<Account>();
        for(Integer i=0;i<numRecords;i++) {
            Account acco = new Account(Name='TestAccount'+i, Phone = '123456789'+i, Fax = '123455677'+i);
            accts.add(acco);
        }
            insert accts;

lstAccount.add(acco);  /// saving in golobal LIST ... (how to save it)?
          return accts;
    }  



​​​​​​​Thanks in advance ...... 
Lookup
I have lookup field name 'Courier Service' with default lookup showing name(here auto-number). But i want to show field other than name. 

How this is going to be ?? 

Thanks in Advance. 
Required Scenario:
-User add one record with [name, address, favorite(checkbox[checked])].
-User can add many record without favorite[checked]
-On adding new record if user apply favorite[checked] and save, user will be prompt with error message, you already marked favorite a record.

I have applied validation rule: IF( Set_Primary__c ,(TRUE), (Set_Primary__c) )
following rule are working if there is already a record with favorite[ checked] . means not allowing to add for 2nd time.

When i am adding data for first time, error message show, not allowing me to add data. Need to know what iam missing ??

Thanks.



 
Hi,
I am trying to copy a Standard Field value to Custom field in the same object.
I need to copy Name field  (standard) from Event to Check_name__C (custom field) to Event only using trigger.

Actualy am not sure how to write a trigger but I tried ..an anyone please help with this.

trigger insertname on Event (after insert) {
Set<Id> Ids= new Set<Id>();
    for (Event E1 : Trigger.new)
    {
        Ids.add(E1.Id);       
    }
List<Event> EventList = new List<Event>([Select Id,whoId from event where Id in :Ids]);

    for(Event temp : EventList )
    {
        Event e2 = new e2();
       
                insert e2;

    }


}
Hi all, I'm trying to run a simple trigger before delete. The error I'm getting is:

System.NullPointerException: Attempt to de-reference a null object


Code:
trigger deleteMultiday on SFDC_Special_Event__c (before delete) {

        for (SFDC_Special_Event__c co : Trigger.new)
        {

        }//end main for

}//end trigger

 I originally had logic in the loop but removed it to see if it was causing the error. But the error is still showing with this code. The above code works perfectly in insert/update triggers.