• Viasur-
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 2
    Replies
Hello all,

I have been working on this code for a couple of weeks and now the time has come to build the test class for it :( . I don't have much experience on writing test class to be honest, but now I know how painful this can be. I have tried a few things but I just can get the full understanding on how to start coding my test class for this code. I have done some test codes for triggers, but much smaller than this. I will really appreciated if someone can give me some directions. I'm totally lost.  I look my code and can't start thinking on how to get this done.

I hope someone can help me, thanks.
public with sharing class PictureAttachmentController {
       
   public Visit_Report__c vr = new Visit_Report__c();
       
   String recId;
  
   public boolean renOne { get; set; }
   public boolean renTwo { get; set; }
   public boolean renOneIS { get; set; }
   public boolean renTwoIS { get; set; }
   public boolean displaySavedPopup {get; set;}
   public boolean refreshPage {get; set;}
   public String fileIdName {get; set;}
   public String fileIdName2 {get; set;}
   public String fileIdNameIS {get; set;}
   public String fileIdNameIS2 {get; set;}
   private ApexPages.StandardController stdController;
   private PageReference page; 
   
   public String errorMessage {get; set;} 
   public boolean hasErrors = false;
   public boolean getHasErrors(){
       return hasErrors;
    
  }
   
      
   public PictureAttachmentController(ApexPages.StandardController controller) {
   
   this.vr =(Visit_Report__c)controller.getRecord(); 
   this.stdController = controller;
   this.page = ApexPages.currentPage();
        
   recId = controller.getId(); 
   refreshPage= false;
   
     
  }
  
                  
   public void closePopup() {
       displaySavedPopup = false;
       
        
  }
  
 
   public void showPopup() {
       displaySavedPopUp = true; 
      
            
  }
  
          
   public Attachment pictureOne {
       get {
          if (pictureOne == null)
          pictureOne = new Attachment();
          return pictureOne;
           }
      set;
      
   }
 
    
   public PageReference savePictureOne() {
 
    pictureOne.OwnerId = UserInfo.getUserId();
    pictureOne.ParentId = ApexPages.currentPage().getParameters().get('id');
    pictureOne.Name = 'W1' + pictureOne.name; 
     
    
    try {
      
      insert pictureOne;
      renOne = true;
      
      
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading picture one'));
      return null;
    } finally {
      pictureOne = new Attachment(); 
            
            
    }
 
    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Picture one uploaded successfully - Please wait, refreshing page'));
    refreshPage =true;
    return null;
    
    }    
    
    public String getFileId() {
        String fileId = '';
        List<Attachment> attachedFiles = [SELECT Id, Name FROM Attachment WHERE Name LIKE 'W1%' AND parentId =:recId ORDER By LastModifiedDate DESC limit 1];
        if( attachedFiles != null && attachedFiles.size() > 0 ) {
            fileId = attachedFiles[0].Id;
            fileIdName = attachedFiles[0].Name; 
        }
        return fileId;    
    }
    
    public Attachment pictureTwo {
       get {
          if (pictureTwo == null)
          pictureTwo = new Attachment();
          return pictureTwo;
           }
       set;
    }
    
    public PageReference savePictureTwo() {
 
    pictureTwo.OwnerId = UserInfo.getUserId();
    pictureTwo.ParentId = ApexPages.currentPage().getParameters().get('id');
    pictureTwo.Name = 'W2' + pictureTwo.name;
    
    try {
      
      insert pictureTwo;
      renTwo = true;
      
      
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading picture two'));
      return null;
    } finally {
      pictureTwo = new Attachment(); 
       
       
    }
 
    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Picture two uploaded successfully - Please wait, refreshing page'));
    refreshPage =true;
    return null;
    
    }    
    
    public String getFileId2() {
        String fileId2 = '';
        List<Attachment> attachedFiles = [SELECT Id, Name FROM Attachment WHERE Name LIKE 'W2%' AND parentId =:recId ORDER By LastModifiedDate DESC limit 1];
        if( attachedFiles != null && attachedFiles.size() > 0 ) {
            fileId2 = attachedFiles[0].Id;
            fileIdName2 = attachedFiles[0].Name;
        }
        return fileId2;    
    }
    
// Identical process for In-Store pictures section


   public Attachment pictureOneInStore {
       get {
          if (pictureOneInStore == null)
          pictureOneInStore = new Attachment();
          return pictureOneInStore;
           }
      set;
      
   }
 
    
   public PageReference savePictureOneInStore() {
 
    pictureOneInStore.OwnerId = UserInfo.getUserId();
    pictureOneInStore.ParentId = ApexPages.currentPage().getParameters().get('id');
    pictureOneInStore.Name = 'IS1' + pictureOneInStore.name; 
    
    try {
      
      insert pictureOneInStore;
      renOneIS = true;
      
      
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading picture one'));
      return null;
    } finally {
      pictureOneInStore = new Attachment(); 
       
       
    }
 
    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Picture one uploaded successfully - Please wait, refreshing page'));
    refreshPage =true;
    return null;
    
    }    
    
    public String getFileIdIS() {
        String fileIdIS = '';
        List<Attachment> attachedFiles = [SELECT Id, Name FROM Attachment WHERE Name LIKE 'IS1%' AND parentId =:recId ORDER By LastModifiedDate DESC limit 1];
        if( attachedFiles != null && attachedFiles.size() > 0 ) {
            fileIdIS = attachedFiles[0].Id;
            fileIdNameIS = attachedFiles[0].Name;
        }
        return fileIdIS;    
    }
    
    public Attachment pictureTwoInStore {
       get {
          if (pictureTwoInStore == null)
          pictureTwoInStore = new Attachment();
          return pictureTwoInStore;
           }
       set;
    }
    
    public PageReference savePictureTwoInStore() {
 
    pictureTwoInStore.OwnerId = UserInfo.getUserId();
    pictureTwoInStore.ParentId = ApexPages.currentPage().getParameters().get('id');
    pictureTwoInStore.Name = 'IS2' + pictureTwoInStore.name;
    
    try {
      
      insert pictureTwoInStore;
      renTwoIS = true;
      
      
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading picture two'));
      return null;
    } finally {
      pictureTwoInStore = new Attachment(); 
       
       
    }
 
    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Picture two uploaded successfully - Please wait, refreshing page'));
    refreshPage =true;
    return null;
    
    }    
    
    public String getFileIdIS2() {
        String fileIdIS2 = '';
        List<Attachment> attachedFiles = [SELECT Id, Name FROM Attachment WHERE Name LIKE 'IS2%' AND parentId =:recId ORDER By LastModifiedDate DESC limit 1];
        if( attachedFiles != null && attachedFiles.size() > 0 ) {
            fileIdIS2 = attachedFiles[0].Id;
            fileIdNameIS2 = attachedFiles[0].Name;
        }
        return fileIdIS2;    
    }
    
    
    // Save methods
    
    
    public PageReference save(){
       hasErrors=false;
       
       Visit_Report__c compFields =[SELECT id, Description_Photo_One_Window__c, Description_Photo_Two_Window__c FROM Visit_Report__c WHERE Id =:recId];
 
    
       if(compFields.Description_Photo_One_Window__c == null && vr.Description_Photo_One_Window__c ==null && compFields.Description_Photo_Two_Window__c == null && vr.Description_Photo_Two_Window__c ==null){
          hasErrors=true;
                  
 }          
       if(hasErrors){
       errorMessage='No description have been inserted for Window/Facade section!';
       return null;        
       
 }else {              
       
       this.stdController.save(); 
       displaySavedPopUp =true;
       errorMessage='';
       refreshPage = true;
       return null;
       } 
             
  }
  
   public PageReference save2(){
       hasErrors=false;
       
       Visit_Report__c descFieldsInStore = [SELECT id, Description_Photo_One_In_Store__c, Description_Photo_Two_In_Store__c FROM Visit_Report__c WHERE Id =:recId];                           
  
       if(descFieldsInStore.Description_Photo_One_In_Store__c == null && vr.Description_Photo_One_In_Store__c ==null && descFieldsInStore.Description_Photo_Two_In_Store__c == null && vr.Description_Photo_Two_In_Store__c ==null){
          hasErrors=true;
                  
 }          
       if(hasErrors){
       errorMessage='No description have been inserted for In-Store section!';
       return null;        
       
 }else {              
       
       this.stdController.save(); 
       displaySavedPopUp =true;
       errorMessage='';
       refreshPage = true;
       return null;
       } 
             
   }

}


Hello all,

 

Can anyone let me know what is making this simple trigger not to firing?

 

trigger DeleteContact on Contact (before delete){
     for(Contact c : Trigger.old){ 
     
       String profileId = UserInfo.getProfileId();
      
       if(c.AccountId!=null && (profileId!='00e11000000Df7mAAC') && (profileId!='00e11000000Df8aAAC') && (profileId!='00eb0000000rNRWAA2')){
                c.addError('You don\'t have sufficient rights to delete this record!');
                
                }
        }
 }

 Thanks in advanced!!

Hello.

 

Does anyone knows if these features are working correctly on Outlook 2013?

I did some tests and I haven't been able to get them to work.

Any direction on this will be much appreciated.

 

Regards,

 

 

  • September 20, 2013
  • Like
  • 0

Hello all,

 

I was wondering if there are people out there with the same problem we are dealing at this moment.

We are using Outlook 2013 in synchronization with SFDC, only form SFDC to Outlook.

All the mapping is fine and all fields are available except one in Outlook, ManagerName.

After reading some documentation on the subject it looks like is totally normal to map the field on the Contact object, Reports To, with the Outlook field ManagerName.

The problem is that when I tried to map these to fields the problem raise.

When editing Outlook Configuration I can't find the Contact field "Reports To" under the fields available for mapping.

I do see the ManagerName on the Outlook column but if I select that option I still can't see the Reports To field, obviously.

So, does anyone know anything about this or can let me know why I can't see the "Reports To" field. I do have System Admin rights.

 

Any help will be great.

 

Regards. 

  • September 20, 2013
  • Like
  • 0

Hello all,

 

I was wondering if someone could tell me about the possibility of skipping the Zone selection page after clicking on 'new'  when creating an Idea. I have tried a number of things but can get it done. Any help would be much appreciated.

 

Thanks in advanced.

 

 

  • September 06, 2013
  • Like
  • 0
Hello all,

I have been working on this code for a couple of weeks and now the time has come to build the test class for it :( . I don't have much experience on writing test class to be honest, but now I know how painful this can be. I have tried a few things but I just can get the full understanding on how to start coding my test class for this code. I have done some test codes for triggers, but much smaller than this. I will really appreciated if someone can give me some directions. I'm totally lost.  I look my code and can't start thinking on how to get this done.

I hope someone can help me, thanks.
public with sharing class PictureAttachmentController {
       
   public Visit_Report__c vr = new Visit_Report__c();
       
   String recId;
  
   public boolean renOne { get; set; }
   public boolean renTwo { get; set; }
   public boolean renOneIS { get; set; }
   public boolean renTwoIS { get; set; }
   public boolean displaySavedPopup {get; set;}
   public boolean refreshPage {get; set;}
   public String fileIdName {get; set;}
   public String fileIdName2 {get; set;}
   public String fileIdNameIS {get; set;}
   public String fileIdNameIS2 {get; set;}
   private ApexPages.StandardController stdController;
   private PageReference page; 
   
   public String errorMessage {get; set;} 
   public boolean hasErrors = false;
   public boolean getHasErrors(){
       return hasErrors;
    
  }
   
      
   public PictureAttachmentController(ApexPages.StandardController controller) {
   
   this.vr =(Visit_Report__c)controller.getRecord(); 
   this.stdController = controller;
   this.page = ApexPages.currentPage();
        
   recId = controller.getId(); 
   refreshPage= false;
   
     
  }
  
                  
   public void closePopup() {
       displaySavedPopup = false;
       
        
  }
  
 
   public void showPopup() {
       displaySavedPopUp = true; 
      
            
  }
  
          
   public Attachment pictureOne {
       get {
          if (pictureOne == null)
          pictureOne = new Attachment();
          return pictureOne;
           }
      set;
      
   }
 
    
   public PageReference savePictureOne() {
 
    pictureOne.OwnerId = UserInfo.getUserId();
    pictureOne.ParentId = ApexPages.currentPage().getParameters().get('id');
    pictureOne.Name = 'W1' + pictureOne.name; 
     
    
    try {
      
      insert pictureOne;
      renOne = true;
      
      
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading picture one'));
      return null;
    } finally {
      pictureOne = new Attachment(); 
            
            
    }
 
    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Picture one uploaded successfully - Please wait, refreshing page'));
    refreshPage =true;
    return null;
    
    }    
    
    public String getFileId() {
        String fileId = '';
        List<Attachment> attachedFiles = [SELECT Id, Name FROM Attachment WHERE Name LIKE 'W1%' AND parentId =:recId ORDER By LastModifiedDate DESC limit 1];
        if( attachedFiles != null && attachedFiles.size() > 0 ) {
            fileId = attachedFiles[0].Id;
            fileIdName = attachedFiles[0].Name; 
        }
        return fileId;    
    }
    
    public Attachment pictureTwo {
       get {
          if (pictureTwo == null)
          pictureTwo = new Attachment();
          return pictureTwo;
           }
       set;
    }
    
    public PageReference savePictureTwo() {
 
    pictureTwo.OwnerId = UserInfo.getUserId();
    pictureTwo.ParentId = ApexPages.currentPage().getParameters().get('id');
    pictureTwo.Name = 'W2' + pictureTwo.name;
    
    try {
      
      insert pictureTwo;
      renTwo = true;
      
      
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading picture two'));
      return null;
    } finally {
      pictureTwo = new Attachment(); 
       
       
    }
 
    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Picture two uploaded successfully - Please wait, refreshing page'));
    refreshPage =true;
    return null;
    
    }    
    
    public String getFileId2() {
        String fileId2 = '';
        List<Attachment> attachedFiles = [SELECT Id, Name FROM Attachment WHERE Name LIKE 'W2%' AND parentId =:recId ORDER By LastModifiedDate DESC limit 1];
        if( attachedFiles != null && attachedFiles.size() > 0 ) {
            fileId2 = attachedFiles[0].Id;
            fileIdName2 = attachedFiles[0].Name;
        }
        return fileId2;    
    }
    
// Identical process for In-Store pictures section


   public Attachment pictureOneInStore {
       get {
          if (pictureOneInStore == null)
          pictureOneInStore = new Attachment();
          return pictureOneInStore;
           }
      set;
      
   }
 
    
   public PageReference savePictureOneInStore() {
 
    pictureOneInStore.OwnerId = UserInfo.getUserId();
    pictureOneInStore.ParentId = ApexPages.currentPage().getParameters().get('id');
    pictureOneInStore.Name = 'IS1' + pictureOneInStore.name; 
    
    try {
      
      insert pictureOneInStore;
      renOneIS = true;
      
      
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading picture one'));
      return null;
    } finally {
      pictureOneInStore = new Attachment(); 
       
       
    }
 
    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Picture one uploaded successfully - Please wait, refreshing page'));
    refreshPage =true;
    return null;
    
    }    
    
    public String getFileIdIS() {
        String fileIdIS = '';
        List<Attachment> attachedFiles = [SELECT Id, Name FROM Attachment WHERE Name LIKE 'IS1%' AND parentId =:recId ORDER By LastModifiedDate DESC limit 1];
        if( attachedFiles != null && attachedFiles.size() > 0 ) {
            fileIdIS = attachedFiles[0].Id;
            fileIdNameIS = attachedFiles[0].Name;
        }
        return fileIdIS;    
    }
    
    public Attachment pictureTwoInStore {
       get {
          if (pictureTwoInStore == null)
          pictureTwoInStore = new Attachment();
          return pictureTwoInStore;
           }
       set;
    }
    
    public PageReference savePictureTwoInStore() {
 
    pictureTwoInStore.OwnerId = UserInfo.getUserId();
    pictureTwoInStore.ParentId = ApexPages.currentPage().getParameters().get('id');
    pictureTwoInStore.Name = 'IS2' + pictureTwoInStore.name;
    
    try {
      
      insert pictureTwoInStore;
      renTwoIS = true;
      
      
    } catch (DMLException e) {
      ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading picture two'));
      return null;
    } finally {
      pictureTwoInStore = new Attachment(); 
       
       
    }
 
    ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Picture two uploaded successfully - Please wait, refreshing page'));
    refreshPage =true;
    return null;
    
    }    
    
    public String getFileIdIS2() {
        String fileIdIS2 = '';
        List<Attachment> attachedFiles = [SELECT Id, Name FROM Attachment WHERE Name LIKE 'IS2%' AND parentId =:recId ORDER By LastModifiedDate DESC limit 1];
        if( attachedFiles != null && attachedFiles.size() > 0 ) {
            fileIdIS2 = attachedFiles[0].Id;
            fileIdNameIS2 = attachedFiles[0].Name;
        }
        return fileIdIS2;    
    }
    
    
    // Save methods
    
    
    public PageReference save(){
       hasErrors=false;
       
       Visit_Report__c compFields =[SELECT id, Description_Photo_One_Window__c, Description_Photo_Two_Window__c FROM Visit_Report__c WHERE Id =:recId];
 
    
       if(compFields.Description_Photo_One_Window__c == null && vr.Description_Photo_One_Window__c ==null && compFields.Description_Photo_Two_Window__c == null && vr.Description_Photo_Two_Window__c ==null){
          hasErrors=true;
                  
 }          
       if(hasErrors){
       errorMessage='No description have been inserted for Window/Facade section!';
       return null;        
       
 }else {              
       
       this.stdController.save(); 
       displaySavedPopUp =true;
       errorMessage='';
       refreshPage = true;
       return null;
       } 
             
  }
  
   public PageReference save2(){
       hasErrors=false;
       
       Visit_Report__c descFieldsInStore = [SELECT id, Description_Photo_One_In_Store__c, Description_Photo_Two_In_Store__c FROM Visit_Report__c WHERE Id =:recId];                           
  
       if(descFieldsInStore.Description_Photo_One_In_Store__c == null && vr.Description_Photo_One_In_Store__c ==null && descFieldsInStore.Description_Photo_Two_In_Store__c == null && vr.Description_Photo_Two_In_Store__c ==null){
          hasErrors=true;
                  
 }          
       if(hasErrors){
       errorMessage='No description have been inserted for In-Store section!';
       return null;        
       
 }else {              
       
       this.stdController.save(); 
       displaySavedPopUp =true;
       errorMessage='';
       refreshPage = true;
       return null;
       } 
             
   }

}


Hello all,

 

Can anyone let me know what is making this simple trigger not to firing?

 

trigger DeleteContact on Contact (before delete){
     for(Contact c : Trigger.old){ 
     
       String profileId = UserInfo.getProfileId();
      
       if(c.AccountId!=null && (profileId!='00e11000000Df7mAAC') && (profileId!='00e11000000Df8aAAC') && (profileId!='00eb0000000rNRWAA2')){
                c.addError('You don\'t have sufficient rights to delete this record!');
                
                }
        }
 }

 Thanks in advanced!!