+ Start a Discussion
Akash Garg 2Akash Garg 2 

Need to understand the trigger code

Need to understand what this lines of Trigger actually means as I'm new to Triggers.
if(salesAreaMatched)
							{
                                if(Trigger.isInsert)
								{ 
								opportunity.CurrencyISOCode = accountSalesArea.CurrencyISOCode; 
								}
                                opportunity.Account_Sales_Area_TI__c = accountSalesArea.Id;
                                opportunity.INCO_Term__c = accountSalesArea.Incoterms__c;
                                if(!String.isBlank(accountSalesArea.Price_List__c))
                                opportunity.Price_List__c = accountSalesArea.Price_List__c;
                                
                                if(Trigger.isInsert && Trigger.isBefore && opportunity.Payment_Term__c == null)
                                {
                                    opportunity.Payment_Term__c = accountSalesArea.Payment_Terms__c;
                                }
                                else if(Trigger.isUpdate && Trigger.isBefore)
                                {
                                    Opportunity tempOpty = (Opportunity)Trigger.oldMap.get(opportunity.Id);
                                    if(tempOpty.Sales_Area__c != null && tempOpty.Sales_Area__c != opportunity.Sales_Area__c && tempOpty.Payment_Term__c == opportunity.Payment_Term__c)
                                    {
                                        opportunity.Payment_Term__c = accountSalesArea.Payment_Terms__c;
                                    }
                                }
                                //opportunity.Payment_Term__c = accountSalesArea.Payment_Terms__c;
                                opportunity.INCO_Term_Location__c = accountSalesArea.Incoterms_2__c;
                                break;
                            }

 
Best Answer chosen by Akash Garg 2
Syed Insha Jawaid 2Syed Insha Jawaid 2
Hi Akash

The code snippet means : 
1. If sales Areas are matched then : 
2. New Opportunity is being created then the Currency ISO Code of oppty will be assigned to the matching account's currency Iso Code.
3. Opportunities Account_Sales_Area_TI__c , INCO_Term__c , INCO_Term_Location__c , Price_List__c(if not blank/null) will be assigned as the accounts corresponding fields
4. On New Opportunity creation if Payment_Terms__c is empty then account's Payment_Terms__c will be filled.
5. If old Opportunity is coming for update event then if Sales Area has been changed without changing the payment terms then again the Payment_Terms__c will be set using account's Payment_Terms__c

Hope It was clear.

Cheers!!!

All Answers

Syed Insha Jawaid 2Syed Insha Jawaid 2
Hi Akash

The code snippet means : 
1. If sales Areas are matched then : 
2. New Opportunity is being created then the Currency ISO Code of oppty will be assigned to the matching account's currency Iso Code.
3. Opportunities Account_Sales_Area_TI__c , INCO_Term__c , INCO_Term_Location__c , Price_List__c(if not blank/null) will be assigned as the accounts corresponding fields
4. On New Opportunity creation if Payment_Terms__c is empty then account's Payment_Terms__c will be filled.
5. If old Opportunity is coming for update event then if Sales Area has been changed without changing the payment terms then again the Payment_Terms__c will be set using account's Payment_Terms__c

Hope It was clear.

Cheers!!!
This was selected as the best answer
Akash Garg 2Akash Garg 2
Hi Syed,

Thanks a lot.