• Sunil Kandel 10
  • NEWBIE
  • 50 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 13
    Replies
I am new to coding. Could you please suggest how to write a test class for the given trigger. Appreciated your time.

trigger Triggerupdatedirectbill on FX5__Ticket_Item__c (before insert, before update ) {
    if(Trigger.isBefore && (Trigger.isInsert || Trigger.isUpdate) ) {
        List<FX5__Ticket_Item__c> items = Trigger.new;
        Set<String> accountsIds = new Set<String>();
        Set<String> wellsIds = new Set<String>();
        for(FX5__Ticket_Item__c item:items) {
            if(item.Customerforlogiconly__c!= null) {
               accountsIds.add(item.Customerforlogiconly__c);
               System.debug(accountsIds);
            }
            if(item.Disposal_Location_on_Ticket_item__c!= null) {
                wellsIds.add(item.Disposal_Location_on_Ticket_item__c);
                 System.debug(wellsIds);
            }
        }
        Map<String, Obj_Direct_Bill_Customer__c> directInvoicesMap = new Map<String, Obj_Direct_Bill_Customer__c>();
        for(Obj_Direct_Bill_Customer__c di :[Select Direct_Bill_Customer__c, Disposal_Location__c from Obj_Direct_Bill_Customer__c where Direct_Bill_Customer__c in :accountsIds and Disposal_Location__c in :wellsIds] ) {
            if(!directInvoicesMap.containsKey(di.Direct_Bill_Customer__c+'_'+di.Disposal_Location__c) ) {
                directInvoicesMap.put(di.Direct_Bill_Customer__c+'_'+di.Disposal_Location__c,di);
            }
            System.debug (di.direct_Bill_Customer__c);
            System.debug (di.Disposal_Location__c);
            System.debug (di.Direct_Bill_Customer__c+'_'+di.Disposal_Location__c);          
        }
        for(FX5__Ticket_Item__c item:items )       
         {
         System.debug (item.Customerforlogiconly__c+'_'+item.Disposal_Location_on_Ticket_item__c);
           if(directInvoicesMap.containsKey(item.Customerforlogiconly__c+'_'+item.Disposal_Location_on_Ticket_item__c)) {
                item.Direct_Bill_Customer__c = True;
                  }
            else {
                item.Direct_Bill_Customer__c = False;
            }
                
        }
        
    }
}
Could you please suggest what is wrong with this. My True condition is not triggering,There are true and False condition, it is always resulting to False.
I have custom object Obj_Direct_Bill_Customer__c with fields Direct_Bill_Customer__c (lookup field) and Disposal_Location__c(lookup field)
Customer object: FX5__Ticket_Item__c with Fields Customerforlogiconly__c (checkbox), Disposal_Location_on_Ticket_item__c (lookup Field) and Test_Direct_Bill_Customer__c (checkbox). If value of Customerforlogiconly__c=Direct_Bill_Customer__c  && Disposal_Location_on_Ticket_item__c=Disposal_Location__c, then update Test_Direct_Bill_Customer__c to True, if not False.


trigger Triggerupdatedirectbill on FX5__Ticket_Item__c (before insert, before update ) {

    if(Trigger.isBefore && (Trigger.isInsert || Trigger.isUpdate) ) {
        List<FX5__Ticket_Item__c> items = Trigger.new;
        Set<String> accountsIds = new Set<String>();
        Set<String> wellsIds = new Set<String>();
        for(FX5__Ticket_Item__c item:items) {
            if(item.Customerforlogiconly__c!= null ) {
               accountsIds.add(item.Customerforlogiconly__c);
            }

            if(item.Disposal_Location_on_Ticket_item__c!= null ) {
                wellsIds.add(item.Disposal_Location_on_Ticket_item__c);
            }
        }

        Map<String, Obj_Direct_Bill_Customer__c> directInvoicesMap = new Map<String, Obj_Direct_Bill_Customer__c>();
        for(Obj_Direct_Bill_Customer__c di :[Select Direct_Bill_Customer__c, Disposal_Location__c from Obj_Direct_Bill_Customer__c where Direct_Bill_Customer__c in :accountsIds and Disposal_Location__c in :wellsIds] ) {
            if(!directInvoicesMap.containsKey(di.Direct_Bill_Customer__c+'-'+di.Disposal_Location__c) ) {
                directInvoicesMap.put(di.Direct_Bill_Customer__c+'-'+di.Disposal_Location__c,di);
            }
        }

        for(FX5__Ticket_Item__c item:items ) {
            if(directInvoicesMap.containsKey(item.Customerforlogiconly__c+'-'+item.Disposal_Location_on_Ticket_item__c) ) {
                item.Test_Direct_Bill_Customer__c = True;
                
            }
            item.Test_Direct_Bill_Customer__c = False;
            
        }
    }
}

Thank you
Hi,

I have custom object called ITEM with three Fields:
  1. CUSTOMER   (lookup field from Account)
  2. LOCATION (lookup from field Well__c)
  3. PRIME CUSTOMER (checkbox)
 
I have another custom field: DIRECT INVOICE where there are only two fields. This is kind of list of combination.
  1. CUSTOMER INVOICE  (lookup field from Account)
  2. LOCATION INVOICE (Lookup field from Well__c)
 
I need to write a trigger (after update, after insert) where if CUSTOMER and LOCATION from object ITEM matches with any of the records  with CUSTOMER INVOICE and LOCATION INVOICE from DIRECT INVOICE, then update a field PRIME CUSTOMER in item to TRUE.
 
I am maintaining a list of combination of customer invoice and location invoice in Direct invoice object, hence any new record of update record in object is to be checked with all records in Direct invoice to find if any records matches.
 
Thank you for your suggestion.
 
Hi,

I am new to Trigger. I want to update field if formula field value is changed. Could you please suggest.
Object: Ticket__c
Field if changed: Bill_to__c
update field: updaterequired__c


trigger Checkprojectbilltoaccount on Ticket__c (before update){
    for(Ticket__c newchange:Trigger.new) {
    Ticket__c oldchange = system.trigger.oldMap.get(newchange.Id);
    if (oldchange.Bill_To__c !=newchange.Bill_To__c) 
        {
              newchange.UpdateRequired__c = True;
              
        }
        }
Hi all,

I have two objects in Master Detail relationship.
Ticket__c  is a Master and Ticket_item__c is Child.
I have related list of Ticket_item__c in Ticket__c but it is standard page and it will show only 10 columns.
I want to display the Ticket_item_c list in Ticket Page Layout with 12 columns. 
Can you please point any sample visualfore page on how to write this.  

Thank you
I am new to coding. Could you please suggest how to write a test class for the given trigger. Appreciated your time.

trigger Triggerupdatedirectbill on FX5__Ticket_Item__c (before insert, before update ) {
    if(Trigger.isBefore && (Trigger.isInsert || Trigger.isUpdate) ) {
        List<FX5__Ticket_Item__c> items = Trigger.new;
        Set<String> accountsIds = new Set<String>();
        Set<String> wellsIds = new Set<String>();
        for(FX5__Ticket_Item__c item:items) {
            if(item.Customerforlogiconly__c!= null) {
               accountsIds.add(item.Customerforlogiconly__c);
               System.debug(accountsIds);
            }
            if(item.Disposal_Location_on_Ticket_item__c!= null) {
                wellsIds.add(item.Disposal_Location_on_Ticket_item__c);
                 System.debug(wellsIds);
            }
        }
        Map<String, Obj_Direct_Bill_Customer__c> directInvoicesMap = new Map<String, Obj_Direct_Bill_Customer__c>();
        for(Obj_Direct_Bill_Customer__c di :[Select Direct_Bill_Customer__c, Disposal_Location__c from Obj_Direct_Bill_Customer__c where Direct_Bill_Customer__c in :accountsIds and Disposal_Location__c in :wellsIds] ) {
            if(!directInvoicesMap.containsKey(di.Direct_Bill_Customer__c+'_'+di.Disposal_Location__c) ) {
                directInvoicesMap.put(di.Direct_Bill_Customer__c+'_'+di.Disposal_Location__c,di);
            }
            System.debug (di.direct_Bill_Customer__c);
            System.debug (di.Disposal_Location__c);
            System.debug (di.Direct_Bill_Customer__c+'_'+di.Disposal_Location__c);          
        }
        for(FX5__Ticket_Item__c item:items )       
         {
         System.debug (item.Customerforlogiconly__c+'_'+item.Disposal_Location_on_Ticket_item__c);
           if(directInvoicesMap.containsKey(item.Customerforlogiconly__c+'_'+item.Disposal_Location_on_Ticket_item__c)) {
                item.Direct_Bill_Customer__c = True;
                  }
            else {
                item.Direct_Bill_Customer__c = False;
            }
                
        }
        
    }
}
Could you please suggest what is wrong with this. My True condition is not triggering,There are true and False condition, it is always resulting to False.
I have custom object Obj_Direct_Bill_Customer__c with fields Direct_Bill_Customer__c (lookup field) and Disposal_Location__c(lookup field)
Customer object: FX5__Ticket_Item__c with Fields Customerforlogiconly__c (checkbox), Disposal_Location_on_Ticket_item__c (lookup Field) and Test_Direct_Bill_Customer__c (checkbox). If value of Customerforlogiconly__c=Direct_Bill_Customer__c  && Disposal_Location_on_Ticket_item__c=Disposal_Location__c, then update Test_Direct_Bill_Customer__c to True, if not False.


trigger Triggerupdatedirectbill on FX5__Ticket_Item__c (before insert, before update ) {

    if(Trigger.isBefore && (Trigger.isInsert || Trigger.isUpdate) ) {
        List<FX5__Ticket_Item__c> items = Trigger.new;
        Set<String> accountsIds = new Set<String>();
        Set<String> wellsIds = new Set<String>();
        for(FX5__Ticket_Item__c item:items) {
            if(item.Customerforlogiconly__c!= null ) {
               accountsIds.add(item.Customerforlogiconly__c);
            }

            if(item.Disposal_Location_on_Ticket_item__c!= null ) {
                wellsIds.add(item.Disposal_Location_on_Ticket_item__c);
            }
        }

        Map<String, Obj_Direct_Bill_Customer__c> directInvoicesMap = new Map<String, Obj_Direct_Bill_Customer__c>();
        for(Obj_Direct_Bill_Customer__c di :[Select Direct_Bill_Customer__c, Disposal_Location__c from Obj_Direct_Bill_Customer__c where Direct_Bill_Customer__c in :accountsIds and Disposal_Location__c in :wellsIds] ) {
            if(!directInvoicesMap.containsKey(di.Direct_Bill_Customer__c+'-'+di.Disposal_Location__c) ) {
                directInvoicesMap.put(di.Direct_Bill_Customer__c+'-'+di.Disposal_Location__c,di);
            }
        }

        for(FX5__Ticket_Item__c item:items ) {
            if(directInvoicesMap.containsKey(item.Customerforlogiconly__c+'-'+item.Disposal_Location_on_Ticket_item__c) ) {
                item.Test_Direct_Bill_Customer__c = True;
                
            }
            item.Test_Direct_Bill_Customer__c = False;
            
        }
    }
}

Thank you
Hi,

I have custom object called ITEM with three Fields:
  1. CUSTOMER   (lookup field from Account)
  2. LOCATION (lookup from field Well__c)
  3. PRIME CUSTOMER (checkbox)
 
I have another custom field: DIRECT INVOICE where there are only two fields. This is kind of list of combination.
  1. CUSTOMER INVOICE  (lookup field from Account)
  2. LOCATION INVOICE (Lookup field from Well__c)
 
I need to write a trigger (after update, after insert) where if CUSTOMER and LOCATION from object ITEM matches with any of the records  with CUSTOMER INVOICE and LOCATION INVOICE from DIRECT INVOICE, then update a field PRIME CUSTOMER in item to TRUE.
 
I am maintaining a list of combination of customer invoice and location invoice in Direct invoice object, hence any new record of update record in object is to be checked with all records in Direct invoice to find if any records matches.
 
Thank you for your suggestion.
 
Hi,

I am new to Trigger. I want to update field if formula field value is changed. Could you please suggest.
Object: Ticket__c
Field if changed: Bill_to__c
update field: updaterequired__c


trigger Checkprojectbilltoaccount on Ticket__c (before update){
    for(Ticket__c newchange:Trigger.new) {
    Ticket__c oldchange = system.trigger.oldMap.get(newchange.Id);
    if (oldchange.Bill_To__c !=newchange.Bill_To__c) 
        {
              newchange.UpdateRequired__c = True;
              
        }
        }
Hi all,

I have two objects in Master Detail relationship.
Ticket__c  is a Master and Ticket_item__c is Child.
I have related list of Ticket_item__c in Ticket__c but it is standard page and it will show only 10 columns.
I want to display the Ticket_item_c list in Ticket Page Layout with 12 columns. 
Can you please point any sample visualfore page on how to write this.  

Thank you