• Duke_Sfdc
  • NEWBIE
  • 65 Points
  • Member since 2017

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 7
    Replies
I have a list of territories names that are inserted into a custom field, Territories__c from an external system via dataloader. The names are split by a comma. eg: 1234,2345,9564 etc. Another custom field called RVP_Code__c stores the parent territory name. e.g. 1111

I'd like to go thru the list of these territories and add the territories names that don't have the same parent territory into a new field, Sales_Rep_Region__c, for review. I wrote a trigger below but it doesn't seem to be working. Would love to get some help regarding this. Thank you in advance!! 
trigger AccountTerritoryReview on Account (before insert) {
	
    List<Account> RepstoAdd = new List<Account>();
    
    if(TriggerHandler.run ){
        TriggerHandler.run = false;
        
        for (account acc : Trigger.new){
            if (acc.Territories__c != null) {
                for (string t : acc.Territories__c.split(',')) {
                    List<Territory2> tt = new List<Territory2>([SELECT Name,Territory2.ParentTerritory2.Name FROM Territory2 WHERE Territory2.Name = :t]);
                    for (Territory2 tx : tt){
                        if (tx.ParentTerritory2.Name != acc.RVP_Code__c){
                            acc.Sales_Rep_Region__c = tx.Name;
                            RepstoAdd.add(acc);
                        }
                    }
                    }                       
                }
            }
            
            
        }
    
    update RepstoAdd;
    
}


 

Using Trigger
in an account ,assume you are having 5 contacts connected and you have Account Annual revenue assume10,000 rs amount.
Scenario is
distribute the annual revenue to child records equally(10,000/5),
when a child record is added then then, modify all child record amount (10000/6) who are conected with assosiated account 
when a child record is deleted then also chages will happed to contact fields(10000/4)....
please help me ..........
thanks in advance

thanks in advance.......
I have a list of territories names that are inserted into a custom field, Territories__c from an external system via dataloader. The names are split by a comma. eg: 1234,2345,9564 etc. Another custom field called RVP_Code__c stores the parent territory name. e.g. 1111

I'd like to go thru the list of these territories and add the territories names that don't have the same parent territory into a new field, Sales_Rep_Region__c, for review. I wrote a trigger below but it doesn't seem to be working. Would love to get some help regarding this. Thank you in advance!! 
trigger AccountTerritoryReview on Account (before insert) {
	
    List<Account> RepstoAdd = new List<Account>();
    
    if(TriggerHandler.run ){
        TriggerHandler.run = false;
        
        for (account acc : Trigger.new){
            if (acc.Territories__c != null) {
                for (string t : acc.Territories__c.split(',')) {
                    List<Territory2> tt = new List<Territory2>([SELECT Name,Territory2.ParentTerritory2.Name FROM Territory2 WHERE Territory2.Name = :t]);
                    for (Territory2 tx : tt){
                        if (tx.ParentTerritory2.Name != acc.RVP_Code__c){
                            acc.Sales_Rep_Region__c = tx.Name;
                            RepstoAdd.add(acc);
                        }
                    }
                    }                       
                }
            }
            
            
        }
    
    update RepstoAdd;
    
}


 
Hi There,  Can anyone help me with rollup summary trigger on Accounts and Order. I want to populate the Count of Orders on Account and when Order is deleted Account Count should update. Thanks in advance.
  • April 20, 2018
  • Like
  • 0
Apex code ::
public class Trg11HelperClass {
    public static void addLineItem(List<Opportunity> opList){
        
            if(opList.Size()>0){
    List<OpportunityLineItem> Oli = [select Description,ListPrice,Name,OpportunityId from 
                                     OpportunityLineItem where  OpportunityId IN : opList];
                 
              for(Opportunity op:opList){
                  Integer count =0;
              for(OpportunityLineItem o:oli)  {
                 
                  count++;
                
                }  
                  if(count > 2){
                        op.addError('opportunity cannot be closed');
                           } 
                
            }
        }
    }
}

Trigger::

trigger Trg11 on Opportunity (after insert) {
    if(trigger.isUpdate)
Trg11HelperClass.addLineItem(Trigger.new);
}
Trigger Updatechildrec on Account (after update )

List <Account > lst = new list<account>()
If (trigger. Isafter&&trigger.Isupdate){

For(account a: trigger.new)
If(a.id!=null && a. Check box == false)
lst. Add(a)
}

For(contact c: [Select I'd, accountid,checkbox from contact where accountid =:lst]){

C. Checkbox = false
Update c // we can list also to update...



}

Hello All, 
 I have to update the contact records when the account checkbox is false...Above code will work for the same? 
Regards,
VSK98
  • April 18, 2018
  • Like
  • 0
public with sharing class AccountsController 
{
	@AuraEnabled
    public static List<Account> getAccounts()
    {
        return[SELECT Id, Name, Industry , Type, NumberofEmployees, TickerSymbol, Phone FROM Account];
    }
}

 

Using Trigger
in an account ,assume you are having 5 contacts connected and you have Account Annual revenue assume10,000 rs amount.
Scenario is
distribute the annual revenue to child records equally(10,000/5),
when a child record is added then then, modify all child record amount (10000/6) who are conected with assosiated account 
when a child record is deleted then also chages will happed to contact fields(10000/4)....
please help me ..........
thanks in advance

thanks in advance.......