• nandana
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 8
    Replies
I rendered one pdf page. In that  pdf page attachment file is there. I have 4 or 5 attachments. First attachment will be display as an image( like thumb nail) and remaing attachments will be display as an links.
I have 3 incident types like A,B,C. Incident type A only having incident description field. And incident type B and incident type C having no incident description field. So if i choose incident type A then incident description div tag it should be display in pdf page. If i choose incident type B or incident type C then incident description div tag it shouldn't be display in pdf page(hide that div tag).
public class Testcontroller{
    public string getsname(){
        return 'raj';
    }
    public string Tname{get; set;}
    public Account acc{get; set;}
    public Testcontroller(){
        Tname = 'ram';
        acc = new Account();
        acc = [select id,name,phone from account where name='adf'];
        changeTname();
    }
    public void changeTname(){
        if(Tname=='hai'){
            Tname = label.namet;
        }
        else{
            Tname = label.label_val;
        }
     }
     public void accsave(){
         if(acc!=null){
             upsert acc;
         }
     }
     public pageReference googlepage(){
         //agereference p = new pagereference('/001/o');
         //pagereference p = new pagereference('/apex/Testpage1');
         pagereference p = page.Testpage1;
         p.getParameters().put('id', acc.id);
         p.getParameters().put('testb', 'fdsgs');
         p.setRedirect(true);
         
         return p;
     }
}
I have 3 incident types like A,B,C. Incident type A only having incident description field. And incident type B and incident type C having no incident description field. So if i choose incident type A then incident description div tag it should be display in pdf page. If i choose incident type B or incident type C then incident description div tag it shouldn't be display in pdf page(hide that div tag).
public class Testcontroller{
    public string getsname(){
        return 'raj';
    }
    public string Tname{get; set;}
    public Account acc{get; set;}
    public Testcontroller(){
        Tname = 'ram';
        acc = new Account();
        acc = [select id,name,phone from account where name='adf'];
        changeTname();
    }
    public void changeTname(){
        if(Tname=='hai'){
            Tname = label.namet;
        }
        else{
            Tname = label.label_val;
        }
     }
     public void accsave(){
         if(acc!=null){
             upsert acc;
         }
     }
     public pageReference googlepage(){
         //agereference p = new pagereference('/001/o');
         //pagereference p = new pagereference('/apex/Testpage1');
         pagereference p = page.Testpage1;
         p.getParameters().put('id', acc.id);
         p.getParameters().put('testb', 'fdsgs');
         p.setRedirect(true);
         
         return p;
     }
}
Hi everyone,

I have to test this class:

List<Account> oldAccounts   = Trigger.old;
        for(Account check : oldAccounts){
            if(check.Account_ID__c!=null){
                check.addError('Accounts that have SAP Account ID can not be deleted');
            }
        }

I know that in theese cases one has to use try/catch methods to solve the test.
But I've been trying for hours and I don't know how to solve it.

I post what I did so far, it covers everything except last line ('addError'):

@isTest
public class TriggerAccountDeleteTest {
      public class MyException extends Exception {}
       static testMethod void metodoDeletAccount(){
        
             //Create an Account with his required fields
             Account accountPrueba = new Account();
                accountPrueba.Name = 'Siemens2';
                accountPrueba.Account_Country__c = 'a014E000005XNKh';
                accountPrueba.Language__c = 'a064E0000060Wnr'; 
                accountPrueba.Department__c = 'Services';
            
            //Insert it
            insert accountPrueba ;
           
            //Test.startTest();  
                try{
                    delete accountPrueba;
                    Account deletedAccount = [SELECT Id, IsDeleted FROM Account WHERE Id = :accountPrueba.Id ALL ROWS];
                    System.assertEquals(deletedAccount.IsDeleted, true);
        
                    }
                 catch(Exception e){
                    Boolean b = null;
                    accountPrueba2.Account_ID__c = String.valueOf(b);
                    System.assert(e.getMessage().contains('Accounts that have SAP Account ID can not be deleted'));
                 }
               Test.stopTest();   
        
    }
}
Thank you for your time
Cheers,
Alberto