• krish123
  • NEWBIE
  • 20 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
Q.I am new to salesforce test class.Can you please write test class for the below trigger code.

Thanks in advance !

trigger UpdateItselfAccount on Account (After update)
{
    if(TriggerHelper.isAccountTriggersAreRunning == false){
    List<Account> parentAccounts = new List<Account>();
    
    for(Account currAcc : Trigger.New)
    {
        if(currAcc.parentId != null)
        {
            Account acc = new Account();
            acc.Id = currAcc.parentId;
            acc.Rating = currAcc.Rating;
            parentAccounts.add(acc);
        }
    }
    
    if(parentAccounts.size() > 0)
    update parentAccounts;
 }
}
Hello All,

1. I am trying to update parent account fields on account using trigger.
2. I did't get any error but it's not updated on parent account fields.
Can you please check the below Trigger/Code,..thanks for support..

trigger UpdateItselfAccount on Account (After update) {
    If(TriggerHelper.isAccountTriggersAreRunning == false){
 //   boolean isAccountTriggersAreRunningt = true;    
    List<Account> al=trigger.new;
    Set<ID> accPIDs =  new set<ID>();
    for(Account acclist:al){
        if(acclist.ParentId != Null)
          accPIDs.add(acclist.ParentId);
    }
    list<Account> Accchiledlist=[SELECT id,Name,Rating,ParentId FROM Account where ParentId= : accPIDs];
    system.debug('Account parent list@@@@@'+Accchiledlist);
    for(Account a:trigger.new){
      for(Account clist:Accchiledlist){
           clist.Rating =a.Rating;
         system.debug('Parent rating@@@@@'+clist.Rating);
      }
    }
    if(Accchiledlist.size()>0 ){
        If(TriggerHelper.isAccountTriggersAreRunning =! false){
        //system.debug('isAccountTriggersAreRunning@@@@@'+TriggerHelper.isAccountTriggersAreRunning);  
             update Accchiledlist;
                }
        }
  }
}



 

Hi ...

 

I am new to sfdc ....please help me this issus

 

 

trigger HelloWorld on Account (before insert , before update) {
List<Account> aaa=Trigger.new;
MyHelloWorld my=new MyHelloWorld();
my.addHelloWorld(aaa);
}
public class MyHelloWorld{  ------------------the error show msg like  Unexpected token : public
Public void addHelloWorld( List <Account> aaa){
for(Account acc:aaa){
if(acc.Hello__c!='World'){
acc.Hello__c='World';
}
}
}
}

Hello All,

1. I am trying to update parent account fields on account using trigger.
2. I did't get any error but it's not updated on parent account fields.
Can you please check the below Trigger/Code,..thanks for support..

trigger UpdateItselfAccount on Account (After update) {
    If(TriggerHelper.isAccountTriggersAreRunning == false){
 //   boolean isAccountTriggersAreRunningt = true;    
    List<Account> al=trigger.new;
    Set<ID> accPIDs =  new set<ID>();
    for(Account acclist:al){
        if(acclist.ParentId != Null)
          accPIDs.add(acclist.ParentId);
    }
    list<Account> Accchiledlist=[SELECT id,Name,Rating,ParentId FROM Account where ParentId= : accPIDs];
    system.debug('Account parent list@@@@@'+Accchiledlist);
    for(Account a:trigger.new){
      for(Account clist:Accchiledlist){
           clist.Rating =a.Rating;
         system.debug('Parent rating@@@@@'+clist.Rating);
      }
    }
    if(Accchiledlist.size()>0 ){
        If(TriggerHelper.isAccountTriggersAreRunning =! false){
        //system.debug('isAccountTriggersAreRunning@@@@@'+TriggerHelper.isAccountTriggersAreRunning);  
             update Accchiledlist;
                }
        }
  }
}



 

Hi ...

 

I am new to sfdc ....please help me this issus

 

 

trigger HelloWorld on Account (before insert , before update) {
List<Account> aaa=Trigger.new;
MyHelloWorld my=new MyHelloWorld();
my.addHelloWorld(aaa);
}
public class MyHelloWorld{  ------------------the error show msg like  Unexpected token : public
Public void addHelloWorld( List <Account> aaa){
for(Account acc:aaa){
if(acc.Hello__c!='World'){
acc.Hello__c='World';
}
}
}
}