• Girbson Bijou 8
  • NEWBIE
  • 130 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 27
    Questions
  • 18
    Replies
Hi All,
I have a class where the Coverage is 91% in  a sandbox. But, when  I am deploying it to the production, i received  code Coverage error  and it is 0%. Where do you think the problem is. 

Best, 
I want to test a class with an invocable method. Actually i get 51% Coverage and  at the line 73 in the Test class the error is:

"System.DmlException: Update failed. First exception on row 0 with id a03f0000006BbNwAAK; first error: CANNOT_EXECUTE_FLOW_TRIGGER, We can't save this record because the “Post Affiliate Inventory” process failed. Give your Salesforce admin these details. An Apex error occurred: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: this ID value isn't valid for the user: : [RecordTypeId]
: []


I want to remind that this class is to copy all child records from an object to an other object when a criteria is meet in the parent record. 

Apex Class: 
public class PostToAffiliateInventory {
    
    @InvocableMethod(label ='post to affiliate inventory')
    
    public static void PosttoInv(list<Id> deliveryId){
        
        list <Container__c> con = new List <Container__c>();
        list <Articles_Containers__c> contenairItems = new list <Articles_Containers__c>();
        list <Item_Distributed__c> itemList = new  list<Item_Distributed__c>();
        list <Delivery__c> delList = [SELECT Id, Is_Posted_To_Affiliate_Inventory__c, Affiliate_Center__c,AffiliateCenterId__c, Automatic_Code__c  FROM Delivery__c WHERE Id in :deliveryId];
        
        Id containerRecordTypeCaracole = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('FFP_Caracole').getRecordTypeId();
        Id containerRecordTypePAPCRN = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('CRN_PAP').getRecordTypeId();
        Id containerRecordTypeCanteenPAP = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('Canteen_PAP').getRecordTypeId();
        id crt; 
        
        Id ArticleContainerRecordTypeCaracole = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('FFP_Caracole').getRecordTypeId();
        Id ArticleContainerPAPCRN = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('CRN_PAP').getRecordTypeId();
        Id ArticleContainerCanteenPAP = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('PAP_Canteen').getRecordTypeId();
        id ArticleContainerAdmin = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('Admin').getRecordTypeId();
        id acrt;
        
        Container__c c;
        
        for (Delivery__c d : delList){
            if (d.Is_Posted_To_Affiliate_Inventory__c){
                if(d.Affiliate_Center__c =='FFP Caracole'){
                    crt = containerRecordTypeCaracole;
                }else if(d.Affiliate_Center__c =='CRN PAP'){
                    crt = containerRecordTypePAPCRN;
                }else if(d.Affiliate_Center__c =='PAP Canteen'){
                    crt = containerRecordTypeCanteenPAP;
                }
                c = new  Container__c();
                c.Name = d.Automatic_Code__c;
                c.FFP_Centers__c = d.Affiliate_Center__c ;
                c.RecordTypeId = crt;
                c.Distribution_Center__c = d.AffiliateCenterId__c;
                c.Is_Owner_Shipper__c = 'No';
                c.Provenance__c = 'FFP PAP';
                c.Type__c = 'Food';
                c.Shipment_Status__c = 'A - AWAITING ARRIVAL';
                c.Is_Automatic_Creation__c = TRUE;
                
                insert c;
                
                itemList = [SELECT id,Name, Product__r.Expiration_Date__c,Product__r.Unit_Cost__c,   
                            Product__r.Lot_Number__c,  Product__r.Unit_Weight__c ,
                            Product__r.UM__c, Product__r.Product__r.Id , Quantity__c 
                            FROM Item_Distributed__c  where Delivery__c  =: d.id ];             
                
                for (Item_Distributed__c OrderItems: itemList){
                    Articles_Containers__c ac = new Articles_Containers__c();
                    if(c.FFP_Centers__c == 'FFP Caracole'){
                        acrt = ArticleContainerRecordTypeCaracole;
                    }else if(c.FFP_Centers__c == 'CRN PAP'){
                        acrt = ArticleContainerPAPCRN;
                    }else if (c.FFP_Centers__c == 'PAP Canteen'){
                        acrt = ArticleContainerCanteenPAP;
                    }else acrt = ArticleContainerAdmin;
                    
                    ac.FFP_Centers__c = d.Affiliate_Center__c ;
                    ac.RecordTypeId = acrt; 
                    ac.Container__c =c.Id;
                    ac.Product__c = OrderItems.Product__r.Product__r.Id;
                    ac.Number__c= 0;
                    ac.Quantity__c = OrderItems.Quantity__c;
                    ac.Unit_Of_Measure_Paking__c= OrderItems.Product__r.UM__c;
                    ac.UM__c = OrderItems.Product__r.UM__c;
                    ac.Expiration_Date__c = OrderItems.Product__r.Expiration_Date__c;
                    ac.Lot_Number__c = OrderItems.Product__r.Lot_Number__c;
                    ac.Unit_Cost__c = OrderItems.Product__r.Unit_Cost__c;
                    ac.Unit_Weight__c =OrderItems.Product__r.Unit_Weight__c;
                    ac.DeliveryItemsReferences__c = OrderItems.id;
                    
                    contenairItems.add(ac);
                }      
                Insert contenairItems; 

            }
            
        } 
    }
}

Test Class: 
@IsTest
public class PostToAffiliateInventoryTest {
    
     @isTest static  void PostToAffiliateInv (){
        Account afc = new Account(Name ='test Account parent', Representant__c ='hkjlhjd', 
                                 Distribution_Center__c='FFP Caracole', Class__c = 'Clinic', Type = 'CLINICS', 
                                 Departement__c = 'NORD', Address__c ='Test Address');
        
        Account pa = new Account(Name ='Central Office', Representant__c ='hkjlhjd', 
                                 Distribution_Center__c='Central Office', Class__c = 'Clinic', Type = 'CLINICS', 
                                 Departement__c = 'OUEST', Address__c ='Test Address');
        
        insert pa;
   
        Product2 p = new Product2(Name ='TestProduct'); 
        insert p;
        Container_Shipper__c cs =new Container_Shipper__c(Name = 'Test Shipper');
        insert cs;
        
        //Id containerRecordTypeCaracole =      Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('FFP_Caracole').getRecordTypeId();
        //Id containerRecordTypeCentralOffice = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('Central Office').getRecordTypeId();
        Container__c c = new Container__c( Name = 'CMLU', Provenance__c='FFP FLORIDA', Statut__c='Open', Distribution_Center__c= pa.id, FFP_Centers__c = 'Central Office',  RecordTypeId='0126A000000nMlj',  Shipper__c=cs.Id );
        insert c;
        
       // Id ArticleContainerRecordTypeCaracole = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('FFP_Caracole').getRecordTypeId();
       // Id ArticleContainerRecordTypeCentralOffice = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('HT Central Office').getRecordTypeId();
        Articles_Containers__c ac = new Articles_Containers__c();   
        
        ac.Product__c=p.ID;
        ac.Unit_Weight__c = 45; 
        ac.Unit_Cost__c = 87;
        ac.Container__c= c.ID;
        ac.Number__c = 55;
        ac.UM__c ='UNIT(S)';    
        ac.Local_ID__c = 7888;
        ac.Comments__c = 'UNIT(S)';
        ac.Purpose__c='Consignment';
        ac.Condition__c= 'New';
        ac.FFP_Centers__c = 'Central Office';
        ac.RecordTypeId = '0126A0000019jRK';
        insert ac;
        
        Account a = new Account();
        a.Name ='test Account'; 
        a.Representant__c ='Bijou';
        a.Distribution_Center__c='Central Office';
        a.Class__c = 'NGO'; 
        a.Type = 'CLINICS';
        a.Departement__c = 'NORD';
        a.Address__c ='Test Address';
        a.ParentId = pa.ID;
        a.Affiliate_Center__c = afc.Id;
        insert a ;
       
        
        Delivery__c del = new Delivery__c();
        del.Beneficiaire__c = a.Id;
        del.Ration__c =3;
        del.Delivery_status__c='Pending';
       
        del.Is_Posted_To_Affiliate_Inventory__c = false;
        
        insert del;
        
        Item_Distributed__c itemDis = new Item_Distributed__c();
        itemDis.Quantity__c = 10;
        itemDis.Product__c = ac.Id;
        itemDis.Delivery__c =del.Id;
     
        insert itemDis;
        
        del.Is_Posted_To_Affiliate_Inventory__c = true;
        update del;
        
        
        List<Delivery__c> delivery_Obj  =  [SELECT Beneficiaire__c from Delivery__c];
        System.assertEquals(1,delivery_Obj.size());
        List<Item_Distributed__c> item_distributed_Obj  =  [SELECT Product__c,Quantity__c,Delivery__c from Item_Distributed__c];
        System.assertEquals(1,item_distributed_Obj.size());

        PostToAffiliateInventory pav = new PostToAffiliateInventory();
      
    }
    
}


 
I have this Trigger which works well but i would to use a class with a quick action instead. Please help me to transform this trigger to an apex class. 
trigger PostToAfficliateInventory on Delivery__c (after update) {
    
    list <Container__c> con = new List <Container__c>();
    list <Articles_Containers__c> contenairItems = new list <Articles_Containers__c>();
    list <Item_Distributed__c> itemList = new  list<Item_Distributed__c>();
    
    Id containerRecordTypeCaracole = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('FFP_Caracole').getRecordTypeId();
    Id containerRecordTypePAPCRN = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('CRN_PAP').getRecordTypeId();
    Id containerRecordTypeCanteenPAP = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('Canteen_PAP').getRecordTypeId();
    id crt; 
    
    Id ArticleContainerRecordTypeCaracole = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('FFP_Caracole').getRecordTypeId();
    Id ArticleContainerPAPCRN = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('CRN_PAP').getRecordTypeId();
    Id ArticleContainerCanteenPAP = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('PAP_Canteen').getRecordTypeId();
    id ArticleContainerAdmin = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('Admin').getRecordTypeId();
    id acrt;
    
    Container__c c;
    for (Delivery__c d : Trigger.New){
        if (d.Is_Posted_To_Affiliate_Inventory__c){
            if(d.Affiliate_Center__c =='FFP Caracole'){
                crt = containerRecordTypeCaracole;
            }else if(d.Affiliate_Center__c =='CRN PAP'){
                crt = containerRecordTypePAPCRN;
            }else if(d.Affiliate_Center__c =='PAP Canteen'){
                crt = containerRecordTypeCanteenPAP;
            }
            c = new  Container__c();
            c.Name = d.Automatic_Code__c;
            c.FFP_Centers__c = d.Affiliate_Center__c ;
            c.RecordTypeId = crt;
            c.Distribution_Center__c = d.AffiliateCenterId__c;
            c.Is_Owner_Shipper__c = 'No';
            c.Provenance__c = 'FFP PAP';
            c.Type__c = 'Food';
            c.Shipment_Status__c = 'A - AWAITING ARRIVAL';
            c.Is_Automatic_Creation__c = TRUE;
            
            insert c;
            
            itemList = [SELECT id,Name, Product__r.Expiration_Date__c,Product__r.Unit_Cost__c,   
                        Product__r.Lot_Number__c,  Product__r.Unit_Weight__c ,
                        Product__r.UM__c, Product__r.Product__r.Id , Quantity__c 
                        FROM Item_Distributed__c  where Delivery__c  =: d.id ];             
            
            for (Item_Distributed__c OrderItems: itemList){
                Articles_Containers__c ac = new Articles_Containers__c();
                if(c.FFP_Centers__c == 'FFP Caracole'){
                    acrt = ArticleContainerRecordTypeCaracole;
                }else if(c.FFP_Centers__c == 'CRN PAP'){
                    acrt = ArticleContainerPAPCRN;
                }else if (c.FFP_Centers__c == 'PAP Canteen'){
                    acrt = ArticleContainerCanteenPAP;
                }else acrt = ArticleContainerAdmin;
                
                ac.FFP_Centers__c = d.Affiliate_Center__c ;
                ac.RecordTypeId = acrt; 
                ac.Container__c =c.Id;
                ac.Product__c = OrderItems.Product__r.Product__r.Id;
                ac.Number__c= 0;
                ac.Quantity__c = OrderItems.Quantity__c;
                ac.Unit_Of_Measure_Paking__c= OrderItems.Product__r.UM__c;
                ac.UM__c = OrderItems.Product__r.UM__c;
                ac.Expiration_Date__c = OrderItems.Product__r.Expiration_Date__c;
                ac.Lot_Number__c = OrderItems.Product__r.Lot_Number__c;
                ac.Unit_Cost__c = OrderItems.Product__r.Unit_Cost__c;
                ac.Unit_Weight__c =OrderItems.Product__r.Unit_Weight__c;
                ac.DeliveryItemsReferences__c = OrderItems.id;
                
                contenairItems.add(ac);
            }
            
            Insert contenairItems; 
            
        }
        
    } 
}

 
Considering the attached Picture, i want to copy the A Delivery with all its related list to Container and Related List.  I mean,  The Value of Delivey will be a new record in the object Container and the Item Distributed of the object Delivery will become Arcticle Container for the object Container. 
The Code below saved well but it fires with the following error :
caused by: System.ListException: Before Insert or Upsert list must not have two identically equal elements. Line 51
trigger PostToAfficliateInventory on Delivery__c (after update) {

list <Container__c> con = new List <Container__c>();
list <Articles_Containers__c> contenairItems = new list <Articles_Containers__c>();

    for (Delivery__c d : Trigger.New){
         if (d.Is_Posted_To_Affiliate_Inventory__c){
             Container__c c = new  Container__c();
             c.Name = d.Automatic_Code__c;
             c.FFP_Centers__c = d.Affiliate_Center__c ;
             c.RecordTypeId = '0126A000000nMlU';
             c.Distribution_Center__c = d.AffiliateCenterId__c;
             c.Is_Owner_Shipper__c = 'No';
             c.Provenance__c = 'FFP PAP';
             c.Type__c = 'Food';
             c.Shipment_Status__c = 'A - AWAITING ARRIVAL';
             c.Is_Automatic_Creation__c = TRUE;
             
             con.add(c);  
             insert con;
          
             Articles_Containers__c ac = new Articles_Containers__c();
             list<Item_Distributed__c> itemList = new  list<Item_Distributed__c>();
             
             
             itemList = [SELECT id,Name, Product__r.Expiration_Date__c,Product__r.Unit_Cost__c,   
                                 Product__r.Lot_Number__c,  Product__r.Unit_Weight__c ,
                                 Product__r.UM__c, Product__r.Product__r.Id , Quantity__c 
                         FROM Item_Distributed__c  
                         WHERE Delivery__c =: d.Id];
          
             for (Item_Distributed__c OrderItems: itemList){

                 for(Integer i = 0; i<itemList.Size(); i++){
                     ac.FFP_Centers__c = d.Affiliate_Center__c ;
                    ac.RecordTypeId = '0126A0000019jRJ'; 
                     ac.Container__c =c.Id;
                     ac.Product__c = OrderItems.Product__r.Product__r.Id;
                     ac.Number__c= 0;
                     ac.Quantity__c = OrderItems.Quantity__c;
                     ac.Unit_Of_Measure_Paking__c= OrderItems.Product__r.UM__c;
                     ac.UM__c = OrderItems.Product__r.UM__c;
                     ac.Expiration_Date__c = OrderItems.Product__r.Expiration_Date__c;
                     ac.Lot_Number__c = OrderItems.Product__r.Lot_Number__c;
                     ac.Unit_Cost__c = OrderItems.Product__r.Unit_Cost__c;
                     ac.Unit_Weight__c =OrderItems.Product__r.Unit_Weight__c;
                     
                     contenairItems.add(ac);
                     Insert contenairItems;
                }
             }          
         }
    } 
}

User-added image
I have a requirement to create record on Salesforce From NAV Dynamic (microsoft) when a Criteria is meet on NAV Dynamic.  my first Idea is to use Salesforce Connect to create External objects in Salesforce Mapped to NAV and than, i would create a trigger on the External in Salesforce to copy the data into intern object when the criteria is met.  Let me know if i am correct or propose me a better solution. I am looking for a free solution.

Thank you
Hi all, 
I have a 'Text Area (Long)'  Field called  All_Products_List__c  wich will be populate by a trigger. To avoid error, i want to limit the number of caracter sto the max vaklue of Text Area (Long). 
The code  save well but when i run  the test class, The error is: "Ending position out of bounds: 131072".  
 
trigger DeliveryNotification on Item_Distributed__c (after update, after insert, after delete, after undelete){

    List <Item_Distributed__c> deliveryItems = (Trigger.isInsert|| Trigger.isUnDelete) ? Trigger.new : Trigger.old;
    
    List <Id> delveryId = new List<Id> ();
    String fullProduct;
    
    for (Item_Distributed__c allDeliveryItems : deliveryItems) {
           delveryId.add(allDeliveryItems.Delivery__c);
   }
   
   List< Delivery__c> deliveryList = [ SELECT id, All_Products_List__c, (SELECT Product_With_UOM__c  from  Items_Distributed__r ) From Delivery__c 
                                    Where id in:delveryId];
                                    
    for (Delivery__c del: deliveryList){
        if (del.Items_Distributed__r.size()>0){
            //camp.Product_With_UOM__c = string.valueOf(del.Items_Distributed [0].Product_With_UOM__c);
            del.All_Products_List__c = '';
            for(Item_Distributed__c member : del.Items_Distributed__r )
               fullProduct = del.All_Products_List__c + member.Product_With_UOM__c + ' ,';
                del.All_Products_List__c = fullProduct.substring(131072);
        }
            else
            del.All_Products_List__c = null;
        }   
                    update deliveryList;

 
I Want to sum 2 block in a Join report .  As you can see in the picture, when the second block is Blank , SF does not consider it as zero and the calculation is not made. Hoe can you help me?User-added image
Please help me to increase the code coverage of this class. actually is is only at 25%. the class is to increment in field each time a visualforce page called "DeliveryPage" is launched.  This field is on an object called Delivery__c which is a child of Account
public class DeliveryPageClass {
   // public Delivery__c delivery{get;set;}
public id deliveryId;
    public DeliveryPageClass(ApexPages.StandardController stdController)
    {
        deliveryId=stdController.getId();
     
    }
    public void updateDelivery()
    {
        Delivery__c delivery = [select id,Print_Counter__c from Delivery__c where id=:deliveryId];
        if(delivery.Print_Counter__c==null)
        {
            delivery.Print_Counter__c=1;
        }
        else
        {
            delivery.Print_Counter__c=delivery.Print_Counter__c+1;
        }
        system.debug(delivery);
        update delivery;
        system.debug(delivery);
        
    }

}

Test Class
@isTest
public class DeliveryPageClassTest {
    static testMethod void TestDeliveryPageClass(){
     Account pa = new Account(Name ='test Account parent', Representant__c ='hkjlhjd', 
     Distribution_Center__c='CRD Cayes', Class__c = 'Clinic', Type = 'CLINICS', 
     Departement__c = 'NORD', Address__c ='Test Address');
     insert pa;
         
 Account a = new Account();
 a.Name ='test Account'; 
 a.Representant__c ='Bijou';
 a.Distribution_Center__c='FFP Caracole';
 a.Class__c = 'NGO'; 
 a.Type = 'CLINICS';
 a.Departement__c = 'NORD';
 a.Address__c ='Test Address';
 a.ParentId = pa.ID;
 insert a ;
    
        Delivery__c del = new Delivery__c();
        del.Beneficiaire__c = a.Id;
        del.Ration__c =3;
        del.Delivery_status__c='Pending';
        
        insert del;
          
       
        ApexPages.StandardController sc = new ApexPages.standardController(new Delivery__c());
        DeliveryPageClass dpc = new DeliveryPageClass(sc);
    }
}
 
 
can someone give me a step by step guide to migrate an org to an other one? I need to migrate the metadata only. 
Thank you
I Have a lookup relationship in  to the same object ( Articles_Containers__c). The lookup field is ParentItem__c. I need to display on a VF Page All parents and Child related to them  below them. 
I want to make sure that the child be right after their parent (in the next line as in the attached screenshot. For Now, the visualforce launch without error but it only display the parent records, but not the child. 
// Controller 

public class RGRPart1Controller {
    public Container__c container {get;set;}
    public Map<String,List<Articles_Containers__c>> ContainerItem{get;set;}
    String containerId;
    
    public RGRPart1Controller(){
    
    container = new Container__c();
        ContainerItem = new Map<String,List<Articles_Containers__c>>();
        
        try
        {
    
        containerId = ApexPages.currentPage().getParameters().get('id');
        container = [SELECT Id,Name,DR__c, PO__c,Arrived_Date__c, 
                     Invoice__c, Pkl__c, Description__c, 
                     Container__c.Provenance__c, Percent_Distributed__c, 
                     Bill_of_Lading__c, Size_in_feet__c, Seal_No__c, 
                         (SELECT Id,Name,Prod__c,Number__c,
                          Number_Distributed__c,Available__c,UM__c, Quantity__c,Unit_Of_Measure_Paking__c,
                          Pending__c, Percentagedistributed__c, Lot_Number__c ,Qty_Recieved_in_Paking_UoM__c,PrimaryDiscrepency__c,Action__c
                          FROM Articles_Containers__r WHERE ParentItem__c = NULL  )
                     FROM Container__c WHERE Id =:containerId];
        
          if(container != null)
            {
                Set<Id> articleContainersParentId = new Set<Id>();
                
                if(!container.Articles_Containers__r.isEmpty())
                {
                    for(Articles_Containers__c art :container.Articles_Containers__r)
                    {
                        articleContainersParentId.add(art.Id);
                        ContainerItem.put(art.Id, new List<Articles_Containers__c>());
                    }
                }
    
      List<Articles_Containers__c> lstChildArticleContainer = new List<Articles_Containers__c>();
                
                 lstChildArticleContainer = [SELECT Id,
                                                    Name,
                                                    Prod__c,
                                                    Number__c,
                                                    Number_Distributed__c,
                                                    Available__c,
                                                    UM__c,
                                                    Quantity__c, 
                                                    Pending__c, 
                                                    Percentagedistributed__c, 
                                                    Lot_Number__c, 
                                                    Qty_Recieved_in_Paking_UoM__c, 
                                                    PrimaryDiscrepency__c, 
                                                    Unit_Of_Measure_Paking__c,
                                                    Action__c 
                                               FROM Articles_Containers__c
                                               WHERE ParentItem__c IN : articleContainersParentId];
                                               
               if(!lstChildArticleContainer.isEmpty())
                {
                    for(Articles_Containers__c childItem :lstChildArticleContainer)
                    {
                        if(ContainerItem.containsKey(childItem.ParentItem__c))
                        {
                            ContainerItem.get(childItem.ParentItem__c).add(childItem);
                        }
                    }
                }
            }         
        }
        catch(Exception e)
        {
            System.debug(e.getMessage());
        }
    
}
}

The Body of the VF Page
//VF Page

<apex:page renderAs="pdf"  Controller="RGRPart1Controller"> 
 <table width="100%"> 
			 <tr> 
					 <th>Record ID</th> 
					 <th>Product</th>
					 <th>Qty Packing</th> 
					 <th>UOM Packing</th>
					 <th>Qty revieved in packing UoM</th> 
					 <th>Qty Recorded</th> 
					 <th>Uom Recorded</th> 
					 <th>Discrepencies</th>
					 <th>Action</th>
			 </tr> 
	 <apex:repeat var="c" value="{!container.Articles_Containers__r}"> 
			 <tr>
					 <td>{!c.Name}</td>
					 <td>{!c.Prod__c}</td>
					 <td>{!c.Quantity__c}</td>
					 <td>{!c.Unit_Of_Measure_Paking__c}</td>
					 <td>{!c.Qty_Recieved_in_Paking_UoM__c}</td>
					 <td>{!c.Number__c}</td>
					 <td>{!c.UM__c}</td>
					 <td>{!c.PrimaryDiscrepency__c}</td> 
					 <td>{!c.Action__c}</td> 
			 
			 </tr>
				 
		   <apex:repeat var="childItem" value="{!ContainerItem[c.Id]}"> 
			 <tr>
					 <td>--{!childItem.Name}</td>
					 <td>{!childItem.Prod__c}</td>
					 <td>{!childItem.Quantity__c}</td>
					 <td>{!childItem.Unit_Of_Measure_Paking__c}</td>
					 <td>{!childItem.Qty_Recieved_in_Paking_UoM__c}</td>
					 <td>{!childItem.Number__c}</td>
					 <td>{!childItem.UM__c}</td>
					 <td>{!childItem.PrimaryDiscrepency__c}</td> 
					 <td>{!childItem.Action__c}</td> 
			 </tr>
		   </apex:repeat>
	 </apex:repeat>
 </table> 
</apex:page>


User-added image
 
I need to implement a validation rule which should take effect  for all new record created after a specific date. I have a field called  Unit_Cost__c , this field can not be blank for all records created after  July 25, 2019. Below is a draft of my work.  The error message is: Syntax error. Missing ')'

AND(DateValue(CreatedDate)=>Date(2019, 07,25 ), 
(ISBLANK(  Unit_Cost__c  )))
Hi All ,
I follow the Steps in the  link below to filter data but i do not see the Button to Fetch the data when i load the visualforce page. 
https://blog.jeffdouglas.com/2010/07/13/building-a-dynamic-search-page-in-visualforce/

Help me please
<apex:page controller="allItems" sidebar="false">

  <apex:form >
  <apex:pageMessages id="errors" />
  
  <apex:pageBlock title="Find Me A Customer!" mode="edit">
    
  <table width="100%" border="0">
  <tr>  
    <td width="200" valign="top">
  
      <apex:pageBlock title="Parameters" mode="edit" id="criteria">
      
      <script type="text/javascript">
      function doSearch() {
        searchServer(
          document.getElementById("Product").value,
          document.getElementById("Comments").value,
          document.getElementById("Lot_Number").value,
          document.getElementById("centers").options[document.getElementById("technology").selectedIndex].value
          );
      }
      </script> 
      
      <apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
          <apex:param name="Product" value="" />
          <apex:param name="lastName" value="" />
          <apex:param name="Lot_Number" value="" />
          <apex:param name="centers" value="" />
      </apex:actionFunction>
          
      <table cellpadding="2" cellspacing="2">
      <tr>
        <td style="font-weight:bold;">Product Name<br/>
        <input type="text" id="Product" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">Comments<br/>
        <input type="text" id="Comments" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">Lot Number<br/>
        <input type="text" id="Lot_Number" onkeyup="doSearch();"/>
        </td>
      </tr>
      <tr>
        <td style="font-weight:bold;">FFP Centers<br/>
          <select id="centers" onchange="doSearch();">
            <option value=""></option>
            <apex:repeat value="{!centerss}" var="tech">
              <option value="{!tech}">{!tech}</option>
            </apex:repeat>
          </select>
        </td>
      </tr>
      </table>
      
      </apex:pageBlock>
  
    </td>
    <td valign="top">
    
    <apex:pageBlock mode="edit" id="results">
                
        <apex:pageBlockTable value="{!allProduct}" var="allProd">
        
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Product Name" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="Product_Hiden_Name__c" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!allProd.Product_Hiden_Name__c}"/>
            </apex:column>
            
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Comments" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="Comments__c" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!allProd.Comments__c}"/>
            </apex:column>
            
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="Lot_Number" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="Lot_Number__c" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!allProd.Lot_Number__c}"/>
            </apex:column>
            
            <apex:column >
                <apex:facet name="header">
                    <apex:commandLink value="centers" action="{!toggleSort}" rerender="results,debug">
                        <apex:param name="sortField" value="FFP_Centers__c" assignTo="{!sortField}"/>
                    </apex:commandLink>
                </apex:facet>
                <apex:outputField value="{!allProd.FFP_Centers__c}"/>
            </apex:column>
            
        </apex:pageBlockTable>
                
    </apex:pageBlock>
    
    </td>
  </tr>
  </table>
  
  <apex:pageBlock title="Debug - SOQL" id="debug">
      <apex:outputText value="{!debugSoql}" />           
  </apex:pageBlock>    
  
  </apex:pageBlock>

  </apex:form>

</apex:page>

Controller:   I get the following  in the  lines 61, 63, 65 when i use the quote ' ' in the Original post.
Compile Error: Found punctuation symbol or operator '%' that isn't valid in Apex. at line 61 column 85
public with sharing class allItems {
  
  // the soql without the order and limit
  private String soql {get;set;}
  // the collection of contacts to display
  public List<Articles_Containers__c> allProduct {get;set;}
  
  // the current sort direction. defaults to asc
  public String sortDir {
    get  { if (sortDir == null) {  sortDir = 'asc'; } return sortDir;  }
    set;
  }
  
  // the current field to sort by. defaults to last name
  public String sortField {
    get  { if (sortField == null) {sortField = '    FFP_Centers__c'; } return sortField;  }
    set;
  }
  
  // format the soql for display on the visualforce page
  public String debugSoql {
    get { return soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20'; }
    set;
  }

  // init the controller and display some sample data when the page loads
  public allItems() {
    soql = 'select Name ,Left_Warehouse_and_Delivered__c, Lot_Number__c, Expiration_Date__c, Product_Hiden_Name__c,FFP_Centers__c,Prod__c,UM__c, Container__c, Number__c, On_Hand__c,  Pending__c,  Available__c, Purpose__c, Condition__c, Age__c, Comments__c , Prod__c FROM Articles_Containers__c WHERE On_Hand__c >0  AND IsOpened__c = 1 ORDER BY FFP_Centers__c, Prod__c,UM__c ,Number__c';
    runQuery();
  }
  
  // toggles the sorting of query from asc<-->desc
  public void toggleSort() {
    // simply toggle the direction
    sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
    // run the query again
    runQuery();
  }
  
  // runs the actual query
  public void runQuery() {
        
    try {
      allProduct = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' limit 20');
    } catch (Exception e) {
      ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Ooops!'));
    }

  }
  
  // runs the search with parameters passed via Javascript
  public PageReference runSearch() {
    
    String Product = Apexpages.currentPage().getParameters().get('Product_Hiden_Name__c');
    String Comments = Apexpages.currentPage().getParameters().get('Comments__c');
   String Lot_Number = Apexpages.currentPage().getParameters().get('Lot_Number__c');
    String centers = Apexpages.currentPage().getParameters().get('FFP_Centers__c');
    
    soql = 'select Name ,Left_Warehouse_and_Delivered__c, Lot_Number__c, Expiration_Date__c, Product_Hiden_Name__c,FFP_Centers__c,Prod__c,UM__c, Container__c, Number__c, On_Hand__c,  Pending__c,  Available__c, Purpose__c, Condition__c, Age__c, Comments__c , Prod__c FROM Articles_Containers__c WHERE On_Hand__c >0  AND IsOpened__c = 1 ORDER BY FFP_Centers__c, Prod__c,UM__c ,Number__c';
   if (!Product.equals(''))
    soql += ' and Product LIKE "+String.escapeSingleQuotes(Product_Hiden_Name__c)+"%';
   if (!Comments.equals(''))
   soql += ' and Comments__c LIKE "+String.escapeSingleQuotes(Comments__c)+"%';
   if (!Lot_Number.equals(''))
     soql += 'and Lot_Number__c LIKE "+String.escapeSingleQuotes(Lot_Number__c)+"%';  
    if (!centers.equals(''))
      soql += 'and FFP_Centers__c includes ("+centers+")';

    // run the query again
    runQuery();

    return null;
  }
  
  // use apex describe to build the picklist values
  public List<String> centerss {
    get {
      if (centerss == null) {
              
        centerss = new List<String>();
        Schema.DescribeFieldResult field = Articles_Containers__c.FFP_Centers__c.getDescribe();
            
        for (Schema.PicklistEntry f : field.getPicklistValues())
          centerss.add(f.getLabel());
          
      }
      return centerss;          
    }
    set;
  }

}

​​​​​​​
Hi want to know if a record is already printed. I have a check box field called IsPrinted And a Visualforce page with a standard Controller. This VF page is rendered as PDF. Please help me to update the field 'IsPrinted'   when i print the page. Thanks 
Here is a portion of  my page
<apex:page renderAs="PDF"  readOnly="true" showHeader="false" sidebar="false"  applyHtmlTag="false"   standardStylesheets="false"  standardController="Delivery__c"  applyBodyTag="false" >    

    
    
    <!--<apex:stylesheet value="{!$Resource.CSSPrintPageDistrib}" />-->
    <div class="header">        
        <div class="col logo">
            <apex:image url="{!$Resource.LogoFFP}" width="140" height="60"/>
        </div>
        <div class ="col name"> 
            <h2>
                COMPANY Name
            </h2>           
            <h6>
                 {!Delivery__c.Beneficiaire__r.Parent.Distribution_Center__c} , 
                {!Delivery__c.Beneficiaire__r.Parent.Address__c }
                 Tels: {!Delivery__c.Beneficiaire__r.Parent.Phone} 
            </h6>
        </div>  
         <h4>DELIVERY ORDER</h4>
    <div class="firstBlock" > 
        
        <div class ="SubfirstBlock">
            <div>
                <b> Code:  {!Delivery__c.Name} </b>
            </div>
            <div>
                <b>Prochaine Livraison:</b>------------------------ 
            </div>
        </div>
        <div class ="SubfirstBlock">
            <div>
                <b>Status  :</b> {!Delivery__c.Delivery_status__c}  &nbsp;&nbsp; {!Delivery__c.Control_Status__c}     
            </div>
            <div>
                <b> Created By:</b> {!Delivery__c.CreatedBy.FirstName} {!Delivery__c.CreatedBy.LastName} <apex:outputtext value="{0, date, short}">
        <apex:param value="{!Delivery__c.CreatedDate}"></apex:param>  </apex:outputtext> <br/>
            </div>
        </div>
    </div>   
        <div class = "beneInfo">
        <div class ="tableBeneinfo">
            <b> Recipient Code : {! Delivery__c.Beneficiaire__r.Ext_ID__c} <br/></b>
            <b>Name   :</b> {!Delivery__c.Beneficiaire__r.Name}   <br/> 
            <b>Contact Pers.    :</b> {!Delivery__c.RepresentantBenficiaire__c}<br/>
            <b>Telephone    :</b> {!Delivery__c.Beneficiaire__r.Phone}<br/>
        </div>  
        <div class ="tableBeneinfo">
            <b>Category   :</b> {!Delivery__c.Beneficiaire__r.Type}<br/> 
            <b>Departement  :</b> {!Delivery__c.Beneficiaire__r.Departement__c} <br/>
            <b>Region  :</b> {!Delivery__c.Beneficiaire__r.Commune__c}   <br/>     
            <b>Benef.   :</b> {!Delivery__c.Beneficiaire__r.Number_of_Beneficiaries__c} <br/> 
             <b>Comments  :</b>  {!Delivery__c.Comments__c}
               
        </div>
    </div>
        
    </div> 
    
    
    <div class="footer" >    

               Printed by :  {!$User.FirstName} {!$User.LastName} <apex:outputtext value="{0, date, long}">
        <apex:param value="{!NOW()}"></apex:param>
    </apex:outputtext> <br/>
            As often as you did it for one of my  least brothers, you did it for me. Matthiew 25:40 <br/>
            <div>Page <span class="pagenumber"/> of <span class="pagecount"/></div>
     
        </div>
     
    <br/>
  
    <div class="table">
        
        <div class="tableHeader">       
            <th>ID </th> 
            <th>Product  </th> 
            <th>Quantity </th> 
            <th>UM </th> 
            
        </div>
        
        <apex:repeat var="c"  value="{!Delivery__c.Items_distributed__r}"> 
         <!--  <div class="tablebody"> -->
               <tr >
                
                <td>{!c.Product__r.Name}</td>
                <td>{!c.Productt__c}</td> 
                <td>{!Text(c.Quantity__c)}</td>
                <td>{!c.UM__c}</td>
            </tr> 
            <!--</div> -->
        </apex:repeat>
        
            <div class ="recommendation">
      
        En recevant ces articles, vous consentez à:<br/> 
        - ne pas les vendre <br/> 
        - maintenir des archives pouvant etre consultées a tout moment<br/>
        - les utiliser uniquement au benefice des plus pauvres <br/> 
        - accorder l'acces a vos depots en tout temps aux inspecteurs de Food For the Poor. <b/> <b/> 
        .
    </div>
                  
           <div class ="signature" >
        
        <div class="tableBeneinfo">
            
            <div>Authorized Signature </div>
            <br/> 
            <br/>
           
            <div>Delivered by </div><div> Date</div>
            <br/> 
            <br/>
            
            <div>Received by &nbsp;&nbsp;   </div><div>   &nbsp;&nbsp; Date  &nbsp;&nbsp;</div>
            <br/> 
            <br/>
            
        </div>
        <div class="tableBeneinfo">
            
            <div>Controlled by </div><div> Date </div>
            <br/> 
            <br/>
            
            <div>Register by </div><div> Date</div>
            <br/> 
            <br/>
                                                                                                 
            <div>Vehicule information </div><div> Date</div>
            
             
        </div>
    </div>
    </div>
    
    
</apex:page>

 
Help to solve this please: Illegal assignment from Decimal to String at line 34 column 4 in the test class
public with sharing class InventorySearchController { 
public list <Articles_Containers__c> inventoryItem {get;set;} 
public string searchstring {get;set;} 
public InventorySearchController( ) { 
} 
public void search(){ 
string searchquery= 'select Name , FFP_Centers__c,Prod__c, UM__c, Container__c, Number__c, On_Hand__c,  Pending__c,  Available__c, Purpose__c, Condition__c, Age__c, Comments__c FROM Articles_Containers__c  WHERE Prod__c like \'%'+searchstring+'%\'  AND On_Hand__c >0  AND IsOpened__c = 1  ORDER BY FFP_Centers__c, Prod__c,UM__c Number__c Limi 1000';
     
      inventoryItem= Database.query(searchquery); 

}
public void clear(){ 
inventoryItem.clear(); 
} 
}


@isTest
private class InventorySearchController_Test{
  @testSetup
  static void setupTestData(){
     test.startTest();
    Account pa = new Account(Name ='test Account parent', Representant__c ='hkjlhjd', 
    Distribution_Center__c='CRD Cayes', Class__c = 'Clinic', Type = 'CLINICS', 
    Departement__c = 'NORD', Address__c ='Test Address');
    insert pa;
    
          Product2 p = new Product2(Name ='TestProduct'); 
          insert p;
          Container_Shipper__c cs =new Container_Shipper__c(Name = 'Test Shipper');
          insert cs;
    Container__c container_Obj = new Container__c(Provenance__c = 'FFP FLORIDA', Distribution_Center__c= pa.id, Statut__c = 'Open',  FFP_Centers__c = 'FFP Caracole', 
     RecordTypeId='0126A000000nMlU',  Shipper__c=cs.Id );
    Insert container_Obj; 
    Articles_Containers__c articles_containers_Obj = new Articles_Containers__c(Container__c = container_Obj.id, Number__c = 17, UM__c = 'BAG(S)' ,  Local_ID__c = 7888, Product__c=p.ID,
            Comments__c = 'UNIT(S)',
           Purpose__c='Consignment',
            Condition__c= 'New',
           FFP_Centers__c = 'FFP Caracole'
            );
    Insert articles_containers_Obj; 
    test.stopTest();
  }
  static testMethod void test_search_UseCase1(){
    List<Container__c> container_Obj  =  [SELECT Provenance__c,Statut__c,Is_Reported__c,FFP_Centers__c  from Container__c];
    System.assertEquals(true,container_Obj.size()>0);
    List<Articles_Containers__c> articles_containers_Obj  =  [SELECT Container__c,Number__c,UM__c from Articles_Containers__c];
    System.assertEquals(true,articles_containers_Obj.size()>0);
    InventorySearchController obj01 = new InventorySearchController();
    obj01.inventoryItem = articles_containers_Obj;
 //Illegal assignment from Decimal to String at line 34 column 4      
obj01.searchstring =  articles_containers_Obj[0].Number__c;
    obj01.search();
  }
  static testMethod void test_clear_UseCase1(){
    List<Container__c> container_Obj  =  [SELECT Provenance__c,Statut__c,Is_Reported__c,FFP_Centers__c from Container__c];
    System.assertEquals(true,container_Obj.size()>0);
    List<Articles_Containers__c> articles_containers_Obj  =  [SELECT Container__c,Number__c,UM__c from Articles_Containers__c];
    System.assertEquals(true,articles_containers_Obj.size()>0);
    InventorySearchController obj01 = new InventorySearchController();
    obj01.inventoryItem = articles_containers_Obj;
   // obj01.searchstring = articles_containers_Obj[0].Number__c;
    obj01.clear();
  }
}

 
Hi all, Help me please. 
I want display a field value of a Rich text area in a Visualforce as it is formated in the layout. The must important for me is to go on the next line like in the first screenshot. 
Here is my portion of code

<p style="border: 0.08px solid black;"> {!Container__c.General_Comments__c}</p>
User-added image
Please help me to display more than 1000 lines in a visualforce page.
public class InventoryCentralOficce {

      public List<AggregateResult> allproduct{get;set;}

     public InventoryCentralOficce() {

   allproduct = [
      
  SELECT Product_Hiden_Name__c, UM__c ,SUM(On_Hand__c)onHand,  SUM(Pending__c)pending,  SUM(Available__c)avail 
      FROM Articles_Containers__c 
      WHERE IsOpened__c = 1 AND FFP_Centers__c = 'Central Office'
GROUP BY Product_Hiden_Name__c , UM__c 
HAVING SUM(On_Hand__c) >0 
ORDER BY Product_Hiden_Name__c, UM__c limit 50000];
      
      

      }
}

 
Help me to use the User time instead of GMT Time
<div class="footer">
        <div>
                 Printed by :  {!$User.FirstName} {!$User.LastName} &nbsp; 
                   <apex:outputtext value=" {0, date, long} ">
                       <apex:param value=" {!NOW()} "></apex:param>
                  </apex:outputtext> &nbsp; at {!TIMENOW()}
                  <div>Page <span class="pagenumber"/> of <span class="pagecount"/></div>
       </div>
</div>
Hi all, 
Help me to increment a field by 1 based a picklist value of an other field. 
Like below. 
I mean, i have different Location, the auto number should be incremented by location. 

My sObject is: Delivery
Location Name: Location
field to incremented :Number__c
User-added image

 
I need to search data in a visualforce with criteria from multiple field.
The field which will be used as Critieria are:
Purpose__c  : Picklist
Condition__c : Picklist
Prod__c : Text
UM__c: Picklist
Container__c: Text

the code below allow me to set criteria for one field. Help me to improve it.
public with sharing class InventorySearchController { 
public list <Articles_Containers__c> inventoryItem {get;set;} 
public string searchstring {get;set;} 
public InventorySearchController( ) { 
} 
public void search(){ 
string searchquery= 'select Name , Prod__c, UM__c, Container__c, Number__c, On_Hand__c,  Pending__c,  Available__c, Purpose__c, Condition__c, Age__c, Comments__c FROM Articles_Containers__c  WHERE Prod__c like \'%'+searchstring+'%\'  AND On_Hand__c >0  AND IsOpened__c = 1  Limit 50000';
     
      inventoryItem= Database.query(searchquery); 

}
public void clear(){ 
inventoryItem.clear(); 
} 
}

// VF
<apex:page Controller="InventorySearchController"  Sidebar="False"> 
<apex:form > 
<apex:inputText value="{!searchstring}" label="Input"/> 
<apex:commandButton value="Search records" action="{!search}"/> 
<apex:commandButton value="Clear records" action="{!clear}"/> 
<apex:pageBlock title="Search Result"> 
<apex:pageblockTable value="{!inventoryItem}" var="a"> 

<apex:column value="{!a.Name}"/> 
<apex:column value="{!a.Prod__c}"/> 
<apex:column value="{!a.UM__c}"/> 
<apex:column value="{!a.Container__c}"/> 
<apex:column value="{!a.Number__c}"/> 
<apex:column value="{!a.On_Hand__c}"/> 
<apex:column value="{!a.Pending__c}"/> 
<apex:column value="{!a.Available__c}"/> 
<apex:column value="{!a.Purpose__c}"/> 
<apex:column value="{!a.Condition__c}"/> 
<apex:column value="{!a.Age__c}"/> 
<apex:column value="{!a.Comments__c}"/> 
</apex:pageBlockTable> 
</apex:pageBlock> 
</apex:form> 
</apex:page>


 
I need to create Multiple Child Records from Parent Related List but i get the Error: "URL No Longer Exists" but the data saved in the database. Also, it seem that the Parent Id does not populate autonmatically so, i have to add it manually. I want to notice that I add the child page as a related list of the parent. The Parent Obejct is Devery__c, the child is Item_Distributed__c Here is my code:
public class AddOrderItem {

    public String Delivery { get; set; }
Id DeliveryId;
public List<Item_Distributed__c> listOrderItem {get;set;}
public Integer rowNum{get;set;}

public AddOrderItem(ApexPages.StandardController controller){
   Id OrderItemId = ApexPages.currentPage().getParameters().get('OrderItemId');
    DeliveryId=ApexPages.currentPage().getParameters().get('DeliveryId');
    listOrderItem = new List<Item_Distributed__c>();
    listOrderItem.add(new Item_Distributed__c());

}

public pagereference insertOrderItem(){
    insert listOrderItem;
    Pagereference page=new pagereference('/'+DeliveryId);
    Return page;
}

public void insertRow(){
    listOrderItem.add(new Item_Distributed__c());
}

public void delRow(){
    rowNum = 
Integer.valueof(apexpages.currentpage().getparameters().get('index'));
    listOrderItem.remove(rowNum);
}
}

//VF Page

<apex:page StandardController="Delivery__c"  Extensions="AddOrderItem" showHeader="false" sidebar="false" >
<apex:form >
    <apex:variable var="rowNum" value="{!0}" />
    <apex:pageBlock >
        <apex:variable var="rowNum" value="{!0}" />
        <apex:PageBlockTable value="{!listOrderItem}" var="int">
        <apex:facet name="footer">
            <apex:commandLink value="Add" action="{!insertRow}"/>
            </apex:facet>
            <apex:column headerValue="Quantity">
                <apex:inputField value="{!int.Quantity__c}"/>                                      
            </apex:column>
            <apex:column headerValue="Product">
            <apex:inputField value="{!int.Product__c}"/> 
            </apex:column>
         <apex:column headerValue="Product">
            <apex:inputField value="{!int.Delivery__c}"/> 
            </apex:column>  
             <apex:column headerValue="Delete">
            <apex:commandLink style="font-size:15px; font-weight:bold; text-align:center;color:red;" value="X" action="{!delRow}">
                <apex:param value="{!rowNum}" name="index"/>
                </apex:commandLink>
                <apex:variable var="rowNum" value="{!rowNum+1}"/>
            </apex:column>
        </apex:PageBlockTable>
    <apex:pageBlockButtons >
        <apex:commandButton value="Save" action="{!insertOrderItem}"/>
        </apex:pageBlockButtons>
    </apex:pageBlock>

  </apex:form>
</apex:page>

User-added image
Hi All,
I have a class where the Coverage is 91% in  a sandbox. But, when  I am deploying it to the production, i received  code Coverage error  and it is 0%. Where do you think the problem is. 

Best, 
I want to test a class with an invocable method. Actually i get 51% Coverage and  at the line 73 in the Test class the error is:

"System.DmlException: Update failed. First exception on row 0 with id a03f0000006BbNwAAK; first error: CANNOT_EXECUTE_FLOW_TRIGGER, We can't save this record because the “Post Affiliate Inventory” process failed. Give your Salesforce admin these details. An Apex error occurred: System.DmlException: Insert failed. First exception on row 0; first error: INVALID_CROSS_REFERENCE_KEY, Record Type ID: this ID value isn't valid for the user: : [RecordTypeId]
: []


I want to remind that this class is to copy all child records from an object to an other object when a criteria is meet in the parent record. 

Apex Class: 
public class PostToAffiliateInventory {
    
    @InvocableMethod(label ='post to affiliate inventory')
    
    public static void PosttoInv(list<Id> deliveryId){
        
        list <Container__c> con = new List <Container__c>();
        list <Articles_Containers__c> contenairItems = new list <Articles_Containers__c>();
        list <Item_Distributed__c> itemList = new  list<Item_Distributed__c>();
        list <Delivery__c> delList = [SELECT Id, Is_Posted_To_Affiliate_Inventory__c, Affiliate_Center__c,AffiliateCenterId__c, Automatic_Code__c  FROM Delivery__c WHERE Id in :deliveryId];
        
        Id containerRecordTypeCaracole = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('FFP_Caracole').getRecordTypeId();
        Id containerRecordTypePAPCRN = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('CRN_PAP').getRecordTypeId();
        Id containerRecordTypeCanteenPAP = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('Canteen_PAP').getRecordTypeId();
        id crt; 
        
        Id ArticleContainerRecordTypeCaracole = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('FFP_Caracole').getRecordTypeId();
        Id ArticleContainerPAPCRN = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('CRN_PAP').getRecordTypeId();
        Id ArticleContainerCanteenPAP = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('PAP_Canteen').getRecordTypeId();
        id ArticleContainerAdmin = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('Admin').getRecordTypeId();
        id acrt;
        
        Container__c c;
        
        for (Delivery__c d : delList){
            if (d.Is_Posted_To_Affiliate_Inventory__c){
                if(d.Affiliate_Center__c =='FFP Caracole'){
                    crt = containerRecordTypeCaracole;
                }else if(d.Affiliate_Center__c =='CRN PAP'){
                    crt = containerRecordTypePAPCRN;
                }else if(d.Affiliate_Center__c =='PAP Canteen'){
                    crt = containerRecordTypeCanteenPAP;
                }
                c = new  Container__c();
                c.Name = d.Automatic_Code__c;
                c.FFP_Centers__c = d.Affiliate_Center__c ;
                c.RecordTypeId = crt;
                c.Distribution_Center__c = d.AffiliateCenterId__c;
                c.Is_Owner_Shipper__c = 'No';
                c.Provenance__c = 'FFP PAP';
                c.Type__c = 'Food';
                c.Shipment_Status__c = 'A - AWAITING ARRIVAL';
                c.Is_Automatic_Creation__c = TRUE;
                
                insert c;
                
                itemList = [SELECT id,Name, Product__r.Expiration_Date__c,Product__r.Unit_Cost__c,   
                            Product__r.Lot_Number__c,  Product__r.Unit_Weight__c ,
                            Product__r.UM__c, Product__r.Product__r.Id , Quantity__c 
                            FROM Item_Distributed__c  where Delivery__c  =: d.id ];             
                
                for (Item_Distributed__c OrderItems: itemList){
                    Articles_Containers__c ac = new Articles_Containers__c();
                    if(c.FFP_Centers__c == 'FFP Caracole'){
                        acrt = ArticleContainerRecordTypeCaracole;
                    }else if(c.FFP_Centers__c == 'CRN PAP'){
                        acrt = ArticleContainerPAPCRN;
                    }else if (c.FFP_Centers__c == 'PAP Canteen'){
                        acrt = ArticleContainerCanteenPAP;
                    }else acrt = ArticleContainerAdmin;
                    
                    ac.FFP_Centers__c = d.Affiliate_Center__c ;
                    ac.RecordTypeId = acrt; 
                    ac.Container__c =c.Id;
                    ac.Product__c = OrderItems.Product__r.Product__r.Id;
                    ac.Number__c= 0;
                    ac.Quantity__c = OrderItems.Quantity__c;
                    ac.Unit_Of_Measure_Paking__c= OrderItems.Product__r.UM__c;
                    ac.UM__c = OrderItems.Product__r.UM__c;
                    ac.Expiration_Date__c = OrderItems.Product__r.Expiration_Date__c;
                    ac.Lot_Number__c = OrderItems.Product__r.Lot_Number__c;
                    ac.Unit_Cost__c = OrderItems.Product__r.Unit_Cost__c;
                    ac.Unit_Weight__c =OrderItems.Product__r.Unit_Weight__c;
                    ac.DeliveryItemsReferences__c = OrderItems.id;
                    
                    contenairItems.add(ac);
                }      
                Insert contenairItems; 

            }
            
        } 
    }
}

Test Class: 
@IsTest
public class PostToAffiliateInventoryTest {
    
     @isTest static  void PostToAffiliateInv (){
        Account afc = new Account(Name ='test Account parent', Representant__c ='hkjlhjd', 
                                 Distribution_Center__c='FFP Caracole', Class__c = 'Clinic', Type = 'CLINICS', 
                                 Departement__c = 'NORD', Address__c ='Test Address');
        
        Account pa = new Account(Name ='Central Office', Representant__c ='hkjlhjd', 
                                 Distribution_Center__c='Central Office', Class__c = 'Clinic', Type = 'CLINICS', 
                                 Departement__c = 'OUEST', Address__c ='Test Address');
        
        insert pa;
   
        Product2 p = new Product2(Name ='TestProduct'); 
        insert p;
        Container_Shipper__c cs =new Container_Shipper__c(Name = 'Test Shipper');
        insert cs;
        
        //Id containerRecordTypeCaracole =      Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('FFP_Caracole').getRecordTypeId();
        //Id containerRecordTypeCentralOffice = Schema.SObjectType.Container__c.getRecordTypeInfosByDeveloperName().get('Central Office').getRecordTypeId();
        Container__c c = new Container__c( Name = 'CMLU', Provenance__c='FFP FLORIDA', Statut__c='Open', Distribution_Center__c= pa.id, FFP_Centers__c = 'Central Office',  RecordTypeId='0126A000000nMlj',  Shipper__c=cs.Id );
        insert c;
        
       // Id ArticleContainerRecordTypeCaracole = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('FFP_Caracole').getRecordTypeId();
       // Id ArticleContainerRecordTypeCentralOffice = Schema.SObjectType.Articles_Containers__c.getRecordTypeInfosByDeveloperName().get('HT Central Office').getRecordTypeId();
        Articles_Containers__c ac = new Articles_Containers__c();   
        
        ac.Product__c=p.ID;
        ac.Unit_Weight__c = 45; 
        ac.Unit_Cost__c = 87;
        ac.Container__c= c.ID;
        ac.Number__c = 55;
        ac.UM__c ='UNIT(S)';    
        ac.Local_ID__c = 7888;
        ac.Comments__c = 'UNIT(S)';
        ac.Purpose__c='Consignment';
        ac.Condition__c= 'New';
        ac.FFP_Centers__c = 'Central Office';
        ac.RecordTypeId = '0126A0000019jRK';
        insert ac;
        
        Account a = new Account();
        a.Name ='test Account'; 
        a.Representant__c ='Bijou';
        a.Distribution_Center__c='Central Office';
        a.Class__c = 'NGO'; 
        a.Type = 'CLINICS';
        a.Departement__c = 'NORD';
        a.Address__c ='Test Address';
        a.ParentId = pa.ID;
        a.Affiliate_Center__c = afc.Id;
        insert a ;
       
        
        Delivery__c del = new Delivery__c();
        del.Beneficiaire__c = a.Id;
        del.Ration__c =3;
        del.Delivery_status__c='Pending';
       
        del.Is_Posted_To_Affiliate_Inventory__c = false;
        
        insert del;
        
        Item_Distributed__c itemDis = new Item_Distributed__c();
        itemDis.Quantity__c = 10;
        itemDis.Product__c = ac.Id;
        itemDis.Delivery__c =del.Id;
     
        insert itemDis;
        
        del.Is_Posted_To_Affiliate_Inventory__c = true;
        update del;
        
        
        List<Delivery__c> delivery_Obj  =  [SELECT Beneficiaire__c from Delivery__c];
        System.assertEquals(1,delivery_Obj.size());
        List<Item_Distributed__c> item_distributed_Obj  =  [SELECT Product__c,Quantity__c,Delivery__c from Item_Distributed__c];
        System.assertEquals(1,item_distributed_Obj.size());

        PostToAffiliateInventory pav = new PostToAffiliateInventory();
      
    }
    
}


 
Considering the attached Picture, i want to copy the A Delivery with all its related list to Container and Related List.  I mean,  The Value of Delivey will be a new record in the object Container and the Item Distributed of the object Delivery will become Arcticle Container for the object Container. 
The Code below saved well but it fires with the following error :
caused by: System.ListException: Before Insert or Upsert list must not have two identically equal elements. Line 51
trigger PostToAfficliateInventory on Delivery__c (after update) {

list <Container__c> con = new List <Container__c>();
list <Articles_Containers__c> contenairItems = new list <Articles_Containers__c>();

    for (Delivery__c d : Trigger.New){
         if (d.Is_Posted_To_Affiliate_Inventory__c){
             Container__c c = new  Container__c();
             c.Name = d.Automatic_Code__c;
             c.FFP_Centers__c = d.Affiliate_Center__c ;
             c.RecordTypeId = '0126A000000nMlU';
             c.Distribution_Center__c = d.AffiliateCenterId__c;
             c.Is_Owner_Shipper__c = 'No';
             c.Provenance__c = 'FFP PAP';
             c.Type__c = 'Food';
             c.Shipment_Status__c = 'A - AWAITING ARRIVAL';
             c.Is_Automatic_Creation__c = TRUE;
             
             con.add(c);  
             insert con;
          
             Articles_Containers__c ac = new Articles_Containers__c();
             list<Item_Distributed__c> itemList = new  list<Item_Distributed__c>();
             
             
             itemList = [SELECT id,Name, Product__r.Expiration_Date__c,Product__r.Unit_Cost__c,   
                                 Product__r.Lot_Number__c,  Product__r.Unit_Weight__c ,
                                 Product__r.UM__c, Product__r.Product__r.Id , Quantity__c 
                         FROM Item_Distributed__c  
                         WHERE Delivery__c =: d.Id];
          
             for (Item_Distributed__c OrderItems: itemList){

                 for(Integer i = 0; i<itemList.Size(); i++){
                     ac.FFP_Centers__c = d.Affiliate_Center__c ;
                    ac.RecordTypeId = '0126A0000019jRJ'; 
                     ac.Container__c =c.Id;
                     ac.Product__c = OrderItems.Product__r.Product__r.Id;
                     ac.Number__c= 0;
                     ac.Quantity__c = OrderItems.Quantity__c;
                     ac.Unit_Of_Measure_Paking__c= OrderItems.Product__r.UM__c;
                     ac.UM__c = OrderItems.Product__r.UM__c;
                     ac.Expiration_Date__c = OrderItems.Product__r.Expiration_Date__c;
                     ac.Lot_Number__c = OrderItems.Product__r.Lot_Number__c;
                     ac.Unit_Cost__c = OrderItems.Product__r.Unit_Cost__c;
                     ac.Unit_Weight__c =OrderItems.Product__r.Unit_Weight__c;
                     
                     contenairItems.add(ac);
                     Insert contenairItems;
                }
             }          
         }
    } 
}

User-added image
Please help me to increase the code coverage of this class. actually is is only at 25%. the class is to increment in field each time a visualforce page called "DeliveryPage" is launched.  This field is on an object called Delivery__c which is a child of Account
public class DeliveryPageClass {
   // public Delivery__c delivery{get;set;}
public id deliveryId;
    public DeliveryPageClass(ApexPages.StandardController stdController)
    {
        deliveryId=stdController.getId();
     
    }
    public void updateDelivery()
    {
        Delivery__c delivery = [select id,Print_Counter__c from Delivery__c where id=:deliveryId];
        if(delivery.Print_Counter__c==null)
        {
            delivery.Print_Counter__c=1;
        }
        else
        {
            delivery.Print_Counter__c=delivery.Print_Counter__c+1;
        }
        system.debug(delivery);
        update delivery;
        system.debug(delivery);
        
    }

}

Test Class
@isTest
public class DeliveryPageClassTest {
    static testMethod void TestDeliveryPageClass(){
     Account pa = new Account(Name ='test Account parent', Representant__c ='hkjlhjd', 
     Distribution_Center__c='CRD Cayes', Class__c = 'Clinic', Type = 'CLINICS', 
     Departement__c = 'NORD', Address__c ='Test Address');
     insert pa;
         
 Account a = new Account();
 a.Name ='test Account'; 
 a.Representant__c ='Bijou';
 a.Distribution_Center__c='FFP Caracole';
 a.Class__c = 'NGO'; 
 a.Type = 'CLINICS';
 a.Departement__c = 'NORD';
 a.Address__c ='Test Address';
 a.ParentId = pa.ID;
 insert a ;
    
        Delivery__c del = new Delivery__c();
        del.Beneficiaire__c = a.Id;
        del.Ration__c =3;
        del.Delivery_status__c='Pending';
        
        insert del;
          
       
        ApexPages.StandardController sc = new ApexPages.standardController(new Delivery__c());
        DeliveryPageClass dpc = new DeliveryPageClass(sc);
    }
}
 
 
can someone give me a step by step guide to migrate an org to an other one? I need to migrate the metadata only. 
Thank you
I need to implement a validation rule which should take effect  for all new record created after a specific date. I have a field called  Unit_Cost__c , this field can not be blank for all records created after  July 25, 2019. Below is a draft of my work.  The error message is: Syntax error. Missing ')'

AND(DateValue(CreatedDate)=>Date(2019, 07,25 ), 
(ISBLANK(  Unit_Cost__c  )))
I need to search data in a visualforce with criteria from multiple field.
The field which will be used as Critieria are:
Purpose__c  : Picklist
Condition__c : Picklist
Prod__c : Text
UM__c: Picklist
Container__c: Text

the code below allow me to set criteria for one field. Help me to improve it.
public with sharing class InventorySearchController { 
public list <Articles_Containers__c> inventoryItem {get;set;} 
public string searchstring {get;set;} 
public InventorySearchController( ) { 
} 
public void search(){ 
string searchquery= 'select Name , Prod__c, UM__c, Container__c, Number__c, On_Hand__c,  Pending__c,  Available__c, Purpose__c, Condition__c, Age__c, Comments__c FROM Articles_Containers__c  WHERE Prod__c like \'%'+searchstring+'%\'  AND On_Hand__c >0  AND IsOpened__c = 1  Limit 50000';
     
      inventoryItem= Database.query(searchquery); 

}
public void clear(){ 
inventoryItem.clear(); 
} 
}

// VF
<apex:page Controller="InventorySearchController"  Sidebar="False"> 
<apex:form > 
<apex:inputText value="{!searchstring}" label="Input"/> 
<apex:commandButton value="Search records" action="{!search}"/> 
<apex:commandButton value="Clear records" action="{!clear}"/> 
<apex:pageBlock title="Search Result"> 
<apex:pageblockTable value="{!inventoryItem}" var="a"> 

<apex:column value="{!a.Name}"/> 
<apex:column value="{!a.Prod__c}"/> 
<apex:column value="{!a.UM__c}"/> 
<apex:column value="{!a.Container__c}"/> 
<apex:column value="{!a.Number__c}"/> 
<apex:column value="{!a.On_Hand__c}"/> 
<apex:column value="{!a.Pending__c}"/> 
<apex:column value="{!a.Available__c}"/> 
<apex:column value="{!a.Purpose__c}"/> 
<apex:column value="{!a.Condition__c}"/> 
<apex:column value="{!a.Age__c}"/> 
<apex:column value="{!a.Comments__c}"/> 
</apex:pageBlockTable> 
</apex:pageBlock> 
</apex:form> 
</apex:page>


 
Hi  All, I want group record by the  field named Shipment_Status__c  as attached.  I get the error "only aggregate expressions use field aliasing"
Here the controller
public class ContainerGlobalShipmentController{
public Map<String, List<Container__c>> Records { get; set; }
public ContainerGlobalShipmentController() {
 Records = new Map<String, List<Container__c>>();
 Container__c [] results =
[SELECT  Shipment_Status__c status, Pkl__c, PO__c, Invoice__c,Name, Size_in_feet__c, Description__c, 
Bill_of_Lading__c,On_Wharf_Date__c,Sailing__c,ETA__c,Demurrage_begins__c,
Brocker__c,Comments__c,     ID_Container__c,  Consignee__c, Provenance__c
 FROM Container__c WHERE (Departed_to_Wharf_Date__c = NULL OR 
 (Departed_to_Wharf_Date__c =LAST_N_DAYS:5))   
 AND Provenance__c ='FFP FLORIDA'];
 
  for(Container__c result: results) {
     status = (String)result.get('status');
    if(!Records.containsKey(status)) {
      Records.put(status, new Container__c[0]);
    }
    Records.get(status).add(result);
  }
}
}

User-added image
I want want to update child in a  self  lookup relationship with value of the parent. The idea is to create a child with projectType ='Sanitition' when a record is created with the type of House. And update the child anytime the parent is updated.  The error msg i get is: Illegal assignment from List<Output__c> to Map<Id,Output__c>  at the line 29
trigger AutoOutput on Output__c (after insert, after update) {
    
If(Trigger.isInsert){
List<Output__c> lstNewOutputs = new List<Output__c>();
for (Output__c NewOut : Trigger.New) {
if ( NewOut.Project_Type__c =='House') {
Output__c OutputChild = new Output__c();
OutputChild.Housing_If_Sanitation__c= NewOut.Id;
OutputChild.Project_Type__c = 'Sanitition';
OutputChild.RecordTypeId=NewOut.RecordTypeId;
OutputChild.Description__c=NewOut.Description__c;
OutputChild.Locality__c=NewOut.Locality__c;
OutputChild.Milestone__c= NewOut.Milestone__c;
OutputChild.Address__c = NewOut.Address__c;
OutputChild.claust__c=NewOut.claust__c;
OutputChild.A__c=NewOut.A__c;
OutputChild.Besem__c = NewOut.Besem__c;
lstNewOutputs.add(OutputChild);
}     
   
}
if(!lstNewOutputs.isEmpty())
INSERT lstNewOutputs;
}
If(Trigger.isUpdate){
    
Map<Id,Output__c> outputsWithChilds = new Map<Id,Output__c>();
List<Output__c> lstNewOutputs = new List<Output__c>();
outputsWithChilds = [SELECT Id,(SELECT Id FROM Housing_If_Sanitation__r WHERE Project_Type__c = 'Sanitition')FROM Output__c WHERE Id IN :Trigger.New];
for (Output__c NewOut : Trigger.New) {
if (NewOut.Project_Type__c =='House') {
Output__c OutputChild = new Output__c();
OutputChild.Housing_If_Sanitation__c= NewOut.Id;
OutputChild.Project_Type__c = 'Sanitition';
OutputChild.RecordTypeId=NewOut.RecordTypeId;
OutputChild.Description__c=NewOut.Description__c;
OutputChild.Locality__c=NewOut.Locality__c;
OutputChild.Milestone__c= NewOut.Milestone__c;
OutputChild.Address__c = NewOut.Address__c;
OutputChild.claust__c=NewOut.claust__c;
OutputChild.A__c=NewOut.A__c;
OutputChild.Besem__c = NewOut.Besem__c;
if(!outputsWithChilds.get(NewOut.Id).Housing_If_Sanitation__r.isEmpty()){
OutputChild.Id = outputsWithChilds.get(NewOut.Id).Housing_If_Sanitation__r[0].Id;
}
lstNewOutputs.add(OutputChild);
}
}
if(!lstNewOutputs.isEmpty())
UPSERT lstNewOutputs;
    }
}
Where do you thank the problem is. the trigger is save but does not fire.  The idee is to create a child record on a self relationship when outputType is House. Help me please
trigger AutoOutput on 	Output__c (after insert, after update) {
    List<Output__c> Output = new List<Output__c>();

     
    for (Output__c NewOut : Trigger.New) {
        if ( NewOut.OutputType__c =='House') {
            Output__c OutputChild = new Output__c();
            OutputChild.Housing_If_Sanitation__c= NewOut.Id;
            OutputChild.Project_Type__c = 'Sanitition';
            OutputChild.RecordTypeId='Infrastructure';
            OutputChild.Description__c='Discrption';
            OutputChild.Locality__c='ghjggh';
            Output.add(OutputChild);
        }
    }
    upsert Output;
}