• Devayani Avadhani
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 3
    Replies
Hi All, Our product built on salesforce service cloud serves 8 different companies with different holiday schedules, and the holidays for a company can also differ based on states. I would want time-based email alerts to be sent only on holidays. Any solution is greatly appreciated!
I get this error when I try to update Email using Javascript remoting on User object.
VFRemote.js:117 Visualforce Remoting Exception: You popped a context which you never pushed, check for unbalanced push and pops: ContextFrame:common.apex.runtime.bytecode.BytecodeApexContext@270aa53f:Established by /apexremote 
Established at Wed Aug 03 20:06:47 GMT 2016

Any help is greatly appreciated thanks.
Devayani.
Here is my Class: the lines that are covered are in bold, italics and underlined. How do i cover these lines.
public with sharing class fxolaf2_CreateNewPassword{
    public fxolaf2_CreateNewPassword() {
        serverErrors = new List<String>();
        email = UserInfo.getUserEmail();
    }
    
    public String newPassword {get; set;}
    public String verifyNewPassword {get; set;}
    public List<String> serverErrors{get; set;}
    public String email{get; set;}
    public PageReference pr = null;
    public String error {
        get{
            if (serverErrors.size() > 0) {
                return serverErrors[0];
            }
            
            return null;
        }
    }       
    
    public boolean isValidPassword() {
        system.debug('Isvalid password method**');
        return newPassword == verifyNewPassword;
    }
    
    public PageReference changePassword(){
        
        try {
            
            if (!isValidPassword()) {
                serverErrors.add('Passwords must match.');
                return null;
            }
            
            pr = Site.changePassword(newPassword, verifyNewPassword);
            if (pr == null) {
                serverErrors.add('An unexpected error occurred. Please try again.');
            }
            
            if(Test.isRunningTest()) {
                pr = new PageReference('/abc/abc_login');
                serverErrors.clear();//This is to have coverage for the condition if serverErrors.size() is not greater than 0 in the property string error.
            }
            
            system.debug(pr);//pr here is pagereference to Active Site Home page
            
                       
        }
        
        catch(Exception ex) {
            serverErrors.add(ex.getMessage());
        } 
        
        return pr;
    }
}
Here is my test class:
@isTest
private class fxolaf2_CreateNewPasswordTest {

    public static testMethod void test1() {
        // Instantiate a new controller with all parameters in the page
        fxolaf2_CreateNewPassword controller = new fxolaf2_CreateNewPassword();
        try{
            controller.newPassword = 'qwerty1'; 
            controller.verifyNewPassword = 'qwerty1';   
            PageReference pr = controller.changePassword(); 
            system.debug(controller.serverErrors+'TestClass Server Errors');
        }catch(Exception e){
            
        }
        system.assert(true,null);     
        System.assertNotEquals(controller.pr,null);
        System.assertEquals(controller.serverErrors.Size(), 0);
    } 
    public static testMethod void test2() {
        // Instantiate a new controller with all parameters in the page
        fxolaf2_CreateNewPassword controller = new fxolaf2_CreateNewPassword();
        controller.newPassword = ''; 
        controller.verifyNewPassword = 'qwerty1';
        pageReference  pr = controller.changePassword();
        System.assertEquals(controller.error,'Passwords must match.'); 
        System.assertEquals(controller.serverErrors.Size(), 1);
        System.assertEquals(controller.isValidPassword(),false);                         
    }  
    
    
    public static testMethod void test3()
    {
      fxolaf2_CreateNewPassword controller = new fxolaf2_CreateNewPassword();
      System.assertEquals(controller.serverErrors.Size(), 0);
      System.assertNotEquals(controller.email , null);
    }
    
}


Thanks,
Devayani.
I have a HTTPCallout class, whose response is captured and saved as a document or updated if that document already exists in database. I have separated the class so that the Callout is done in another class and DML is done in another class. But how do I test the DML after callout. The class which has just Callout code is 100% covered but not the code that contains DML. I get various errors while running the test. i have created Mock for the Callout. Should I also include the DML in mock? If so then how?
This is the test class:
@isTest(SeeAllData=true)
    public class fxolaf2_FetchInavDocsTest{
    @isTest static void testCallout(){

    test.starttest();
    string headerURL = 'https://www.example.html';
    string documentName = 'iNav_US_Header';
    // insert iNavURLs;
    // Set mock callout class 

     Test.setMock(HttpCalloutMock.class, new fxolaf2_fetchInavURLsMock());

    // Call method to test.
    // This causes a fake response to be sent
    // from the class that implements HttpCalloutMock. 
    HttpResponse res = fxolaf2_fetchINavURLsCallout.doCallout(headerURL,documentName);

    test.stoptest();

    //       System.assertEquals('Test', docs[0].Name);
    // Verify response received contains fake values

    String actualValue = res.getBody();
    String expectedValue = 'Test Body';
    System.assertEquals(actualValue, expectedValue);
    //System.assertEquals(200, res.getStatusCode());

}

@isTest static void testDocsCreation(){
    test.startTest();
    Test.setMock(HttpCalloutMock.class, new fxolaf2_fetchInavURLsMock());
    fxolaf2_FetchINavDocuments.postOrder();
    test.stoptest();
}

}

This is my Calloutclass which has 100% coverage:
public class fxolaf2_fetchINavURLsCallout {
public static HttpResponse doCallout(String iNavUrl, String docName) {
    HttpRequest req = new HttpRequest();
    req.setEndpoint(iNavUrl);
    req.setMethod('GET');
    Http h = new Http();
    HttpResponse res = h.send(req);
    return res;
}
}

This is the real class that needs coverage:
global class fxolaf2_FetchINavDocuments {
     public static void postOrder(){

    string INavDocument =' ';      
    List<fxolaf2_iNav_URLs__c> iNavURLsList = [select Name, Header_URL__c, Footer_URL__c from fxolaf2_iNav_URLs__c limit 2];
    fxolaf2_iNav_URLs__c temp = new fxolaf2_iNav_URLs__c();

    if(iNavURLsList != null) {
        for(Integer i = 0; i < iNavURLsList.size(); i++) {
            temp = iNavURLsList.get(i);
            system.debug('iNavURLList' +  i + temp );
            //Fetching header and attching the doc
            if(temp.Header_URL__c != null) {
                attachINavDocuments(temp.Header_URL__c,'iNav_'+temp.Name + '_'+'Header');
                INavDocument = 'iNav_'+temp.Name + '_'+'Header';
            }
            //Fetching footer and attching to document
            if(temp.Footer_URL__c != null) {
                attachINavDocuments(temp.Footer_URL__c,'iNav_'+temp.Name + '_'+'Footer');
                INavDocument = 'iNav_'+temp.Name + '_'+'Footer';
            }

        }    
    }

}
@future(callout = true)
public static void attachINavDocuments(String iNavUrl, String docName) {

    HTTPREsponse res = fxolaf2_fetchINavURLsCallout.doCallOut(iNavUrl, docName);

    //If success

    if(res.getStatusCode()==200){
        Document d = new Document();
        d.Name = docName;
        d.ContentType = 'text/html';
        d.Type='html';

        Folder[] folders = [select id from Folder where name='fxolaf2_iNav_documents'];//Folder into which the documents should be stored
        if(folders != null && folders.size() > 0) {
            d.FolderId = folders[0].id;  
            d.Body = res.getBodyAsBlob();
            List<Document> iNavDocNameList = [select Name,ID from Document where Name =: d.Name];
            //If already present update the doc
            if(iNavDocNameList != null && iNavDocNameList.size() > 0) {
                Document tempDoc = new Document();
                tempDoc = iNavDocNameList.get(0);
                d.ID = tempDoc.ID;
                update d;

            } else {
                //Insert the doc
                insert d;

            }               
        } else {
            //Create the folder   
        }
    }

}

Here is the Mock response Class:
@isTest
global class fxolaf2_fetchInavURLsMock implements HttpCalloutMock  {
global HTTPResponse respond(HTTPRequest req){
    // Create a fake response
    HttpResponse res = new HttpResponse();
    res.setBody('Test Body');
    res.setStatusCode(200);        
    return res;
}
}

 
Here is my Class: the lines that are covered are in bold, italics and underlined. How do i cover these lines.
public with sharing class fxolaf2_CreateNewPassword{
    public fxolaf2_CreateNewPassword() {
        serverErrors = new List<String>();
        email = UserInfo.getUserEmail();
    }
    
    public String newPassword {get; set;}
    public String verifyNewPassword {get; set;}
    public List<String> serverErrors{get; set;}
    public String email{get; set;}
    public PageReference pr = null;
    public String error {
        get{
            if (serverErrors.size() > 0) {
                return serverErrors[0];
            }
            
            return null;
        }
    }       
    
    public boolean isValidPassword() {
        system.debug('Isvalid password method**');
        return newPassword == verifyNewPassword;
    }
    
    public PageReference changePassword(){
        
        try {
            
            if (!isValidPassword()) {
                serverErrors.add('Passwords must match.');
                return null;
            }
            
            pr = Site.changePassword(newPassword, verifyNewPassword);
            if (pr == null) {
                serverErrors.add('An unexpected error occurred. Please try again.');
            }
            
            if(Test.isRunningTest()) {
                pr = new PageReference('/abc/abc_login');
                serverErrors.clear();//This is to have coverage for the condition if serverErrors.size() is not greater than 0 in the property string error.
            }
            
            system.debug(pr);//pr here is pagereference to Active Site Home page
            
                       
        }
        
        catch(Exception ex) {
            serverErrors.add(ex.getMessage());
        } 
        
        return pr;
    }
}
Here is my test class:
@isTest
private class fxolaf2_CreateNewPasswordTest {

    public static testMethod void test1() {
        // Instantiate a new controller with all parameters in the page
        fxolaf2_CreateNewPassword controller = new fxolaf2_CreateNewPassword();
        try{
            controller.newPassword = 'qwerty1'; 
            controller.verifyNewPassword = 'qwerty1';   
            PageReference pr = controller.changePassword(); 
            system.debug(controller.serverErrors+'TestClass Server Errors');
        }catch(Exception e){
            
        }
        system.assert(true,null);     
        System.assertNotEquals(controller.pr,null);
        System.assertEquals(controller.serverErrors.Size(), 0);
    } 
    public static testMethod void test2() {
        // Instantiate a new controller with all parameters in the page
        fxolaf2_CreateNewPassword controller = new fxolaf2_CreateNewPassword();
        controller.newPassword = ''; 
        controller.verifyNewPassword = 'qwerty1';
        pageReference  pr = controller.changePassword();
        System.assertEquals(controller.error,'Passwords must match.'); 
        System.assertEquals(controller.serverErrors.Size(), 1);
        System.assertEquals(controller.isValidPassword(),false);                         
    }  
    
    
    public static testMethod void test3()
    {
      fxolaf2_CreateNewPassword controller = new fxolaf2_CreateNewPassword();
      System.assertEquals(controller.serverErrors.Size(), 0);
      System.assertNotEquals(controller.email , null);
    }
    
}


Thanks,
Devayani.
I have a HTTPCallout class, whose response is captured and saved as a document or updated if that document already exists in database. I have separated the class so that the Callout is done in another class and DML is done in another class. But how do I test the DML after callout. The class which has just Callout code is 100% covered but not the code that contains DML. I get various errors while running the test. i have created Mock for the Callout. Should I also include the DML in mock? If so then how?
This is the test class:
@isTest(SeeAllData=true)
    public class fxolaf2_FetchInavDocsTest{
    @isTest static void testCallout(){

    test.starttest();
    string headerURL = 'https://www.example.html';
    string documentName = 'iNav_US_Header';
    // insert iNavURLs;
    // Set mock callout class 

     Test.setMock(HttpCalloutMock.class, new fxolaf2_fetchInavURLsMock());

    // Call method to test.
    // This causes a fake response to be sent
    // from the class that implements HttpCalloutMock. 
    HttpResponse res = fxolaf2_fetchINavURLsCallout.doCallout(headerURL,documentName);

    test.stoptest();

    //       System.assertEquals('Test', docs[0].Name);
    // Verify response received contains fake values

    String actualValue = res.getBody();
    String expectedValue = 'Test Body';
    System.assertEquals(actualValue, expectedValue);
    //System.assertEquals(200, res.getStatusCode());

}

@isTest static void testDocsCreation(){
    test.startTest();
    Test.setMock(HttpCalloutMock.class, new fxolaf2_fetchInavURLsMock());
    fxolaf2_FetchINavDocuments.postOrder();
    test.stoptest();
}

}

This is my Calloutclass which has 100% coverage:
public class fxolaf2_fetchINavURLsCallout {
public static HttpResponse doCallout(String iNavUrl, String docName) {
    HttpRequest req = new HttpRequest();
    req.setEndpoint(iNavUrl);
    req.setMethod('GET');
    Http h = new Http();
    HttpResponse res = h.send(req);
    return res;
}
}

This is the real class that needs coverage:
global class fxolaf2_FetchINavDocuments {
     public static void postOrder(){

    string INavDocument =' ';      
    List<fxolaf2_iNav_URLs__c> iNavURLsList = [select Name, Header_URL__c, Footer_URL__c from fxolaf2_iNav_URLs__c limit 2];
    fxolaf2_iNav_URLs__c temp = new fxolaf2_iNav_URLs__c();

    if(iNavURLsList != null) {
        for(Integer i = 0; i < iNavURLsList.size(); i++) {
            temp = iNavURLsList.get(i);
            system.debug('iNavURLList' +  i + temp );
            //Fetching header and attching the doc
            if(temp.Header_URL__c != null) {
                attachINavDocuments(temp.Header_URL__c,'iNav_'+temp.Name + '_'+'Header');
                INavDocument = 'iNav_'+temp.Name + '_'+'Header';
            }
            //Fetching footer and attching to document
            if(temp.Footer_URL__c != null) {
                attachINavDocuments(temp.Footer_URL__c,'iNav_'+temp.Name + '_'+'Footer');
                INavDocument = 'iNav_'+temp.Name + '_'+'Footer';
            }

        }    
    }

}
@future(callout = true)
public static void attachINavDocuments(String iNavUrl, String docName) {

    HTTPREsponse res = fxolaf2_fetchINavURLsCallout.doCallOut(iNavUrl, docName);

    //If success

    if(res.getStatusCode()==200){
        Document d = new Document();
        d.Name = docName;
        d.ContentType = 'text/html';
        d.Type='html';

        Folder[] folders = [select id from Folder where name='fxolaf2_iNav_documents'];//Folder into which the documents should be stored
        if(folders != null && folders.size() > 0) {
            d.FolderId = folders[0].id;  
            d.Body = res.getBodyAsBlob();
            List<Document> iNavDocNameList = [select Name,ID from Document where Name =: d.Name];
            //If already present update the doc
            if(iNavDocNameList != null && iNavDocNameList.size() > 0) {
                Document tempDoc = new Document();
                tempDoc = iNavDocNameList.get(0);
                d.ID = tempDoc.ID;
                update d;

            } else {
                //Insert the doc
                insert d;

            }               
        } else {
            //Create the folder   
        }
    }

}

Here is the Mock response Class:
@isTest
global class fxolaf2_fetchInavURLsMock implements HttpCalloutMock  {
global HTTPResponse respond(HTTPRequest req){
    // Create a fake response
    HttpResponse res = new HttpResponse();
    res.setBody('Test Body');
    res.setStatusCode(200);        
    return res;
}
}