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

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 36
    Questions
  • 20
    Replies
I need help to increase the placeholder box of combobox and lightning-input in an lwc component, change the border color and also change the arrow selection button.
 
<lightning-combobox options={LightningComboboxOptions_1} class="c1" value={State} label="" onchange={unit}>
</lightning-combobox>
        
  
     <div class="slds-col slds-size_1-of-12  ">
        <lightning-input value={eff} onchange={calc} class="eff"></lightning-input>
    </div>

 
Hi All, Help me to complete the test class for the controller below
public class MaintenanceRequestController {

    public MaintenanceRequestController() {

    }


    public Map<Id,User> userMap { get; set; }
    public List<ProcessInstanceStep> processInstanceList { get; set; }

    public MaintenanceRequestController(ApexPages.StandardController controller) {
      userMap = new Map<Id, User>();
      processInstanceList = new List<ProcessInstanceStep>();
      Id recordId = ApexPages.CurrentPage().getparameters().get('id');
  
      processInstanceList = [Select id,ActorId, Actor.Name,CreatedDate, Actor.Title, Actor.FirstName , ProcessInstanceId, 
                              Actor.LastName, StepStatus, ProcessInstance.TargetObjectId
                              from ProcessInstanceStep
                              WHERE ProcessInstance.TargetObjectId = :recordId];
       for (ProcessInstanceStep step : processInstanceList){
            userMap.put(step.ActorId, new User(Signature__c=null));
       }
        userMap.putAll([SELECT Id,Name,Signature__c FROM User WHERE Id = :userMap.keySet()]);
    
        }

}
The main Object is Car_Maintenance__c(). My headache start at the line 53 in the code below
@IsTest
public class CarMaitenanceControllerTest{
static testMethod  void CarMaitenanceController(){
   
     Car__c veh = new Car__c (  Category__c='Pickup', Color__c='Red', Condition__c='Excellent', 
     Description__c='Test Vehicle',  Engine_Number__c='XXX',
     Matriculation__c = 'IT-00011', Make__c='Toyota', Year__c ='2017', Model__c='Colorado');
          insert veh;
    
    
    Part_Accessories_Reception__c par = new Part_Accessories_Reception__c();
    par.Date__c = System.today();
    par.Provider__c = 'Other';
    
     
    insert par;
    
    Part_Accessories__c pa = new Part_Accessories__c(Name = 'filter');
    insert pa;
    
    
    Part_Accessories_Inventory__c pai =  new Part_Accessories_Inventory__c();
    pai.Quantity_Received__c =7771;
   
    pai.Part_Accessories_Reception__c = par.ID;
    pai.Part_Accessories__c = pa.Id;
    
    insert pai; 
    
    
    
    
     Car_Maintenance__c carMain = new Car_Maintenance__c();
       
          carMain.Car__c = veh.ID;
          carMain.Cheque_Bank__c = '444-Cmmm'; 
          carMain.Company__c = 'FFP';
          carMain.Date__c = System.today();

         insert carMain;
     
        Maintenance_Details__c mdet = new Maintenance_Details__c();
        mdet.Description__c      = 'qiuyiuyi';
        mdet.Quantity__c         =555;
        
        mdet.Maintenance__c      = carMain.Id;
        mdet.Description__c      ='kjalhsdhfklasdf';
        mdet.Cost__c             = 999;
        mdet.Part_Accessories_Inventory__c = pai.Id;

        insert mdet;
        
        Approval.ProcessSubmitRequest app = new Approval.ProcessSubmitRequest();
        app.setObjectId(carMain.Id);
        Approval.ProcessResult result = Approval.process(app);
        
        
        ProcessInstance pi = new ProcessInstance ();
        pi.TargetObjectId = carMain.Id;
        pi.Status ='Approved';
        Insert pi;
        
        ProcessInstanceStep pis = new ProcessInstanceStep();
        pis.ProcessInstanceId = pi.Id;
        Insert pis;

    Test.setCurrentPageReference(new PageReference('CarMaintenanceView')); 
    System.currentPageReference().getParameters().put('id', veh.ID);
    CarMaintenanceController CRC = new CarMaintenanceController();
    MaintenanceRequestController mrc = new MaintenanceRequestController();
    
}

}


 
Hi All, 
I want to display a custom field (Rich Text Image) from User to approval History related list which will display the scanned signature of an Approver in aproval process. The Message i get when i add the Signature__c field is "Invalid field Signature__c for SObject Name"
<table border="0" >
               <tr>
                <th>Approver</th> 
                <th>Status</th> 
                 <th>Comments</th> 
                <th>Signature</th>
               
            </tr>
            <apex:repeat var="cx" value="{!Material_Request__c.ProcessSteps}">
                <tr>
                    
                <td>{!cx.Actor.Name}</td> 
                <td>{!cx.StepStatus}</td>
                <td>{!cx.Comments}</td>
                <td>{!cx.Actor.Signature__c}</td>
                
                </tr>
            </apex:repeat> 
            </table>

 
Please, help me to clearly understand the logic of Parent to Child Communication in LWC.

In all all articles i read it like they  say communication from parent to child is:  
- making a property of a child public to be accessed in the parent. 
- calling the method of Child Component from the Parent Component.

They finally say:  Parent to Child  is passing value from parent to child. 
which make me really confused. 

for me There is  a different between passing value from parent to Child and Access property of child in/from the parent. 

How can you help me to be cleared.

 
How can i display the result of the following method in a JavaFX TextArea Field instead of using print. when i use 
taf.appendText(printPreOrderRec(root));
Where taf is an instance of TextArea, i get an error saying that void type not allowed here.
below is the Method , i want to display the result in taf. I want to notice that BSTNode is a Comparable.
private static void printPreOrderRec(BSTNode currRoot) {
    if (currRoot == null) {
        return;
    }
    System.out.printf("%d ", currRoot.data);
    printPreOrderRec(currRoot.leftNode);
    printPreOrderRec(currRoot.rightNode);
}

 
I am about to diplay an image from the Fich Text Field in a Ligtning Web Component , i only see the form of the Image not the image(ScreenShot below. 

HTML
<template>
    <lightning-card title="My Contact Record" icon-name="standard:contact">
        <template if:true={contact.data}>
            <div class="slds-m-around_medium">
                <div style=" border-radius: 50%;"><img src={img__c} width="100" height="100"/></div>
                <p>{name}</p>
                <p>{title}</p>
                <p><lightning-formatted-phone value={phone}></lightning-formatted-phone></p>
                <p><lightning-formatted-email value={email}></lightning-formatted-email></p>
            </div>
        </template>
        
    </lightning-card>
</template>
JS
import { LightningElement, api, wire } from 'lwc';
import { getRecord } from 'lightning/uiRecordApi';

const FIELDS = [
    'Contact.Name',
    'Contact.Title',
    'Contact.Phone',
    'Contact.Email',
    'Contact.img__c'
];

export default class EmployeeCard extends LightningElement {
    @api recordId;

    @wire(getRecord, { recordId: '$recordId', fields: FIELDS })
    contact;

    get name() {
        return this.contact.data.fields.Name.value;
    }

    get title() {
        return this.contact.data.fields.Title.value;
    }

    get phone() {
        return this.contact.data.fields.Phone.value;
    }

    get email() {
        return this.contact.data.fields.Email.value;
    }
    get email() {
        return this.contact.data.fields.img__c.value;
    }
}

User-added image
 
Hi All, 
I am using the following Script inside  a VF Page to print the VF Page without preview it. 
The page is rendered in the printer format but it Is also previewed in the backgroud (Screenshot below). i mean when  i click  on the button , The VF Page and the Printer page , the both are open.  I do not want to preview the VF Page. If i could  automatically send it to the printer  when the button is clicked without any preview that would be awesome. 

Here th starting of my page
<apex:page readOnly="false"  action="{!updateDelivery}"  showHeader="false" sidebar="false"  applyHtmlTag="false"   standardStylesheets="false"  standardController="Delivery__c" extensions="DeliveryPageClass"  applyBodyTag="false" >    

    <head>
    <script type="test/javascript">
    function printFunc(){
        window.print();
    }
</script>

User-added image
Hi All, 
I need to use a button to print a VF Page directely to a printer without preview it. My requirement is to autorized a document to be printed only one time. As solution, i use a print counter (custom field) which is incremented each time the print button is clicked.  the problem i have with that solution is when the user click the button, the page is rendered as PDF and the use is able to print it the number of time he want. 

Let me know how i can print without preview.

Thank you,
Hi All, 
I have  an issue with using Controller Extension in code below. 

When i use the The custom Controller,  the data display well in the VF Page. But when i use the controller as extensions, the code savde but the data are not displayed in the VF Page. 

Make a look for me please. 

Controller
public class OrdercompilerController{
    
    public OrdercompilerController(ApexPages.StandardController controller) {
        
    }
    
   // public Order_Compiler__c oc { get; set; }
    public List <String> OrderNumberList { get; set; }
    
    //public List<Order_Compiler__c> compiler = New List<Order_Compiler__c>();
    public List<AggregateResult> allItems{get;set;}
    
    String compilerId;
    
    public  OrdercompilerController(){
        
        OrderNumberList= new List<String>();
        
        
        compilerId= ApexPages.currentPage().getParameters().get('id');
        
        
       // oc = new Order_Compiler__c();
       // try{ 
           // oc = [ SELECT Name,  Account__r.Parent.Distribution_Center__c, Account__r.Parent.Address__c,Account__r.Parent.Phone  FROM Order_Compiler__c Where Id =: compilerId LIMIT 1];
            
            List<Delivery__c> del = new  List<Delivery__c> ();
            
            del = [SELECT id , Name From Delivery__c WHERE   Compiler__c =: compilerId]; 
            
            //List<String> OrderNumberList = new List<String>() ;
            
            for( Delivery__c d : del){
                OrderNumberList.add(d.Name);
            }
            
            //compiler = [SELECT id FROM Order_Compiler__c WHERE id =:compilerId  LIMIT 1];
            
            allItems= [SELECT Pro__c, UOM__c,SUM(Quantity__c)Qty
                       FROM Item_Distributed__c 
                       WHERE compilerId__c =: compilerId
                       GROUP BY Pro__c, UOM__c  
                       HAVING SUM(Quantity__c) >0 
                       ORDER BY Pro__c,  UOM__c  limit 100000];
       // }
        //catch(Exception e)
        //{
           // System.debug(e.getMessage());
       // }
    } 
}

VF Page
 
public class OrdercompilerController{
    
    public OrdercompilerController(ApexPages.StandardController controller) {
        
    }
    
   // public Order_Compiler__c oc { get; set; }
    public List <String> OrderNumberList { get; set; }
    
    //public List<Order_Compiler__c> compiler = New List<Order_Compiler__c>();
    public List<AggregateResult> allItems{get;set;}
    
    String compilerId;
    
    public  OrdercompilerController(){
        
        OrderNumberList= new List<String>();
        
        
        compilerId= ApexPages.currentPage().getParameters().get('id');
        
        
       // oc = new Order_Compiler__c();
       // try{ 
           // oc = [ SELECT Name,  Account__r.Parent.Distribution_Center__c, Account__r.Parent.Address__c,Account__r.Parent.Phone  FROM Order_Compiler__c Where Id =: compilerId LIMIT 1];
            
            List<Delivery__c> del = new  List<Delivery__c> ();
            
            del = [SELECT id , Name From Delivery__c WHERE   Compiler__c =: compilerId]; 
            
            //List<String> OrderNumberList = new List<String>() ;
            
            for( Delivery__c d : del){
                OrderNumberList.add(d.Name);
            }
            
            //compiler = [SELECT id FROM Order_Compiler__c WHERE id =:compilerId  LIMIT 1];
            
            allItems= [SELECT Pro__c, UOM__c,SUM(Quantity__c)Qty
                       FROM Item_Distributed__c 
                       WHERE compilerId__c =: compilerId
                       GROUP BY Pro__c, UOM__c  
                       HAVING SUM(Quantity__c) >0 
                       ORDER BY Pro__c,  UOM__c  limit 100000];
       // }
        //catch(Exception e)
        //{
           // System.debug(e.getMessage());
       // }
    } 
}





// VF Page
<apex:page renderAs="pdf" readOnly="true" showHeader="false" sidebar="false"  standardStylesheets="false"  Standardcontroller="Order_Compiler__c" extensions="OrdercompilerController"  applyBodyTag="false" >
    
   
    <div class="head">        
        <div class="col logo">
            <apex:image url="{!$Resource.LogoFFP}" width="140" height="60"/>
        </div>
        <div class ="col name"> 
            <h2>
                FOOD FOR THE POOR
            </h2>               
            <h6>
                      <!-- {!oc.Account__r.Parent.Distribution_Center__c}   
                      {!oc.Account__r.Parent.Address__c }-->
                <!-- Tels: {!oc.Account__r.Parent.Phone}-->
            </h6>
            
        </div>        
    </div>
    
    <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()} &nbsp; GMT <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>
    </div>        
 <h3> TRANSPORT FOR:  {!Order_Compiler__c.Account__r.Name }  </h3>
    
    <h6>List of Order Number: </h6>    {!OrderNumberList }    
    
    <table style="width:100%;border-collapse: collapse; border: 0px solid black; line-height:1.1em; "> 
 
        <th>Product</th> 
        <th>Unit Of Measure </th> 
        <th>Quantity </th> 
        
        <apex:repeat value="{!allItems}" var="a"> 
            <!--  <div class="tablebody"> -->
            
            <tr>     
                <td>{!a['Pro__c']}</td>
                <td>{!a['UOM__c']}</td>
                <td>{!TEXT(a['Qty'])}</td>
            </tr> 
            
        </apex:repeat>
 
    </table>
    
</apex:page>

 
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 am using the following Script inside  a VF Page to print the VF Page without preview it. 
The page is rendered in the printer format but it Is also previewed in the backgroud (Screenshot below). i mean when  i click  on the button , The VF Page and the Printer page , the both are open.  I do not want to preview the VF Page. If i could  automatically send it to the printer  when the button is clicked without any preview that would be awesome. 

Here th starting of my page
<apex:page readOnly="false"  action="{!updateDelivery}"  showHeader="false" sidebar="false"  applyHtmlTag="false"   standardStylesheets="false"  standardController="Delivery__c" extensions="DeliveryPageClass"  applyBodyTag="false" >    

    <head>
    <script type="test/javascript">
    function printFunc(){
        window.print();
    }
</script>

User-added image
Hi All, 
I am using the following Script inside  a VF Page to print the VF Page without preview it. 
The page is rendered in the printer format but it Is also previewed in the backgroud (Screenshot below). i mean when  i click  on the button , The VF Page and the Printer page , the both are open.  I do not want to preview the VF Page. If i could  automatically send it to the printer  when the button is clicked without any preview that would be awesome. 

Here th starting of my page
<apex:page readOnly="false"  action="{!updateDelivery}"  showHeader="false" sidebar="false"  applyHtmlTag="false"   standardStylesheets="false"  standardController="Delivery__c" extensions="DeliveryPageClass"  applyBodyTag="false" >    

    <head>
    <script type="test/javascript">
    function printFunc(){
        window.print();
    }
</script>

User-added image
Hi All, 
I need to use a button to print a VF Page directely to a printer without preview it. My requirement is to autorized a document to be printed only one time. As solution, i use a print counter (custom field) which is incremented each time the print button is clicked.  the problem i have with that solution is when the user click the button, the page is rendered as PDF and the use is able to print it the number of time he want. 

Let me know how i can print without preview.

Thank you,
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;
}