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
nksfnksf 

Trigger to Update Field

Hi Guys,
Can you please help me out with this Trigger?
Whenever any record is created or edited on kugo2p__SalesOrder__c then it should copy kugo2p__BillingFrequency__c field value to other Custom Object I have kugo2p__SalesOrderServiceLine__c and the field name is Billing_Frequency__c. kugo2p__SalesOrderServiceLine__c is the Child of kugo2p__SalesOrder__c. 
Also this Trigger should only update field when on kugo2p__SalesOrder__c we have Order_Form_Type__c = New Order OR Upsell – Independent OR Upsell – Coterminous OR Organic Growth OR Credit OR Renewal OR Renewal – Entitlement Reconciliation OR New – Entitlement Reconciliation OR Upsell – Entitlement Reconciliation
CyberJusCyberJus
Can you post the code you have so far and where exactly you need help?
nksfnksf
I am sorry. I am not a developer. I have not written any code yet. If you can please help me out with the code. I just need to populate parent account field value to child account.
CyberJusCyberJus
You do not need a trigger for this, you can do it with the process builder if you are not a developer. 

Otherwise with a trigger you would need to:
1. loop through your trigger items
2. check conditions as stated for if you want to copy
3. create a map of salesorder id to the billing frequency
4. query the salesorderservicelines
5. loop those lines
6. get the value from the map based on salesorderid and enter the billingfrequency field
7. update your salesorderservicelines
 
Ricky ThedaRicky Theda
I don't know if this work or no, but at least you can give it a try:
trigger Trigger_kugo2p__SalesOrder__c on kugo2p__SalesOrder__c (after insert, after update) {
    for(kugo2p__SalesOrder__c kugoSO:Trigger.new){
        Set<String> OrderType = new Set<String>();
        List<String> AllowedOrderType = new List<String> {'New Order','Upsell – Independent','Upsell – Coterminous','Organic Growth','Credit','Renewal','Renewal – Entitlement Reconciliation',' New – Entitlement Reconciliation','Upsell – Entitlement Reconciliation'};      
        OrderType.addAll(AllowedOrderType);
        boolean checker = OrderType.contains(kugoSO.Order_Form_Type__c);
        if(checker)
        {
            kugo2p__SalesOrderServiceLine__c kugo2pSL = [SELECT id from kugo2p__SalesOrderServiceLine__c where kugo2p__SalesOrder__c =: kugoSO.id];        
            kugo2pSL.Billing_Frequency__c = kugoSO.BillingFrequency__c;
            update kugo2pSL;
        }        
    }
}


 
nksfnksf
Thanks Ricky!
I have written this code below but I need to modify this code. I actually created couple of workflow rules and 1 Trigger to achieve my requirement but I need to get rid of workflow rules and have everything done in 1 Trigger. All the WF Rules and Trigger I created on kugo2p__SalesOrder__c Object. 
Can you guys please help me to update my Trigger?

Trigger:
trigger ServiceLineBillingFrequency on kugo2p__SalesOrder__c (after update) {

Set<Id> OrderID = new Set<Id>();

 for(kugo2p__SalesOrder__c so : Trigger.new){
 OrderID.add(so.id);
}

List<kugo2p__SalesOrderServiceLine__c> SLUpdate = [select id, kugo2p__SalesOrder__c from kugo2p__SalesOrderServiceLine__c where kugo2p__SalesOrder__c in :OrderID];
 for(kugo2p__SalesOrder__c so : trigger.new){
 for (kugo2p__SalesOrderServiceLine__c osl : SLUpdate) {
 If(so.Order_Billing_Frequency__c != Null){

        osl.Billing_Frequency__c = so.Order_Billing_Frequency__c;
 }
}
}
update SLUpdate;
  }

Workflow Rule 1:
Evaluation Criteria: Evaluate the rule when a record is created, and every time it’s edited
Rule Criteria: OR(ISCHANGED( kugo2p__RecordStatus__c) && kugo2p__RecordStatus__c = "Approved", kugo2p__RecordStatus__c = "Released")
Field Update: Order_Billing_Frequency__c    and Order_Billing_Frequency__c should be equals to Billing_Frequency__c

Workflow Rule 2:
Evaluation Criteria: Evaluate the rule when a record is created, and every time it’s edited
Rule Criteria: AND(ISCHANGED( kugo2p__RecordStatus__c ), OR(PRIORVALUE(kugo2p__RecordStatus__c) = "Approved", PRIORVALUE(kugo2p__RecordStatus__c) = "Released"))
Field Update: Order_Billing_Frequency__c    and Order_Billing_Frequency__c should be equals to Billing_Frequency__c