• Anoop Patel 11
  • NEWBIE
  • 30 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 9
    Replies
This is the first time I'm using visual flows and trying to combine it with login flows. The requirement is to have a service agreement accepted every quarter by users once they login. This only needs to be completed once a quarter so a record lookup is required to check if this has happened. I have started to create the flow using a screen where a user enters their username (again but only for testing the rest of the flow), I want to avoid this and perhaps see if it is possible to pull direct from the standard login page? This then checks the existing records (at the moment just on username) but here I want it to also check the date to make sure that there is a record within the quarter using the standard created date. If there is a record then no further action is required but if there isn’t, then a screen where the agreement is displayed appears and a user must agree to progress. Once they have the finish button should take them to the standard home.

My issue areas are:
  • Pulling the username from the standard login page if possible or another way without the user having to enter the information again. (in the background hopefully).
  • Checking criteria to see if a record exists for the current QTR.
  • If a record does exists then DO NOT enter the follow. (where my current screen just says no action required, it should bypass this and re-direct to home page with the user having to see this screen then click finish).

User-added image
My test class returns 'System.NullPointerException: Attempt to de-reference a null object' when I uncomment the highlights reference to my method? If I comment then it runs but only covers 60%.

Controller
public List<EventRelation> getParticipants(){
        
        List<EventRelation> inviteeRelations = new List<EventRelation>();
    
        if(mt.Id!=null){
            inviteeRelations = new List<EventRelation>([SELECT Id, Relation.Name FROM EventRelation 
                                WHERE EventId =:mt.Id 
                                AND IsWhat = false]); 
        }
        return inviteeRelations ;

Test Class

 Test.startTest();  
      
           System.runAs(u) {  
               ApexPages.StandardController controller = new APexPages.StandardController(event);
               CORE_viewEventWordController extension = new CORE_viewEventWordController(controller);
               String url=extension.getmyimageurl();             
               //List<EventRelation> listPart=extension.getParticipants();
               us=extension.eventOwner;
           }
       Test.stopTest();    }
 
I'm trying to set a value on the parent record if a child record is live. However the field on the Account is pick list and there are 4 different record types which means there needs to be criteria before updating the parent. I.e. if child record is record type a, status is live and part of a certain department then update account to A.

Essentially, I just need to find at least one child record that matches the specified criteria even if there are multiple child records that match the criteria and update the pick list to a value. If there is a live child record with record type A and B that are both live and match the other criteria then A takes priority and the field on Account should update to A. If A is inactive then it should show B, and if B is inactive it should show A.

My trigger for one business line is below;

trigger UpdateBusinessHighlights on Activity__c (after delete, after insert, after update){

Map<ID, Account> parentAccs = new Map<ID, Account>();
Map<ID, Account> parentAccsClients = new Map<ID, Account>();
List<Id> MAIds = new List<Id>();
List<Id> MAClientIds = new List<Id>();
Boolean isExists = false;

if(trigger.isInsert || trigger.isUpdate){
for (Activity__c MA: Trigger.new) {
MAIds.add(MA.CMember_ID__c);
MAClientIds.add(MA.Participant__c);
}
}

if(trigger.isDelete){
for(Activity__c MA: trigger.old){
MAIds.add(MA.CMember_ID__c);
MAClientIds.add(MA.Participant__c);
}
}

parentAccs = new Map<Id, Account>([SELECT id, CEStatus__c,CDSCStatus__c,DStatus__c,FCStatus__c,FIStatus__c,SCStatus__c FROM Account WHERE Id IN :MAIds]);


parentAccsClients = new Map<Id, Account>([SELECT id, CEStatus__c,CDSCStatus__c,DStatus__c,FCStatus__c,FIStatus__c,SCStatus__c FROM Account WHERE Id IN :MAClientIds]);

for (Activity__c MA: Trigger.new){
isExists = False;
if(MA.Status__c == 'Live' && MA.Business_Line__c == 'CE' && (MA.RecordTypeid == '01220000000JTeP' || MA.RecordTypeid == '01220000000Q6r5')){
Account myParentAcc = parentAccs.get(MA.CMember_ID__c);
myParentAcc.CEStatus__c = 'Live A';
isExists = True;
}
else if(MA.Status__c == 'Live' && MA.Business_Line__c == 'CE' && (MA.RecordTypeid == '01220000000JTZA' || MA.RecordTypeid == '01220000000JTZB')){
Account myParentAccClients = parentAccsClients.get(MA.Participant__c);
myParentAccClients.CEStatus__c = 'Live B';
isExists = True;
}
else if(isExists == false && MA.Business_Line__c == 'CE' && (MA.RecordTypeid == '01220000000JTeP' || MA.RecordTypeid == '01220000000Q6r5')){
Account myParentAcc = parentAccs.get(MA.CMember_ID__c);
myParentAcc.CEStatus__c = 'Prospect - A;
}
else if(isExists == false && MA.Business_Line__c == 'CE' && (MA.RecordTypeid == '01220000000JTZA' || MA.RecordTypeid == '01220000000JTZB')){
Account myParentAccClients = parentAccsClients.get(MA.Participant__c);
myParentAccClients.CEStatus__c = 'Prospect – B’;
}
}
if(!parentAccs.isEmpty())
{
update parentAccs.values();
}
if(!parentAccsClients.isEmpty())
{
update parentAccsClients.values();
}
}

 
I have the test class below that only has 72% code coverage and I can't seem to increase it anymore. My trigger fires to make all Contacts related to an Account inactive, when a Account has been made inactive using a checkbox (this part seems to be covered). When the checkbox is unchecked then it reserves and makes all Contacts active (this part is not covered in bold below). I have tried various ways i.e. updating the Account, inserting a Contact with the inactive flag equals true with the latest version below. but still doesn't get past 72%.

Test Class

@isTest
private class TestUpdateContactToActiveOrInactive {

static testMethod void UpdateContactToActiveOrInactive() {
         
          Account acc = new Account();
          list<RecordType> rt = [SELECT Id FROM RecordType WHERE Name = 'Customer' and SobjectType='Account'];
          acc.RecordTypeId=rt[0].id;
          acc.Name = 'test acct';
          acc.Industry = 'Retail';
          try {
              insert acc;
          } catch (DmlException e) {}
   
          Contact c = new Contact();
          c.AccountId = acc.id;
          c.LastName='test cont';
          c.MobilePhone= '(0)00 0000 0000';
           try {
              insert c;
          } catch (DmlException e) {}
                   
          acc.Inactive__c = True;
          try {
          Update acc;         
          } catch (DmlException e) {}    
         
          Account acc1 = new Account();
          list<RecordType> rt1 = [SELECT Id FROM RecordType WHERE Name = 'Customer' and SobjectType='Account'];
          acc1.RecordTypeId=rt1[0].id;
          acc1.Name = 'test acct1';
          acc1.Industry = 'Retail';
          acc1.Inactive__c = True;
          try {
              insert acc1;
          } catch (DmlException e) {}    
         
          Contact c1 = new Contact();
          c1.AccountId = acc1.id;
          c1.LastName='test cont1';
          c1.MobilePhone= '(0)00 0000 0000';
          c1.Inactive_Contact__c = True;
           try {
              insert c1;
          } catch (DmlException e) {}         
         
          acc.Inactive__c = False;
          try {
          Update acc1;         
          } catch (DmlException e) {}           

}
}
This is the first time I'm using visual flows and trying to combine it with login flows. The requirement is to have a service agreement accepted every quarter by users once they login. This only needs to be completed once a quarter so a record lookup is required to check if this has happened. I have started to create the flow using a screen where a user enters their username (again but only for testing the rest of the flow), I want to avoid this and perhaps see if it is possible to pull direct from the standard login page? This then checks the existing records (at the moment just on username) but here I want it to also check the date to make sure that there is a record within the quarter using the standard created date. If there is a record then no further action is required but if there isn’t, then a screen where the agreement is displayed appears and a user must agree to progress. Once they have the finish button should take them to the standard home.

My issue areas are:
  • Pulling the username from the standard login page if possible or another way without the user having to enter the information again. (in the background hopefully).
  • Checking criteria to see if a record exists for the current QTR.
  • If a record does exists then DO NOT enter the follow. (where my current screen just says no action required, it should bypass this and re-direct to home page with the user having to see this screen then click finish).

User-added image
My test class returns 'System.NullPointerException: Attempt to de-reference a null object' when I uncomment the highlights reference to my method? If I comment then it runs but only covers 60%.

Controller
public List<EventRelation> getParticipants(){
        
        List<EventRelation> inviteeRelations = new List<EventRelation>();
    
        if(mt.Id!=null){
            inviteeRelations = new List<EventRelation>([SELECT Id, Relation.Name FROM EventRelation 
                                WHERE EventId =:mt.Id 
                                AND IsWhat = false]); 
        }
        return inviteeRelations ;

Test Class

 Test.startTest();  
      
           System.runAs(u) {  
               ApexPages.StandardController controller = new APexPages.StandardController(event);
               CORE_viewEventWordController extension = new CORE_viewEventWordController(controller);
               String url=extension.getmyimageurl();             
               //List<EventRelation> listPart=extension.getParticipants();
               us=extension.eventOwner;
           }
       Test.stopTest();    }
 
I have the test class below that only has 72% code coverage and I can't seem to increase it anymore. My trigger fires to make all Contacts related to an Account inactive, when a Account has been made inactive using a checkbox (this part seems to be covered). When the checkbox is unchecked then it reserves and makes all Contacts active (this part is not covered in bold below). I have tried various ways i.e. updating the Account, inserting a Contact with the inactive flag equals true with the latest version below. but still doesn't get past 72%.

Test Class

@isTest
private class TestUpdateContactToActiveOrInactive {

static testMethod void UpdateContactToActiveOrInactive() {
         
          Account acc = new Account();
          list<RecordType> rt = [SELECT Id FROM RecordType WHERE Name = 'Customer' and SobjectType='Account'];
          acc.RecordTypeId=rt[0].id;
          acc.Name = 'test acct';
          acc.Industry = 'Retail';
          try {
              insert acc;
          } catch (DmlException e) {}
   
          Contact c = new Contact();
          c.AccountId = acc.id;
          c.LastName='test cont';
          c.MobilePhone= '(0)00 0000 0000';
           try {
              insert c;
          } catch (DmlException e) {}
                   
          acc.Inactive__c = True;
          try {
          Update acc;         
          } catch (DmlException e) {}    
         
          Account acc1 = new Account();
          list<RecordType> rt1 = [SELECT Id FROM RecordType WHERE Name = 'Customer' and SobjectType='Account'];
          acc1.RecordTypeId=rt1[0].id;
          acc1.Name = 'test acct1';
          acc1.Industry = 'Retail';
          acc1.Inactive__c = True;
          try {
              insert acc1;
          } catch (DmlException e) {}    
         
          Contact c1 = new Contact();
          c1.AccountId = acc1.id;
          c1.LastName='test cont1';
          c1.MobilePhone= '(0)00 0000 0000';
          c1.Inactive_Contact__c = True;
           try {
              insert c1;
          } catch (DmlException e) {}         
         
          acc.Inactive__c = False;
          try {
          Update acc1;         
          } catch (DmlException e) {}           

}
}