• Yogesh Kumar 35
  • NEWBIE
  • 10 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
Hi All,

I am new to Salesforce and trying to write a trigger and test class so that I can create a trigger that fires when the Active__c field on the Account object is updated to ‘No’. This trigger should find all related Case records and update their Status fields to ‘Closed’. 

This trigger should create at least 150 Accounts and at least 10 Cases for each Account. ​I need  to use assert statements to validate that my trigger is working. 

I have written the below code and getting 3 errors:

Trigger:

trigger  AccountTrigger  on  Account   ( after update )   { 
Account.CaseUpdate(Trigger.new);
}


or 


trigger  AccountTrigger  on  Account   ( after update )   { 
CaseUpdate update = new CaseUpdate();
   if (Trigger.isAfter && Trigger.isUpdate){
        update.CaseUpdate(Trigger.new);
   }   
}

=========================================================================
Class:

public class CaseUpdate {
       set <Account> accId = new Set <Id>();
       set <Cases> caseId = new Set <Id>();

  for (Case c : Trigger.new); {
  List<Case> opencase = [SELECT Id, Status, Account Id from Case where Id = :accId.Id];
 if (a.Active__c = 'No')
 {
  c.Status = 'Closed';
update opencase;
 } 
}
   }

======================================================================

Testclass:

@isTest
public   class   AccountTriggerTest  {
public   static  testMethod  void  doTest ()  {

    Account acc = new Account(
          Name = 'Test Account',

          Active__c = 'None'
       );
    insert acc;
       Case c = new Case(
           Account = acc.Id,
           Status = 'None';
       );
    insert c;
       Account accTest = [SELECT Id, Active__c FROM Account WHERE Id = :acc.id];
       System.assertEquals(accTest.Active__c, 'Yes');
       c.Status = 'Closed';
       update c;
       accTest = [SELECT Id, Active__C FROM Account WHERE Id = :acc.id];
       System.assertEquals(accTest.Status, 'Closed');
   }
}
}

Any suggestions and guidance would really help me. Thanks in advance. 
Hi All,  How can i use the assert statement in a test class to create the accounts and cases related to each account? And to validate if trigger is working .

 
When i am using the reRender="pgBlckId" to grey the vf page once we click on save button, than i am not able to get the error message that i want.

But once i remove  the "reRender" the save grey out functionalilty stopped working.

Any suggestion????
Hi All,

I have to create a report with one 'field' that chaged to 'one text value'  in the past 7 days and same 'field' with different " text value" no specific time.
Report need to be generated on weekly basis.
Hi All,

I am new to Salesforce and trying to write a trigger and test class so that I can create a trigger that fires when the Active__c field on the Account object is updated to ‘No’. This trigger should find all related Case records and update their Status fields to ‘Closed’. 

This trigger should create at least 150 Accounts and at least 10 Cases for each Account. ​I need  to use assert statements to validate that my trigger is working. 

I have written the below code and getting 3 errors:

Trigger:

trigger  AccountTrigger  on  Account   ( after update )   { 
Account.CaseUpdate(Trigger.new);
}


or 


trigger  AccountTrigger  on  Account   ( after update )   { 
CaseUpdate update = new CaseUpdate();
   if (Trigger.isAfter && Trigger.isUpdate){
        update.CaseUpdate(Trigger.new);
   }   
}

=========================================================================
Class:

public class CaseUpdate {
       set <Account> accId = new Set <Id>();
       set <Cases> caseId = new Set <Id>();

  for (Case c : Trigger.new); {
  List<Case> opencase = [SELECT Id, Status, Account Id from Case where Id = :accId.Id];
 if (a.Active__c = 'No')
 {
  c.Status = 'Closed';
update opencase;
 } 
}
   }

======================================================================

Testclass:

@isTest
public   class   AccountTriggerTest  {
public   static  testMethod  void  doTest ()  {

    Account acc = new Account(
          Name = 'Test Account',

          Active__c = 'None'
       );
    insert acc;
       Case c = new Case(
           Account = acc.Id,
           Status = 'None';
       );
    insert c;
       Account accTest = [SELECT Id, Active__c FROM Account WHERE Id = :acc.id];
       System.assertEquals(accTest.Active__c, 'Yes');
       c.Status = 'Closed';
       update c;
       accTest = [SELECT Id, Active__C FROM Account WHERE Id = :acc.id];
       System.assertEquals(accTest.Status, 'Closed');
   }
}
}

Any suggestions and guidance would really help me. Thanks in advance. 
Hi All,

I have to create a report with one 'field' that chaged to 'one text value'  in the past 7 days and same 'field' with different " text value" no specific time.
Report need to be generated on weekly basis.