function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
kuldeep paliwalkuldeep paliwal 

Can anyone help me to write a trigger...??

i have purchace order as master and purchase order line as child and for purchase order line is lookup to sales order line which is child of sales order i want a field value(Customer PO#) on purchase order to display on sales order..i want to write a trigger on purchase order (after update) and update the field of sales its done..can u help me..
Hi Kuldeep ,

I understood your ERD ,However your requirment is not clear .Better you can explain your requirment,based on that  we can decide which object we need to write trigger to solve your problem .Please elaborate your requirment clearly .

kuldeep paliwalkuldeep paliwal
i have phurchase order on that we have field Customer_PO, purchase order is related to purchase order line(Master detail relationship) where purchase order is parent and purchase order line is detail
now purchase order line is a lookup relationship to 'sales order line' which is child of 'sales order'
whenever user add  Customer_PO on purchase order it also add field of sales order.
purchase order line is list and sales order line is list we give the LIMIT of 1 to query 
HI Kuldeep,
What I understood is when you update customer PO in purchase order ,Customer Po value you want to update in  field of sales order .
In your system you have restricted to create only one purchase order line item per purchase order and only one salesorder line item per sales order .

Confirm me If I am right ?
kuldeep paliwalkuldeep paliwal
update means insert that customer po in sales order
no its a list or purchase order line with purchase order but have only one customer PO  field on purchase order  
and that purchase orer line are connected to list of sales order line in a same sales order thats we want to take the first element of purchase order line an sales order line and update to sales order
single purchase order have multiple purchase order line and they have connectede to mulitple sales order line in a single sales order..
means single purchase order is created for single sales it clear
kuldeep paliwalkuldeep paliwal
I write some code something like that..can u give 

trigger UpdateCustomerPOField on AcctSeedERP__Purchase_Order__c (after insert) {

    list<id> pOrderLineId = new list<id>();
    list<id> sOrderLineId = new list<id>();
    list<id> sOrderId = new list<id>();
    List<AcctSeedERP__Purchase_Order__c> purchase = [SELECT Id,Customer_PO__c,(SELECT Id,Name FROM AcctSeedERP__Purchase_Order_Lines__r ) FROM AcctSeedERP__Purchase_Order__c LIMIT 1];

    for(AcctSeedERP__Purchase_Order__c  purchaseOrder : purchase){
        for(AcctSeedERP__Purchase_Order_Line__c purchaseOrderLine : purchaseOrder.AcctSeedERP__Purchase_Order_Lines__r ) {

    List<AcctSeedERP__Purchase_Order_Line__c> pOrderLineList = [Select Id  FROM AcctSeedERP__Purchase_Order_Line__c Where Id IN: pOrderLineId LIMIT 1];
    map<id, AcctSeedERP__Purchase_Order_Line__c> purIdpurObjectMap = new map<id, AcctSeedERP__Purchase_Order_Line__c>();
    for(AcctSeedERP__Purchase_Order_Line__c purOrder : pOrderLineList){        
                purIdpurObjectMap.put(purOrder.Id, purOrder);
    list<AcctSeedERP__Sales_Order_Line__c> salesOrderLineList = [Select id, AcctSeedERP__Purchase_Order_Line__c From AcctSeedERP__Sales_Order_Line__c Where AcctSeedERP__Purchase_Order_Line__c In: pOrderLineId LIMIT 1];
    map<id, list<AcctSeedERP__Sales_Order_Line__c>> purOrderLineSalesOrderLineMap = new map<id, list<AcctSeedERP__Sales_Order_Line__c>>();

    for(AcctSeedERP__Sales_Order_Line__c salesOrderLine : salesOrderLineList){
    list<AcctSeedERP__Sales_Order_Line__c> tempList = purOrderLineSalesOrderLineMap.get(salesOrderLine.AcctSeedERP__Purchase_Order_Line__c);
        if(templist!= null && templist.Size()>0){
                    tempList = new list<AcctSeedERP__Sales_Order_Line__c>();
                    purOrderLineSalesOrderLineMap.put(salesOrderLine.AcctSeedERP__Purchase_Order_Line__c, tempList);
    list<AcctSeedERP__Sales_Order__c> salesOrderList = [Select id,Customer_PO__c,(SELECT Id,Name FROM AcctSeedERP__Sales_Order_Line__r)  From AcctSeedERP__Sales_Order__c Where Id In: sOrderLineId];
    map<id, AcctSeedERP__Sales_Order__c> salIdsalObjectMap = new map<id, AcctSeedERP__Sales_Order__c>();
    for(AcctSeedERP__Sales_Order__c salesOrder : salesOrderList){
                    salIdsalObjectMap.put(salesOrder.Id, salesOrder);
                    for(AcctSeedERP__Sales_Order_Line__c salesLine : salesOrder.AcctSeedERP__Sales_Order_Line__r) {

    for(AcctSeedERP__Purchase_Order__c pur :{
        for(AcctSeedERP__Sales_Order__c sales : listOfSalesOrder){            
                    AcctSeedERP__Sales_Order__c salesObject  = salIdsalObjectMap.get(;
                    salesObject.Customer_PO__c = pur.Customer_PO__c;