• Bryan Jimenez 5
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 4
    Replies
Hi Everyone,

I am currently trying to get a test to work for a simple dynamic apex query.

However, I am getting nothing back when running the test.

Could someone please offer some assistance?

Below is my controller
 
public class UserInfo { 
    Public List<User> getUserInfo() {
       List<User> UserInfo=[Select Name,Kolbe_Score__c,Verb__c,Question_1__c,Question_1_Answer__c,Question_2__c,Question_2_Answer__c,Question_3__c,Question_3_Answer__c,Question_4__c,Question_4_Answer__c,Question_5__c,Question_5_Answer__c,Question_6__c,Question_6_Answer__c,User_Bio_Image_ID__c
                                                      From User                                                     
                                                      Where id = :ApexPages.currentPage().getParameters().get('sfdc.userId') ];
                                                    
                                                                                          
        return UserInfo;
  }
}

My Test
@isTest
public class UserInfoTest 
{ 
    public static testMethod void TestMethod1() 
    {
        User U = new User();
        U.Kolbe_Score__c= 'Test';
        insert U;
        
        
        Test.StartTest(); 

        PageReference pageRef = Page.UserInfoVF; 
        pageRef.getParameters().put('id', String.valueOf(U.Id));
        Test.setCurrentPage(pageRef);

        UserInfo testAccPlan = new UserInfo();
  
        //testAccPlan.save(); call all your function here
        Test.StopTest();
        
    }
   
}


My Visualforce Page is called UserInfoVF

Thank you in advance for your help!
Hi Everyone,

I am having trouble adding a standardcontroller "Mclabs2__Sale" to my Custom controller below.

Can someone guide me in the right direction?
 
global with sharing class ModalFlowAttachment{

    global Flow.Interview.attachmentFlow2 myflow { get; set; }
    global string varAttachmentParentId = 'init';

    global ModalFlowAttachment(){
        myflow  = new Flow.Interview.attachmentFlow2(new map<string, object>{'varAttachmentParentId'=> ''});
    }
    global string getVarAttachmentParentId() {
        if(varAttachmentParentId == 'init'){
            varAttachmentParentId = '';
            return '';
        }
        return myflow.varAttachmentParentId;
    }
    global Attachment attachment {
        get {
            if (attachment == null)
                attachment = new Attachment();
            return attachment;
        }
        set;
    }
    global PageReference upload() {

        attachment.OwnerId = UserInfo.getUserId();
        attachment.IsPrivate = true;
        attachment.parentId = getVarAttachmentParentId();

        try {
            insert attachment;
        } 
        catch (DMLException e) {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
            return null;
        } 
        finally {
            attachment = new Attachment();
        }

        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
        varAttachmentParentId = null;
        return null;
    }

 
Hi Everyone,

I am having trouble getting coverage for my dml exception.
 
global with sharing class ModalFlowAttachment{

    global Flow.Interview.attachmentFlow2 myflow { get; set; }
    global string varAttachmentParentId = 'init';

    global ModalFlowAttachment(){
        myflow  = new Flow.Interview.attachmentFlow2(new map<string, object>{'varAttachmentParentId'=> ''});
    }
    global string getVarAttachmentParentId() {
        if(varAttachmentParentId == 'init'){
            varAttachmentParentId = '';
            return '';
        }
        return myflow.varAttachmentParentId;
    }
    global Attachment attachment {
        get {
            if (attachment == null)
                attachment = new Attachment();
            return attachment;
        }
        set;
    }
    global PageReference upload() {

        attachment.OwnerId = UserInfo.getUserId();
        attachment.IsPrivate = True;
        attachment.parentId = getVarAttachmentParentId();
        
        
        try {
            insert attachment;
        } 
        catch (DMLException e) {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
            return null;
        } 
        finally {
            attachment = new Attachment();
        }

        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
        varAttachmentParentId = null;
        return null;
    }
}

can anyone help me with this?

 
Hi Guys,

Attached is the controller and below that is the test class.
 
global with sharing class ModalFlowAttachment{

    global Flow.Interview.attachmentFlow2 myflow { get; set; }
    global string varAttachmentParentId = 'init';

    global ModalFlowAttachment(){
        myflow  = new Flow.Interview.attachmentFlow2(new map<string, object>{'varAttachmentParentId'=> ''});
    }
    global string getVarAttachmentParentId() {
        if(varAttachmentParentId == 'init'){
            varAttachmentParentId = '';
            return '';
        }
        return myflow.varAttachmentParentId;
    }
    global Attachment attachment {
        get {
            if (attachment == null)
                attachment = new Attachment();
            return attachment;
        }
        set;
    }
    global PageReference upload() {

        attachment.OwnerId = UserInfo.getUserId();
        attachment.IsPrivate = true;
        attachment.parentId = getVarAttachmentParentId();

        try {
            insert attachment;
        } 
        catch (DMLException e) {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
            return null;
        } 
        finally {
            attachment = new Attachment();
        }

        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
        varAttachmentParentId = null;
        return null;
    }
}

Test  Class
 
@isTest
Private class ModalFlowAttachmentTest {
    
    @isTest static void CreateProperty() {
        McLabs2__Property__c Property = New McLabs2__Property__c();
        Property.Name                         = 'Fakename';
        Property.McLabs2__Property_Address__c = 'FakeAddress';
        Property.McLabs2__City__c             = 'FakeCity';
        Property.Block__c                     = '328';
        Property.Lot__c                       = '23';
        Insert Property;
    }
    
    static testMethod void ModalFlowAttachment_1() {

    system.Test.setCurrentPage(Page.ModalFlowAttachmentVF);
    ModalFlowAttachment controller = new ModalFlowAttachment();

    controller.getVarAttachmentParentId();
    
    Attachment tmpAttach = controller.attachment;
    Attachment attachment = new Attachment();
    attachment.Body = Blob.valueOf('Dreamforce15');
    attachment.Name = String.valueOf('Coastal Cloud.txt');
    attachment.ParentId = [select id from McLabs2__Property__c limit 1].id;
    
    controller.attachment = attachment;
    controller.upload();
  }
}

Any help is greatly appreciated
 

Hi all,

I am currently trying to create a test for my controller. The test I have currently gives me 100% in salesforce but it fails on validation to production.

What am i doing wrong?

public class ContactExtension {
  public ContactExtension(ApexPages.StandardController controller) {
    Contact C = (Contact)controller.getRecord();
    C.Recordtypeid = '012d0000001cltE';
  }
}




@istest(seeAllData='true')
public class ContactExtensionTest 
{
  public static testMethod  void ContactExtensionTest() {
    Contact Con = new Contact();
    ApexPages.StandardController controller = new ApexPages.StandardController(Con);
    ContactExtension extension = new ContactExtension(controller);
    System.assert(Con.Firstname !=Null);
  }
}

I keep getting this error when validating in production.



System.AssertException: Assertion Failed 
Stack Trace: Class.ContactExtensionTest.ContactExtensionTest: line 8, column 1
Hi Everyone,

I am currently trying to get a test to work for a simple dynamic apex query.

However, I am getting nothing back when running the test.

Could someone please offer some assistance?

Below is my controller
 
public class UserInfo { 
    Public List<User> getUserInfo() {
       List<User> UserInfo=[Select Name,Kolbe_Score__c,Verb__c,Question_1__c,Question_1_Answer__c,Question_2__c,Question_2_Answer__c,Question_3__c,Question_3_Answer__c,Question_4__c,Question_4_Answer__c,Question_5__c,Question_5_Answer__c,Question_6__c,Question_6_Answer__c,User_Bio_Image_ID__c
                                                      From User                                                     
                                                      Where id = :ApexPages.currentPage().getParameters().get('sfdc.userId') ];
                                                    
                                                                                          
        return UserInfo;
  }
}

My Test
@isTest
public class UserInfoTest 
{ 
    public static testMethod void TestMethod1() 
    {
        User U = new User();
        U.Kolbe_Score__c= 'Test';
        insert U;
        
        
        Test.StartTest(); 

        PageReference pageRef = Page.UserInfoVF; 
        pageRef.getParameters().put('id', String.valueOf(U.Id));
        Test.setCurrentPage(pageRef);

        UserInfo testAccPlan = new UserInfo();
  
        //testAccPlan.save(); call all your function here
        Test.StopTest();
        
    }
   
}


My Visualforce Page is called UserInfoVF

Thank you in advance for your help!
Hi Everyone,

I am having trouble getting coverage for my dml exception.
 
global with sharing class ModalFlowAttachment{

    global Flow.Interview.attachmentFlow2 myflow { get; set; }
    global string varAttachmentParentId = 'init';

    global ModalFlowAttachment(){
        myflow  = new Flow.Interview.attachmentFlow2(new map<string, object>{'varAttachmentParentId'=> ''});
    }
    global string getVarAttachmentParentId() {
        if(varAttachmentParentId == 'init'){
            varAttachmentParentId = '';
            return '';
        }
        return myflow.varAttachmentParentId;
    }
    global Attachment attachment {
        get {
            if (attachment == null)
                attachment = new Attachment();
            return attachment;
        }
        set;
    }
    global PageReference upload() {

        attachment.OwnerId = UserInfo.getUserId();
        attachment.IsPrivate = True;
        attachment.parentId = getVarAttachmentParentId();
        
        
        try {
            insert attachment;
        } 
        catch (DMLException e) {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
            return null;
        } 
        finally {
            attachment = new Attachment();
        }

        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
        varAttachmentParentId = null;
        return null;
    }
}

can anyone help me with this?

 
Hi Guys,

Attached is the controller and below that is the test class.
 
global with sharing class ModalFlowAttachment{

    global Flow.Interview.attachmentFlow2 myflow { get; set; }
    global string varAttachmentParentId = 'init';

    global ModalFlowAttachment(){
        myflow  = new Flow.Interview.attachmentFlow2(new map<string, object>{'varAttachmentParentId'=> ''});
    }
    global string getVarAttachmentParentId() {
        if(varAttachmentParentId == 'init'){
            varAttachmentParentId = '';
            return '';
        }
        return myflow.varAttachmentParentId;
    }
    global Attachment attachment {
        get {
            if (attachment == null)
                attachment = new Attachment();
            return attachment;
        }
        set;
    }
    global PageReference upload() {

        attachment.OwnerId = UserInfo.getUserId();
        attachment.IsPrivate = true;
        attachment.parentId = getVarAttachmentParentId();

        try {
            insert attachment;
        } 
        catch (DMLException e) {
            ApexPages.addMessage(new ApexPages.message(ApexPages.severity.ERROR,'Error uploading attachment'));
            return null;
        } 
        finally {
            attachment = new Attachment();
        }

        ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Attachment uploaded successfully'));
        varAttachmentParentId = null;
        return null;
    }
}

Test  Class
 
@isTest
Private class ModalFlowAttachmentTest {
    
    @isTest static void CreateProperty() {
        McLabs2__Property__c Property = New McLabs2__Property__c();
        Property.Name                         = 'Fakename';
        Property.McLabs2__Property_Address__c = 'FakeAddress';
        Property.McLabs2__City__c             = 'FakeCity';
        Property.Block__c                     = '328';
        Property.Lot__c                       = '23';
        Insert Property;
    }
    
    static testMethod void ModalFlowAttachment_1() {

    system.Test.setCurrentPage(Page.ModalFlowAttachmentVF);
    ModalFlowAttachment controller = new ModalFlowAttachment();

    controller.getVarAttachmentParentId();
    
    Attachment tmpAttach = controller.attachment;
    Attachment attachment = new Attachment();
    attachment.Body = Blob.valueOf('Dreamforce15');
    attachment.Name = String.valueOf('Coastal Cloud.txt');
    attachment.ParentId = [select id from McLabs2__Property__c limit 1].id;
    
    controller.attachment = attachment;
    controller.upload();
  }
}

Any help is greatly appreciated
 

Hi all,

I am currently trying to create a test for my controller. The test I have currently gives me 100% in salesforce but it fails on validation to production.

What am i doing wrong?

public class ContactExtension {
  public ContactExtension(ApexPages.StandardController controller) {
    Contact C = (Contact)controller.getRecord();
    C.Recordtypeid = '012d0000001cltE';
  }
}




@istest(seeAllData='true')
public class ContactExtensionTest 
{
  public static testMethod  void ContactExtensionTest() {
    Contact Con = new Contact();
    ApexPages.StandardController controller = new ApexPages.StandardController(Con);
    ContactExtension extension = new ContactExtension(controller);
    System.assert(Con.Firstname !=Null);
  }
}

I keep getting this error when validating in production.



System.AssertException: Assertion Failed 
Stack Trace: Class.ContactExtensionTest.ContactExtensionTest: line 8, column 1