• asd@as.asd
  • NEWBIE
  • 55 Points
  • Member since 2011

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

hello,

        i have a custom object.now i create two master child reletionship in that object.

        is that object is now a junction object?

      

hello,

    i am facing a problem to write a test class of  a apex class.

   my test class cover 90% part of apex class.

   Apex class 

 

public class AccountSearchPagination {


public List<Account> accList { get; set; }

public String selectedCity { get; set; }
public String selectedState { get; set; }
public String selectedCountry { get; set; }

public List<SelectOption> cities { get; set; }
public List<SelectOption> states { get; set; }
public List<SelectOption> countries { get; set; }

public ApexPages.Standardsetcontroller setCon;

public AccountSearchPagination(){
cities = new List<SelectOption>();
states = new List<SelectOption>();
countries = new List<SelectOption>();

cities.add(new SelectOption('','-Select City-'));
states.add(new SelectOption('','-Select State-'));
countries.add(new SelectOption('','-Select Country-'));

selectedCity = '';
selectedState = '';
selectedCountry = '';

for(Account a : [Select id,name,BillingCity,BillingState,BillingCountry from Account]){
if(a.BillingCity!=null && a.BillingCity!=''){
cities.add(new SelectOption(a.BillingCity,a.BillingCity));
}
if(a.BillingState!=null && a.BillingState!=''){
states.add(new SelectOption(a.BillingState,a.BillingState));
}
if(a.BillingCountry!=null && a.BillingCountry!='' ){
countries.add(new SelectOption(a.BillingCountry,a.BillingCountry));
}
system.debug('This is provided in for loop of aaccount'+accList);
}
system.debug('This is provided in constructor'+accList);

setCon = new Apexpages.Standardsetcontroller(Database.getQueryLocator(generateQuery()));
setCon.setPageSize(0);
}

public String generateQuery(){
String query = 'select id,name from Account';
String whereClause = '';

if(selectedCity!=null && selectedCity!=''){
whereClause =' BillingCity =\''+selectedCity+'\'';
}
if(selectedState!=null && selectedState!=''){
if(whereClause!=''){
whereClause +=' and ';
}
whereClause +=' BillingState =\'' + selectedState + '\'';
}
if(selectedCountry!=null && selectedCountry!=''){
if(whereClause!=''){
whereClause +=' and ';
}
whereClause +=' BillingCountry =\''+ selectedCountry +'\'';
}
if(whereClause!=''){
query +=' Where '+whereClause;
}
return query;
}

public List<Account> getSearchAccountDetails(){
return (List<Account>) setCon.getRecords();
}

public PageReference search() {
setCon = new Apexpages.Standardsetcontroller(Database.getQueryLocator(generateQuery()));
setCon.setPageSize(10);
return null;
}

public Pagereference next(){
setCon.next();
return null;
}
public Pagereference last(){
setCon.last();
return null;
}
public Pagereference previous(){
setCon.previous();
return null;
}

public Boolean hasNext{
get{return setCon.getHasNext();}
set;
}

public Boolean hasPrevious{
get{return setCon.getHasPrevious();}
set;
}

public Integer pageNumber{
get{return setCon.getPageNumber();}
set {setCon.setPageNumber(1);}
}

}

 

now how to test code in red colour.

how to cover addError in test class

 

 

trigger insertStudent on Student__c (before insert ) {
Map<id,class__C> claMap=new Map<id,class__C>([select NumberOfStudents__c,MaxSize__c from class__c]);
for(Student__c s:Trigger.new){
class__c cls=claMap.get(s.class__c);
if(cls.NumberOfStudents__c >=cls.MaxSize__c){
s.addError('Can\'t add');
}
}

}

hello,

  i want to write a test class for a trigger but my test class cant cover Trigger on  undelete.

 Trigger 

trigger triggerOnMyCount on Student__c ( after insert , after delete ,after undelete) {

Map<Id,Class__c> claMap= new Map<id,Class__C>([Select c.NumberOfStudents__c,c.MyCount__c From Class__c c ]);
if(Trigger.isInsert){
for( student__c std : trigger.new ){
class__c cls=claMap.get(std.class__c);
cls.MyCount__c=cls.NumberOfStudents__c+1;
update cls;
}

}

if(trigger.isdelete){
for(student__c std : trigger.old){
class__c cls=claMap.get(std.class__c);
cls.MyCount__c=cls.NumberOfStudents__c-1;
update cls;
}
}

if(Trigger.isUnDelete){
for( student__c std : trigger.new ){
class__c cls=claMap.get(std.class__c);
cls.MyCount__c=cls.MyCount__c+1;
update cls;
}
}
}

 

TEST CLASS

@isTest
private class test_triggerOnMyCount{
static testmethod void triggerTest(){
class__C cls=new class__C();
cls.Name__c = 'Apex' ;
insert cls;
System.assertEquals(null,cls.MyCount__c);
Student__C std = new Student__C();
std.Last_Name__c='Tejpal';
std.class__C=cls.id;
insert std;
cls=[select MyCount__c from class__C where id=: cls.id];
System.assertEquals(1,cls.MyCount__c);
delete std;
cls=[select MyCount__c from class__C where id=: cls.id];
System.assertEquals(0,cls.MyCount__c);


}

}


please help

hello,

         how can i cover try-catch block in test class.

         Controller

public class TestPagecontroller {

            private String firstName;
            private String lastName;
            private String company;
            private String email;
            private String qp;

            public TestPagecontroller () {
                this.qp = ApexPages.currentPage().getParameters().get('qp');
            }

            public String getFirstName() {
                  return this.firstName;
            }

            public void setFirstName(String firstName) {
                  this.firstName = firstName;
            }

            public String getLastName() {
                  return this.lastName;
            }

            public void setLastName(String lastName) {
                  this.lastName = lastName;
            }

            public String getCompany() {
                  return this.company;
            }

            public void setCompany(String company) {
                  this.company = company;
            }

            public String getEmail() {
                  return this.email;
            }

            public void setEmail(String email) {
                  this.email = email;
            }

            public PageReference save() {
                PageReference p = null;
                
                if (this.qp == null || !'yyyy'.equals(this.qp)) {
                    p = Page.failure;
                    p.getParameters().put('error', 'noParam');
                } else {
                    try {
                        Lead newlead = new Lead(LastName=this.lastName,
                                                FirstName=this.firstName,
                                                Company=this.company,
                                                Email=this.email);
                        insert newlead;
                    } catch (Exception e) {
                        p = Page.failure;
                        p.getParameters().put('error', 'noInsert');
                    }
                }
                
                if (p == null) {
                    p = Page.success;
                }
                
                p.setRedirect(true);
                return p;
            }
 }

 

Test Class

 

public class thecontrollerTests {

    public static testMethod void testMyController() {
        PageReference pageRef = Page.success;
        Test.setCurrentPage(pageRef);
      
        TestPagecontroller controller = new TestPagecontroller();
        String nextPage = controller.save().getUrl();

        // Verify that page fails without parameters
    
        System.assertEquals('/apex/failure?error=noParam', nextPage);

        // Add parameters to page URL
    
        ApexPages.currentPage().getParameters().put('qp', 'yyyy');
      
        // Instantiate a new controller with all parameters in the page
    
        controller = new TestPagecontroller();
        controller.setLastName('lastname');
        
        controller.setFirstName('firstname');
        controller.setCompany('acme');
        controller.setEmail('firstlast@acme.com');
        System.assertEquals('lastname', controller.getLastName());
        System.assertEquals('firstname', controller.getFirstName());
        System.assertEquals('acme', controller.getCompany());
        System.assertEquals('firstlast@acme.com', controller.getEmail());
        nextPage = controller.save().getUrl();

        // Verify that the success page displays
    
        System.assertEquals('/apex/success', nextPage);
        Lead[] leads = [select id, email from lead where Company = 'acme'];
        System.assertEquals('firstlast@acme.com', leads[0].email);
        
    }
    }

 

 

here i am getting 92% Code Coverage. but my test class cant cover catch block.

Plz help me

hello,

           i have a lookup lookup field candidate__C in job_Application custom object.

           now i want to change field candidate__C  from lookup to master Master-Detail Relationship

           how can i do it.

hello,

how to pass list of account from one page to another page.

plz help me.

thanks.

hello,

   i am bit confusing using these  three methods. it's look like same or is there any deffernce among these methods.

plz help me

 

public PageReference next() {
        PageReference pp=new PageReference('https://c.ap1.visual.force.com/apex/demoControllerPage1);
        return pp;
  
    }

 

 

public PageReference next() {
     
    return Page.demoControllerPage1;
    }

 

 

public PageReference next() {

   PageReference acctPage = new ApexPages.StandardController(account).view();
   acctPage.setRedirect(true);
   return acctPage;

    }

hello

  i want to save a image in my custom object  candidate__C.

 how can i do this.

 

Hello

i want to know the differnce and use of of apex:function & apex:support

hello,

   i want to know the use of  TestStop & test start methd. 

   here is my working test class without testStop Method

  TEST CLASS

 

 @isTest
        Private class testChildCount{
            static testMethod  void  testoFChildCount(){
                Account acc1=new Account();
                acc1.name='Tej1';
                acc1.childCount__c=0;
                insert acc1;
                System.assertEquals(0,acc1.childCount__c);
                Account acc2=new Account();
                acc2.name='Tej2';
                acc2.ParentId=acc1.id;
                acc2.childCount__c=0;
                insert acc2;
                Account acc=[select childCount__c from account where id=: acc1.id ];
                System.assertEquals(1,acc.childCount__c);
                delete acc2;
                acc=[select childCount__c from account where id=: acc1.id ];
                System.assertEquals(0,acc.childCount__c);
                Account acc3=new Account();
                acc3.name='Tej3';
                acc3.childCount__c=0;
                insert acc3;
                Account acc4=new Account();
                acc4.name='Tej4';
                acc4.childCount__c=0;
                acc4.ParentId=acc1.id;
                insert acc4;
                acc=[select childCount__c from account where id=: acc1.id ];
                System.assertEquals(1,acc.childCount__c);
                acc=[select childCount__c from account where id=: acc4.id ];
                acc.ParentId=acc3.id;
                update acc;
                acc=[select childCount__c from account where id=: acc1.id ];
                System.assertEquals(0,acc.childCount__c);
                acc=[select childCount__c from account where id=: acc3.id ];
                System.assertEquals(1,acc.childCount__c);
            }
        }

hello

   i write a test method for a controller.but i get only  71% code coverage.

  i am facing  problem to write the test method for get set method.please help me

 here is my code :

  Controller: 

 

public class TestPagecontroller {

private String firstName;
private String lastName;
private String company;
private String email;
private String qp;

public TestPagecontroller () {
this.qp = ApexPages.currentPage().getParameters().get('qp');
}

public String getFirstName() {
return this.firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return this.lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getCompany() {
return this.company;
}

public void setCompany(String company) {
this.company = company;
}

public String getEmail() {
return this.email;
}

public void setEmail(String email) {
this.email = email;
}

public PageReference save() {
PageReference p = null;

if (this.qp == null || !'yyyy'.equals(this.qp)) {
p = Page.failure;
p.getParameters().put('error', 'noParam');
} else {
try {
Lead newlead = new Lead(LastName=this.lastName,
FirstName=this.firstName,
Company=this.company,
Email=this.email);
insert newlead;
} catch (Exception e) {
p = Page.failure;
p.getParameters().put('error', 'noInsert');
}
}

if (p == null) {
p = Page.success;
}

p.setRedirect(true);
return p;
}
}

 

testclass:

 

 

public class TestPagecontroller {

private String firstName;
private String lastName;
private String company;
private String email;
private String qp;

public TestPagecontroller () {
this.qp = ApexPages.currentPage().getParameters().get('qp');
}

public String getFirstName() {
return this.firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return this.lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getCompany() {
return this.company;
}

public void setCompany(String company) {
this.company = company;
}

public String getEmail() {
return this.email;
}

public void setEmail(String email) {
this.email = email;
}

public PageReference save() {
PageReference p = null;

if (this.qp == null || !'yyyy'.equals(this.qp)) {
p = Page.failure;
p.getParameters().put('error', 'noParam');
} else {
try {
Lead newlead = new Lead(LastName=this.lastName,
FirstName=this.firstName,
Company=this.company,
Email=this.email);
insert newlead;
} catch (Exception e) {
p = Page.failure;
p.getParameters().put('error', 'noInsert');
}
}

if (p == null) {
p = Page.success;
}

p.setRedirect(true);
return p;
}
}


hello 

    i am using test,startTest()  and test.stopTest() method in test class.

   i am  facing a error   :

    Method does not exist or incorrect signature: Test.startTest() at line 16 column 9

    my code is : 

       

 

      

@isTest

private class testclass{

public static testMethod void TestOverwriteTestAccountDescriptions(){
// Perform our data preparation.
List<Account> accounts = new List<Account>{};

for(Integer i = 0; i < 200; i++){
Account a = new Account(Name = 'Test Account ' + i);
accounts.add(a);
}

// Start the test, this changes governor limit context to 
// that of trigger rather than test. 
Test.startTest();

// Insert the Account records that cause the trigger to execute.
insert accounts; 

// Stop the test, this changes limit context back to test from trigger.
Test.stopTest();

// Query the database for the newly inserted records.
List<Account> insertedAccounts = [SELECT Name, Description 
FROM Account 
WHERE Id IN : accounts];

// Assert that the Description fields contains the proper value now.
for(Account a : insertedAccounts){
System.assertEquals(
'This Account is probably left over from testing. It should probably be deleted.', 
a.Description);
}
}
}

hello

         i am new salesforce.i want to write test class for triggers and controller class.

         please help me to write test class

hello

          i want to try somthing like this......

         Add a field ‘Primary Contact’ on Account, which would be a lookup to Contact object. Add a button on Account Detail      page labeled ‘Select Primary Contact’. On click of this button, a page should come up with list of all contacts associated with this Account in a table format. The left most column of this table would be a radio button. User should be able to select one contact and submit this page. On submission, the selected contact would become Primary Contact for this account and user would be redirected back to Account detail page.

 

      here i face a problem to create a table with selectradio button

 

how to cover addError in test class

 

 

trigger insertStudent on Student__c (before insert ) {
Map<id,class__C> claMap=new Map<id,class__C>([select NumberOfStudents__c,MaxSize__c from class__c]);
for(Student__c s:Trigger.new){
class__c cls=claMap.get(s.class__c);
if(cls.NumberOfStudents__c >=cls.MaxSize__c){
s.addError('Can\'t add');
}
}

}

hello,

  i want to write a test class for a trigger but my test class cant cover Trigger on  undelete.

 Trigger 

trigger triggerOnMyCount on Student__c ( after insert , after delete ,after undelete) {

Map<Id,Class__c> claMap= new Map<id,Class__C>([Select c.NumberOfStudents__c,c.MyCount__c From Class__c c ]);
if(Trigger.isInsert){
for( student__c std : trigger.new ){
class__c cls=claMap.get(std.class__c);
cls.MyCount__c=cls.NumberOfStudents__c+1;
update cls;
}

}

if(trigger.isdelete){
for(student__c std : trigger.old){
class__c cls=claMap.get(std.class__c);
cls.MyCount__c=cls.NumberOfStudents__c-1;
update cls;
}
}

if(Trigger.isUnDelete){
for( student__c std : trigger.new ){
class__c cls=claMap.get(std.class__c);
cls.MyCount__c=cls.MyCount__c+1;
update cls;
}
}
}

 

TEST CLASS

@isTest
private class test_triggerOnMyCount{
static testmethod void triggerTest(){
class__C cls=new class__C();
cls.Name__c = 'Apex' ;
insert cls;
System.assertEquals(null,cls.MyCount__c);
Student__C std = new Student__C();
std.Last_Name__c='Tejpal';
std.class__C=cls.id;
insert std;
cls=[select MyCount__c from class__C where id=: cls.id];
System.assertEquals(1,cls.MyCount__c);
delete std;
cls=[select MyCount__c from class__C where id=: cls.id];
System.assertEquals(0,cls.MyCount__c);


}

}


please help

hello,

         how can i cover try-catch block in test class.

         Controller

public class TestPagecontroller {

            private String firstName;
            private String lastName;
            private String company;
            private String email;
            private String qp;

            public TestPagecontroller () {
                this.qp = ApexPages.currentPage().getParameters().get('qp');
            }

            public String getFirstName() {
                  return this.firstName;
            }

            public void setFirstName(String firstName) {
                  this.firstName = firstName;
            }

            public String getLastName() {
                  return this.lastName;
            }

            public void setLastName(String lastName) {
                  this.lastName = lastName;
            }

            public String getCompany() {
                  return this.company;
            }

            public void setCompany(String company) {
                  this.company = company;
            }

            public String getEmail() {
                  return this.email;
            }

            public void setEmail(String email) {
                  this.email = email;
            }

            public PageReference save() {
                PageReference p = null;
                
                if (this.qp == null || !'yyyy'.equals(this.qp)) {
                    p = Page.failure;
                    p.getParameters().put('error', 'noParam');
                } else {
                    try {
                        Lead newlead = new Lead(LastName=this.lastName,
                                                FirstName=this.firstName,
                                                Company=this.company,
                                                Email=this.email);
                        insert newlead;
                    } catch (Exception e) {
                        p = Page.failure;
                        p.getParameters().put('error', 'noInsert');
                    }
                }
                
                if (p == null) {
                    p = Page.success;
                }
                
                p.setRedirect(true);
                return p;
            }
 }

 

Test Class

 

public class thecontrollerTests {

    public static testMethod void testMyController() {
        PageReference pageRef = Page.success;
        Test.setCurrentPage(pageRef);
      
        TestPagecontroller controller = new TestPagecontroller();
        String nextPage = controller.save().getUrl();

        // Verify that page fails without parameters
    
        System.assertEquals('/apex/failure?error=noParam', nextPage);

        // Add parameters to page URL
    
        ApexPages.currentPage().getParameters().put('qp', 'yyyy');
      
        // Instantiate a new controller with all parameters in the page
    
        controller = new TestPagecontroller();
        controller.setLastName('lastname');
        
        controller.setFirstName('firstname');
        controller.setCompany('acme');
        controller.setEmail('firstlast@acme.com');
        System.assertEquals('lastname', controller.getLastName());
        System.assertEquals('firstname', controller.getFirstName());
        System.assertEquals('acme', controller.getCompany());
        System.assertEquals('firstlast@acme.com', controller.getEmail());
        nextPage = controller.save().getUrl();

        // Verify that the success page displays
    
        System.assertEquals('/apex/success', nextPage);
        Lead[] leads = [select id, email from lead where Company = 'acme'];
        System.assertEquals('firstlast@acme.com', leads[0].email);
        
    }
    }

 

 

here i am getting 92% Code Coverage. but my test class cant cover catch block.

Plz help me

hello,

           i have a lookup lookup field candidate__C in job_Application custom object.

           now i want to change field candidate__C  from lookup to master Master-Detail Relationship

           how can i do it.

hello,

how to pass list of account from one page to another page.

plz help me.

thanks.

hello,

   i am bit confusing using these  three methods. it's look like same or is there any deffernce among these methods.

plz help me

 

public PageReference next() {
        PageReference pp=new PageReference('https://c.ap1.visual.force.com/apex/demoControllerPage1);
        return pp;
  
    }

 

 

public PageReference next() {
     
    return Page.demoControllerPage1;
    }

 

 

public PageReference next() {

   PageReference acctPage = new ApexPages.StandardController(account).view();
   acctPage.setRedirect(true);
   return acctPage;

    }

Hi,

 

Can someone help me in plain english and step by step about this problem:

 

I have one account with five opportunities attached to its account.

At account i have a field total_amount__c

 

I need a trigger code that will sum all amounts from this five opportunities and update total_amount__c field with sum result.

 

Please if enione can help me

 

Thank you!

hello 

    i am using test,startTest()  and test.stopTest() method in test class.

   i am  facing a error   :

    Method does not exist or incorrect signature: Test.startTest() at line 16 column 9

    my code is : 

       

 

      

@isTest

private class testclass{

public static testMethod void TestOverwriteTestAccountDescriptions(){
// Perform our data preparation.
List<Account> accounts = new List<Account>{};

for(Integer i = 0; i < 200; i++){
Account a = new Account(Name = 'Test Account ' + i);
accounts.add(a);
}

// Start the test, this changes governor limit context to 
// that of trigger rather than test. 
Test.startTest();

// Insert the Account records that cause the trigger to execute.
insert accounts; 

// Stop the test, this changes limit context back to test from trigger.
Test.stopTest();

// Query the database for the newly inserted records.
List<Account> insertedAccounts = [SELECT Name, Description 
FROM Account 
WHERE Id IN : accounts];

// Assert that the Description fields contains the proper value now.
for(Account a : insertedAccounts){
System.assertEquals(
'This Account is probably left over from testing. It should probably be deleted.', 
a.Description);
}
}
}

hello

         i am new salesforce.i want to write test class for triggers and controller class.

         please help me to write test class

hello

          i want to try somthing like this......

         Add a field ‘Primary Contact’ on Account, which would be a lookup to Contact object. Add a button on Account Detail      page labeled ‘Select Primary Contact’. On click of this button, a page should come up with list of all contacts associated with this Account in a table format. The left most column of this table would be a radio button. User should be able to select one contact and submit this page. On submission, the selected contact would become Primary Contact for this account and user would be redirected back to Account detail page.

 

      here i face a problem to create a table with selectradio button