• Shruthi GM 4
  • NEWBIE
  • 234 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 72
    Questions
  • 62
    Replies
Using javascrip in visualforce page I am trying to redirct page.
<script>

window.location.href='+/Account.id';

<script>
This is not working.....How do I pass id dynamically here?
Please help me.


Thanks in advance.
trigger Intervieee on Interviewer__c (after Update)

{

Set<Decimal> setPhoneNumber = new Set<Decimal>();
for(Interviewer__c i:trigger.new)
{
   if(i.Mobile_no__c != null)
{
// As per your current logic you are checking old value not new
   Interviewer__c invSet=Trigger.oldMap.get(i.Id);
   setPhoneNumber.add(invSet.Mobile_no__c);

}

    }
    if( setPhoneNumber.size() > 0 )
    {
    List<Candidates__c> canList = [select Name,Phone_Number__c,Qualification__c,Rating__c,Review_comments__c,Result__c,Mobile_no__c
              from Candidates__c where Mobile_no__c = :setPhoneNumber ];

                                         

        Map<Decimal ,Candidates__c> mapPhoneWiseCand = new Map<Decimal ,Candidates__c>();

        for( Candidates__c cand : canList )

        {

            mapPhoneWiseCand.put( cand.Mobile_no__c , cand );

        }

         

        list<Candidates__c> updatedcand=new list<Candidates__c>();

        for(Interviewer__c i:trigger.new)

        {

            if(i.Mobile_no__c != null)

            {

                Interviewer__c invSet=Trigger.oldMap.get(i.Id);

                if( mapPhoneWiseCand.containsKey( invSet.Mobile_no__c ) )

                {

                    Candidates__c canList1 = mapPhoneWiseCand.get(invSet.Mobile_no__c);

                     

                    canList1.Name=i.CName__c;

                    canlist1.Phone_Number__c=i.Phone_Number__c;

                    canlist1.Qualification__c=i.Candidate_s_qualification__c;

                    canlist1.Rating__c=i.Rating__c;
                    canlist1.Review_comments__c=i.Review_Comments__c;

                    canlist1.Result__c=i.Result__c;

                    canlist1.Mobile_no__c=i.Mobile_no__c;

                     

                    updatedcand.add(canList1);
                }

            }

        }

        if(updatedcand.size() > 0 )

        {

            try{

                system.debug('Before update');

                update updatedcand;

                system.debug('After update');

           }

            catch(Exception e){}

             

        }  

         

    }  

}

Please help.
Error during init [Action failed: c$TestController$controller$myAction [Cannot read property 'get' of undefined]]

Why this error actually comes up?
System.QueryException: Didn't understand relationship 'Id' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
What logic do I need to write to get the calls.I have written a wrapper class to fetch the details of the call.
Please help.
I need to display Calls and Opportunities based on the selection of Contact.
Do I need to write wrapper class?
Please help me.
When I am taking back up from my org through ANT tool,I am getting the above error!
Limit Exceede: Too many files to retrieve in the call.
What needs to be done to rectify this error?

Please help.
Multi select component I have used to get multi picklist field in the vf page.how to make the field on the vf as mandatory?
I need to add something in the component so that an astrisk symbol or a red line comes up so that on the vf page the field seems mandatory?
Please help.
I have multi picklist field that which is not standard.It has been got through component.Now I need to make this multipicklist field mandatory on the vf page.I added "Required" keyword in the vf page which did not work actually.
Can anybody please help as how to make this mandatory.
In a class I have used standard set controller.How to cover the same in the test class?
Please help.
/* class */

Global class emailHelper {
public static void sendEmail(ID recipient, ID candidate) {
//New instance of a single email message
Messaging.SingleEmailMessage mail =

            new Messaging.SingleEmailMessage();

  

// Who you are sending the email to

   mail.setTargetObjectId(recipient);

 

   // The email template ID used for the email

   mail.setTemplateId('');

           

   mail.setWhatId(candidate);   

   mail.setBccSender(false);

   mail.setUseSignature(false);

   mail.setReplyTo('recruiting@acme.com');

   mail.setSenderDisplayName('HR Recruiting');

   mail.setSaveAsActivity(false); 

 Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 

    } 

}

/* testclass */


@istest

public class emailHelpertest{

public static testmethod void testvalidate(){

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator']; 
User u = new User(Alias = 'test1', Email='test@gamil.com',FirstName = 'Test', 
            EmailEncodingKey='UTF-8', LastName='Testlast', LanguageLocaleKey='en_US', 
            LocaleSidKey='en_US', ProfileId = p.Id, 
            TimeZoneSidKey='America/Los_Angeles', UserName='test111@gmail.com');
            insert u;
ID candidate;
ID recipient;

Contact con=new Contact();
con.lastname='Testing';
insert con;

test.starttest();
//mail.setTemplateId('');
mail.setTargetObjectId(recipient);
mail.setWhatId(candidate);   
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setReplyTo('recruiting@acme.com');
mail.setSenderDisplayName('HR Recruiting');
mail.setSaveAsActivity(false); 
emailHelper ehelp=new emailHelper();
emailHelper.sendEmail(recipient,candidate);
test.stoptest();
}
}

But this test class has an error saying invalid id.It is able to cover only 41%.Please help.
/* class */
global class  CustomIterable implements Iterator<list<AccountWrapper>>
{
list<AccountWrapper> InnerList{get; set;}
list<AccountWrapper> ListRequested{get; set;}
Integer i {get; set;}
public Integer setPageSize {get; set;}
public CustomIterable(List<AccountWrapper> lstAccWr)
{
InnerList = new list<AccountWrapper>();
ListRequested = new list<AccountWrapper>();    
InnerList = lstAccWr;
setPageSize = 10;
i = 0;
}  

 
global boolean hasNext(){
if(i >= InnerList.size()) {
return false;

       } else {

           return true;

       }

   }

    

global boolean hasPrevious(){
system.debug('I am in hasPrevious' + i);
if(i <= setPageSize) {
return false;
} else {
return true;
}
}  

 
global list<AccountWrapper> next(){      
system.debug('i value is ' + i);
ListRequested = new list<AccountWrapper>();
integer startNumber;
integer size = InnerList.size();
if(hasNext())

if(size <= (i + setPageSize))
{
startNumber = i;
i = size;
}
else
{
i = (i + setPageSize);
startNumber = (i - setPageSize);
}
system.debug('i value is =====' + i);
system.debug('i value is 2==== ' + (i - setPageSize));

for(integer start = startNumber; start < i; start++)
{
ListRequested.add(InnerList[start]);
}

}
return ListRequested;
}

    
global list<AccountWrapper> previous(){     
ListRequested = new list<AccountWrapper>();
system.debug('i value is previous before =====' + i);
integer size = InnerList.size();
if(i == size)
{
if(math.mod(size, setPageSize) > 0)
{   
i = size - math.mod(size, setPageSize);
}
else
{
i = (size - setPageSize);
}
}
else
{
i = (i - setPageSize);
}
system.debug('i value is previous =====' + i);
system.debug('i value is 2previous ==== ' + (i - setPageSize));

for(integer start = (i - setPageSize); start < i; ++start)
{
ListRequested.add(InnerList[start]);
}
return ListRequested;

   }  


}

How to write test class for this particular class?

I have written it in the following way:-

@istest

public class CustomIterabletest{


public static testmethod void testvalidate(){

list<AccountWrapper> InnerList;
list<AccountWrapper> ListRequested;
List<AccountWrapper> lstAccWr;

InnerList = new list<AccountWrapper>();
ListRequested = new list<AccountWrapper>();    
InnerList = lstAccWr;
integer setPageSize = 10;
integer i = 0;



test.starttest();
CustomIterable custom=new CustomIterable(lstAccWr);
custom.hasNext();
custom.hasPrevious();
custom.next();
custom.previous();
test.stoptest();
}
}

But it is not even covering the single method!!!
/* Class */

global class LightningForgotPasswordController {

    public LightningForgotPasswordController() {

    }

    @AuraEnabled
    public static String forgotPassowrd(String username, String checkEmailUrl) {
        try {
            Site.forgotPassword(username);
            ApexPages.PageReference checkEmailRef = new PageReference(checkEmailUrl);
            if(!Site.isValidUsername(username)) {
                return Label.Site.invalid_email;
            }
            aura.redirect(checkEmailRef);
            return null;
        }
        catch (Exception ex) {
            return ex.getMessage();
        }
    }

}

/* test class */

@istest

public class LightningForgotPasswordControllertest{


public static testmethod void testvalidate(){

String username='shrugm@tcs.com';
String checkEmailUrl='aabgfgb';

test.starttest();
LightningForgotPasswordController lightningForgot=new LightningForgotPasswordController();
LightningForgotPasswordController.forgotPassowrd('shrugm@tcs.com','aabgfgb');
test.stoptest();
}
}

it is covering 63% of the code.Please help me to cover the entire class!
Please help me in writing the test class for the below class:-
public class loadingSpinnerCtrl {
    public List<String> dropdown1{get; set;}
    public List<SelectOption> options;
    public void spin() {
        options = new List<SelectOption>();
        for(String s: dropdown1){
            if(s == '1'){
                options.add(new SelectOption('1','Value 1'));
                options.add(new SelectOption('2','Value 2'));
            }else if(s == '2'){
                options.add(new SelectOption('3','Value 3'));
                options.add(new SelectOption('4','Value 4'));
            }else if(s == '3'){
                options.add(new SelectOption('5','Value 5'));
                options.add(new SelectOption('6','Value 6'));
            }else if(s == '4'){
                options.add(new SelectOption('7','Value 7'));
                options.add(new SelectOption('8','Value 8'));
            }else if(s == '5'){
                options.add(new SelectOption('7','Value 9'));
                options.add(new SelectOption('8','Value 10'));
            }            
        }    
        long now = datetime.now().gettime();
        while(datetime.now().gettime()-now<2000); // Busy loop for 2000 ms to simulate delay
    }
    public List<SelectOption> getItems() {
        return options;
    }    
}
Trigger

trigger Intervieee on Interviewer__c (after Update) {


list<Candidates__c> updatedcand=new list<Candidates__c>();
set<ID> ChangedInter = new set<ID>();


Candidates__c can=new Candidates__c();
for(Interviewer__c i:trigger.new){
Interviewer__c invSet=Trigger.oldMap.get(i.Id);
system.debug('123456'+invSet.Mobile_no__c);



Candidates__c canList=[select Name,Phone_Number__c,Qualification__c,Rating__c,Review_comments__c,Result__c,Mobile_no__c from Candidates__c where Mobile_no__c =: invSet.Mobile_no__c];

if(invSet.Mobile_no__c==canList.Mobile_no__c){

canList.Name=i.CName__c;
canlist.Phone_Number__c=i.Phone_Number__c;
canlist.Qualification__c=i.Candidate_s_qualification__c;
canlist.Rating__c=i.Rating__c;
canlist.Review_comments__c=i.Review_Comments__c;
canlist.Result__c=i.Result__c;
canlist.Mobile_no__c=i.Mobile_no__c;
updatedcand.add(canList);
}
}
try{
system.debug('Before update');
update updatedcand;
system.debug('After update');
}
catch(Exception e){}


test class

@istest

public class Intervieeetest{

public static testmethod void testvalidate(){

test.starttest();


list<Candidates__c> candis=new list<Candidates__c>();

Candidates__c cand=new Candidates__c();
cand.Name='Testing';
cand.Qualification__c='BE';
cand.Review_comments__c='Keep it up';
cand.Rating__c='A';
cand.Result__c='Cleared';
cand.Mobile_no__c=0;

candis.add(cand);



insert candis;

Interviewer__c interview=new Interviewer__c ();
//interview.Name='Testing';
interview.Result__c='Pass';
insert interview;



test.stoptest();







}
}
//Class//
public with sharing class lifecycle{

private final Account acct;
Integer EmpAdd;

Public lifecycle(MYControllernew controller) {
this.acct = (Account)controller.getAccount();
}

public String getGreeting(){
return acct.name + ' Current Information';
}

public void resetEmp() {
acct.numberofemployees = 10;
update acct;


}
}

//testclass//

@istest
public class lifecycletest{

public static testmethod void testvalidate(){

Account acc=new Account ();
acc.Name='Testing';
insert acc;


test.starttest();

//ApexPages.StandardController MYControllernew= new ApexPages.StandardController(acc);
//lifecycle mec = new lifecycle(MYControllernew controller);
//ApexPages.currentPage().getParameters().put('id',acc.id);
        
//mec.getGreeting();
//mec.resetEmp();


test.stoptest();



}

My testclass is not covering the above class.Am getting error regarding standard controller.
Please help.
/*Class*/


public with sharing class bookscontroller{
String searchText;
List<Book__c> results;
public String getSearchText() {
return searchText;
}
public void setSearchText(String s) {
searchText = s;
}
public List<Book__c> getResults() {
return results;
}
public PageReference doSearch() {
results = (List<Book__c>)[FIND :searchText RETURNING Book__c(Name, price__c)][0];
return null;
}
}

/*Test Class*/
@isTest
public class bookscontrollertest{

public static testmethod void testvalidate1(){

List<Book__c> books=new List<Book__c>();

Book__c book=new Book__c();
book.Name='Testing';
book.Price__c=100;

books.add(book);


Book__c book1=new Book__c();
book1.Name='Testing1';
book1.Price__c=200;

books.add(book1);
insert books;



test.starttest();
bookscontroller bcontrol=new bookscontroller();
bcontrol.doSearch();
test.stoptest();
}

Only 22% code coverage is observed.
Can anybody please help me on this?
public class ToyStore{
 public static void addDiscount(toys__c[] toys){
 
 for(toys__c t:toys){
 t.Price__c*=0.4;

 
 
 }
 
 
 }

}

Here is the test class:-

@isTest

private class ToyStoreTestclass{
static void testvalidate(){
 

List<Toys__c> toys=new List<Toys__c>();
Toys__c toy=new Toys__c();
toy.Name='Test';
toy.Price__c=500;
toy.toy_code__c=50;
toy.Feedback__c='testing';
toys.add(toy);

Toys__c toy1=new Toys__c();
toy1.Name='Test1';
toy1.Price__c=50;
toy1.toy_code__c=500;
toy1.Feedback__c='testing1';
toys.add(toy1);

insert toys;
test.starttest(); 
ToyStore.addDiscount(toys);
test.stoptest();

}
}

I have created toys and called the method as well.Still zero lines of code is covered in the class.Please let me know what is missing?
Please help.
 
How to write test class for this class?


public with sharing class AttachmentUploadController {

  public Attachment attachment {
  get {
      if (attachment == null)
        attachment = new Attachment();
      return attachment;
    }
  set;
  }

  public PageReference upload() {

    attachment.OwnerId = UserInfo.getUserId();
   // attachment.ParentId = Account.getId; // the record the file is attached to
    attachment.IsPrivate = true;

    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'));
    return null;
  }

}
How to get rid of this error?
Can anyone please suggest way to remove this error?!


Thanks inadvance.
trigger Intervieee on Interviewer__c (after Update)

{

Set<Decimal> setPhoneNumber = new Set<Decimal>();
for(Interviewer__c i:trigger.new)
{
   if(i.Mobile_no__c != null)
{
// As per your current logic you are checking old value not new
   Interviewer__c invSet=Trigger.oldMap.get(i.Id);
   setPhoneNumber.add(invSet.Mobile_no__c);

}

    }
    if( setPhoneNumber.size() > 0 )
    {
    List<Candidates__c> canList = [select Name,Phone_Number__c,Qualification__c,Rating__c,Review_comments__c,Result__c,Mobile_no__c
              from Candidates__c where Mobile_no__c = :setPhoneNumber ];

                                         

        Map<Decimal ,Candidates__c> mapPhoneWiseCand = new Map<Decimal ,Candidates__c>();

        for( Candidates__c cand : canList )

        {

            mapPhoneWiseCand.put( cand.Mobile_no__c , cand );

        }

         

        list<Candidates__c> updatedcand=new list<Candidates__c>();

        for(Interviewer__c i:trigger.new)

        {

            if(i.Mobile_no__c != null)

            {

                Interviewer__c invSet=Trigger.oldMap.get(i.Id);

                if( mapPhoneWiseCand.containsKey( invSet.Mobile_no__c ) )

                {

                    Candidates__c canList1 = mapPhoneWiseCand.get(invSet.Mobile_no__c);

                     

                    canList1.Name=i.CName__c;

                    canlist1.Phone_Number__c=i.Phone_Number__c;

                    canlist1.Qualification__c=i.Candidate_s_qualification__c;

                    canlist1.Rating__c=i.Rating__c;
                    canlist1.Review_comments__c=i.Review_Comments__c;

                    canlist1.Result__c=i.Result__c;

                    canlist1.Mobile_no__c=i.Mobile_no__c;

                     

                    updatedcand.add(canList1);
                }

            }

        }

        if(updatedcand.size() > 0 )

        {

            try{

                system.debug('Before update');

                update updatedcand;

                system.debug('After update');

           }

            catch(Exception e){}

             

        }  

         

    }  

}

Please help.
System.QueryException: Didn't understand relationship 'Id' in field path. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
I need to display Calls and Opportunities based on the selection of Contact.
Do I need to write wrapper class?
Please help me.
Multi select component I have used to get multi picklist field in the vf page.how to make the field on the vf as mandatory?
I need to add something in the component so that an astrisk symbol or a red line comes up so that on the vf page the field seems mandatory?
Please help.
/* class */

Global class emailHelper {
public static void sendEmail(ID recipient, ID candidate) {
//New instance of a single email message
Messaging.SingleEmailMessage mail =

            new Messaging.SingleEmailMessage();

  

// Who you are sending the email to

   mail.setTargetObjectId(recipient);

 

   // The email template ID used for the email

   mail.setTemplateId('');

           

   mail.setWhatId(candidate);   

   mail.setBccSender(false);

   mail.setUseSignature(false);

   mail.setReplyTo('recruiting@acme.com');

   mail.setSenderDisplayName('HR Recruiting');

   mail.setSaveAsActivity(false); 

 Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 

    } 

}

/* testclass */


@istest

public class emailHelpertest{

public static testmethod void testvalidate(){

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator']; 
User u = new User(Alias = 'test1', Email='test@gamil.com',FirstName = 'Test', 
            EmailEncodingKey='UTF-8', LastName='Testlast', LanguageLocaleKey='en_US', 
            LocaleSidKey='en_US', ProfileId = p.Id, 
            TimeZoneSidKey='America/Los_Angeles', UserName='test111@gmail.com');
            insert u;
ID candidate;
ID recipient;

Contact con=new Contact();
con.lastname='Testing';
insert con;

test.starttest();
//mail.setTemplateId('');
mail.setTargetObjectId(recipient);
mail.setWhatId(candidate);   
mail.setBccSender(false);
mail.setUseSignature(false);
mail.setReplyTo('recruiting@acme.com');
mail.setSenderDisplayName('HR Recruiting');
mail.setSaveAsActivity(false); 
emailHelper ehelp=new emailHelper();
emailHelper.sendEmail(recipient,candidate);
test.stoptest();
}
}

But this test class has an error saying invalid id.It is able to cover only 41%.Please help.
/* Class */

global class LightningForgotPasswordController {

    public LightningForgotPasswordController() {

    }

    @AuraEnabled
    public static String forgotPassowrd(String username, String checkEmailUrl) {
        try {
            Site.forgotPassword(username);
            ApexPages.PageReference checkEmailRef = new PageReference(checkEmailUrl);
            if(!Site.isValidUsername(username)) {
                return Label.Site.invalid_email;
            }
            aura.redirect(checkEmailRef);
            return null;
        }
        catch (Exception ex) {
            return ex.getMessage();
        }
    }

}

/* test class */

@istest

public class LightningForgotPasswordControllertest{


public static testmethod void testvalidate(){

String username='shrugm@tcs.com';
String checkEmailUrl='aabgfgb';

test.starttest();
LightningForgotPasswordController lightningForgot=new LightningForgotPasswordController();
LightningForgotPasswordController.forgotPassowrd('shrugm@tcs.com','aabgfgb');
test.stoptest();
}
}

it is covering 63% of the code.Please help me to cover the entire class!
Trigger

trigger Intervieee on Interviewer__c (after Update) {


list<Candidates__c> updatedcand=new list<Candidates__c>();
set<ID> ChangedInter = new set<ID>();


Candidates__c can=new Candidates__c();
for(Interviewer__c i:trigger.new){
Interviewer__c invSet=Trigger.oldMap.get(i.Id);
system.debug('123456'+invSet.Mobile_no__c);



Candidates__c canList=[select Name,Phone_Number__c,Qualification__c,Rating__c,Review_comments__c,Result__c,Mobile_no__c from Candidates__c where Mobile_no__c =: invSet.Mobile_no__c];

if(invSet.Mobile_no__c==canList.Mobile_no__c){

canList.Name=i.CName__c;
canlist.Phone_Number__c=i.Phone_Number__c;
canlist.Qualification__c=i.Candidate_s_qualification__c;
canlist.Rating__c=i.Rating__c;
canlist.Review_comments__c=i.Review_Comments__c;
canlist.Result__c=i.Result__c;
canlist.Mobile_no__c=i.Mobile_no__c;
updatedcand.add(canList);
}
}
try{
system.debug('Before update');
update updatedcand;
system.debug('After update');
}
catch(Exception e){}


test class

@istest

public class Intervieeetest{

public static testmethod void testvalidate(){

test.starttest();


list<Candidates__c> candis=new list<Candidates__c>();

Candidates__c cand=new Candidates__c();
cand.Name='Testing';
cand.Qualification__c='BE';
cand.Review_comments__c='Keep it up';
cand.Rating__c='A';
cand.Result__c='Cleared';
cand.Mobile_no__c=0;

candis.add(cand);



insert candis;

Interviewer__c interview=new Interviewer__c ();
//interview.Name='Testing';
interview.Result__c='Pass';
insert interview;



test.stoptest();







}
}
/*Class*/


public with sharing class bookscontroller{
String searchText;
List<Book__c> results;
public String getSearchText() {
return searchText;
}
public void setSearchText(String s) {
searchText = s;
}
public List<Book__c> getResults() {
return results;
}
public PageReference doSearch() {
results = (List<Book__c>)[FIND :searchText RETURNING Book__c(Name, price__c)][0];
return null;
}
}

/*Test Class*/
@isTest
public class bookscontrollertest{

public static testmethod void testvalidate1(){

List<Book__c> books=new List<Book__c>();

Book__c book=new Book__c();
book.Name='Testing';
book.Price__c=100;

books.add(book);


Book__c book1=new Book__c();
book1.Name='Testing1';
book1.Price__c=200;

books.add(book1);
insert books;



test.starttest();
bookscontroller bcontrol=new bookscontroller();
bcontrol.doSearch();
test.stoptest();
}

Only 22% code coverage is observed.
Can anybody please help me on this?
public with sharing class AccountSelectClassController{
//Our collection of the class/wrapper objects wrapAccount
public List<wrapAccount> wrapAccountList {get; set;}
public List<Account> selectedAccounts{get;set;}


public AccountSelectClassController(){
if(wrapAccountList == null) {
wrapAccountList = new List<wrapAccount>();
for(Account a: [select Id, Name from Account limit 25]) {
// As each Account is processed we create a new wrapAccount object and add it to the wrapAccountList
wrapAccountList.add(new wrapAccount(a));
}
}

}
public void processSelected() {
selectedAccounts = new List<Account>();
for(wrapAccount wrapAccountObj : wrapAccountList) {
if(wrapAccountObj.selected == true) {
selectedAccounts.add(wrapAccountObj.acc);
 }

        }

    }
    }

Please help!!!