• Azrel Rahiman 11
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies

Hi All,

I have created a trigger in my Sandbox to play around with Apex Trigger. 

My purpose of this code is to check few field in Account from Task, whether they met a certain requirement. The trigger works but I'm stuck with my test class with 71%.
 

New to apex coding, need help to make it at least 80% above.

APEX TRIGGER

trigger checkAccountAge on Task (before insert) {

    Set<Id> accountIds = new Set<Id>();
    Set<Id> invalidacc = new Set<Id>();  
    
    for (Task t : trigger.new)
    {
        accountIds.add(t.WhatId);
    }
    
    List<Account> accounts = [SELECT Id,Name,Market_Share_Count__c,Owner_Profile_Name__c,No_of_Operating_Rooms__c FROM Account WHERE Id IN :accountIds];

    //validation
    if(accounts.size() > 0)
    {
        for(Account acc : accounts){
            if(acc.Market_Share_Count__c == 0 &&  acc.Owner_Profile_Name__c == 'System Admin'){
                invalidacc.add(acc.Id);
            }
        }
    }
    
    System.debug('invalidacc A '+invalidacc);

    if(invalidacc.size() > 0)
    {
        for (Task t : trigger.new){
            if(invalidacc.contains(t.WhatId)){
                t.addError('Please create Market Share information and fill in No. Operating Room in Account before create a task/log a call.');
            }
        }
    }
}
TEST CLASS
@istest
public class checkAccountAge_test{
    static testMethod void testmethod1() 
    {   
        Account acc = new Account(name='test');
        acc.RecordTypeId = '01290000001M1v3';
        acc.OwnerId = '005900000013z6x';
        acc.No_of_Operating_Rooms__c = 50;
        insert acc;
        
        Share_of_Space__c sos = new Share_of_Space__c();
        sos.Account__c = acc.id;
        sos.Record_Date__c = system.Today();
        sos.Share__c = 1;
        sos.Type__c = 'EXAM';
        insert sos;
        
        Task tk = new Task();
        tk.OwnerId = '005O0000003gIAz';
        tk.Subject = 'Call:';
        tk.ActivityDate = system.Today();
        tk.Activity_Bucket__c = 'FTF End User';
        tk.Activity_Type__c = 'Inservice';
        tk.whatId = acc.id;
        tk.Priority = 'Normal';
        tk.Status = 'Not Started';
        tk.RecordTypeId = '01290000001BRWo';
        tk.Time_Spent_Minutes__c = 120;
        insert tk;
        
        tk.Status ='Completed';
        update tk;
    }
}

 
Hi all,

I'm trying to learn and understand the development of visualforce page. New to development anyway.

So I'm trying to include a help text to an outputtext, do you think this is possible? Or is there any other workaround on this?
 
<apex:page standardController="Opportunity">

        <font color="red">
            <apex:outputText style="font-weight: bold;" 
            value="IMPORTANT: My reminder message here"/><br/>
        </font>

</apex:page>

// trying to add a help text to this outputText

 

Hi All,

I have created a trigger in my Sandbox to play around with Apex Trigger. 

My purpose of this code is to check few field in Account from Task, whether they met a certain requirement. The trigger works but I'm stuck with my test class with 71%.
 

New to apex coding, need help to make it at least 80% above.

APEX TRIGGER

trigger checkAccountAge on Task (before insert) {

    Set<Id> accountIds = new Set<Id>();
    Set<Id> invalidacc = new Set<Id>();  
    
    for (Task t : trigger.new)
    {
        accountIds.add(t.WhatId);
    }
    
    List<Account> accounts = [SELECT Id,Name,Market_Share_Count__c,Owner_Profile_Name__c,No_of_Operating_Rooms__c FROM Account WHERE Id IN :accountIds];

    //validation
    if(accounts.size() > 0)
    {
        for(Account acc : accounts){
            if(acc.Market_Share_Count__c == 0 &&  acc.Owner_Profile_Name__c == 'System Admin'){
                invalidacc.add(acc.Id);
            }
        }
    }
    
    System.debug('invalidacc A '+invalidacc);

    if(invalidacc.size() > 0)
    {
        for (Task t : trigger.new){
            if(invalidacc.contains(t.WhatId)){
                t.addError('Please create Market Share information and fill in No. Operating Room in Account before create a task/log a call.');
            }
        }
    }
}
TEST CLASS
@istest
public class checkAccountAge_test{
    static testMethod void testmethod1() 
    {   
        Account acc = new Account(name='test');
        acc.RecordTypeId = '01290000001M1v3';
        acc.OwnerId = '005900000013z6x';
        acc.No_of_Operating_Rooms__c = 50;
        insert acc;
        
        Share_of_Space__c sos = new Share_of_Space__c();
        sos.Account__c = acc.id;
        sos.Record_Date__c = system.Today();
        sos.Share__c = 1;
        sos.Type__c = 'EXAM';
        insert sos;
        
        Task tk = new Task();
        tk.OwnerId = '005O0000003gIAz';
        tk.Subject = 'Call:';
        tk.ActivityDate = system.Today();
        tk.Activity_Bucket__c = 'FTF End User';
        tk.Activity_Type__c = 'Inservice';
        tk.whatId = acc.id;
        tk.Priority = 'Normal';
        tk.Status = 'Not Started';
        tk.RecordTypeId = '01290000001BRWo';
        tk.Time_Spent_Minutes__c = 120;
        insert tk;
        
        tk.Status ='Completed';
        update tk;
    }
}

 
Hi all,

I'm trying to learn and understand the development of visualforce page. New to development anyway.

So I'm trying to include a help text to an outputtext, do you think this is possible? Or is there any other workaround on this?
 
<apex:page standardController="Opportunity">

        <font color="red">
            <apex:outputText style="font-weight: bold;" 
            value="IMPORTANT: My reminder message here"/><br/>
        </font>

</apex:page>

// trying to add a help text to this outputText