• clstanton007
  • NEWBIE
  • 25 Points
  • Member since 2010

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies

I am relatively new to web services, but not new to Apex/SFDC.  I was looking for some resources on how to call the USPS web service and populate city and state when a user enters a zip code, and populate the city and state in "real time".  Is this possible?  Any info would be greatly appreciated!

Hello,

 

I have written a few test classes for triggers and such, but am having difficulty with my test class for controller extension.  This is how the app works:  There is a VF page with 4 picklists, at least one is required.  Then user presses the Search button, and the extension performs the search (using the values of the picklists in the SOQL). 

 

Here's the code for the class:

 

 

public with sharing class BuyerSupplier {
         
    private ApexPages.StandardController controller {get; set;}
    public List<Buyer__c> searchResults {get;set;}
    public string searchText {get;set;}
  
    public String site {get; set;}
    public String region {get;set;}
    public String division {get;set;}
    public String category {get;set;}
    //public String hiddenSite {get; set;}
    
    public Boolean needsAnd;
 
    // standard controller
    public BuyerSupplier(ApexPages.StandardController controller) {  }
 
    // fired when the search button is clicked
    public PageReference search() {
        
        needsAnd = false;
        
        site = ApexPages.currentPage().getParameters().get('hiddenSite');
        region = ApexPages.currentPage().getParameters().get('hiddenRegion');
        division = ApexPages.currentPage().getParameters().get('hiddenDivision');
        category = ApexPages.currentPage().getParameters().get('hiddenCategory');
        
        //FOR SOME REASON, VALUES OF PICKLISTS ARE COMING OVER AS "__".  IF THAT HAPPENS, REMOVE THEM.
        if(site == '__') site = '';
        if(region == '__') region = '';
        if(division == '__') division = '';
        if(category == '__') category = '';

        
        //FIRST CHECK TO SEE IF AT LEAST ONE FIELD IS COMPLETED
        if((site == '' || site == '__') && (region == '' || region == '__') && (division == '' || division == '__') && (category == '' || category == '')) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please make a selection for at least ONE of the fields below.'));
            return null;
        }        
        
        String qry = 'select Buyer__c, Buyer_Email__c, Category__c, Division__c, Region__c, Supplier__c, Site__c, Supplier_URL__c from Buyer__c where ';
        
        if(site != '') {
            if (needsAnd == true) {
                qry = qry + 'and Site__c = \'' + site + '\' ' ;
            }
            
            else {
                qry = qry + 'Site__c = \'' + site + '\' ' ;
                needsAnd = true;
            }
        }
    
        if(region != '') {
            if (needsAnd == true) {
                qry = qry + 'and Region__c = \'' + region + '\' ' ;
            }
            
            else {
                qry = qry + 'Region__c = \'' + region + '\' ' ;
                needsAnd = true;
            }
        }
        
        if(division != '') {
            if (needsAnd == true) {
                qry = qry + 'and Division__c = \'' + division + '\' ';
            }
            
            else {
                qry = qry + 'Division__c = \'' + division + '\' ' ;
                needsAnd = true;
            }
        }
        
        if(category != '') {
            if (needsAnd == true) {
                qry = qry + 'and Category__c = \'' + category + '\' ' ;
            }
            
            else {
                qry = qry + 'Category__c = \'' + category + '\' ' ;
                needsAnd = true;
            }
        }
    
        qry = qry + ' order by Site__c, Region__c, Division__c, Category__c Limit 1000';
        
        searchResults = Database.query(qry);
        return null;
  }
}

 

 

Then here is the code for the Test Class so far.  I get the following error:  Error: Compile Error: Invalid type: BuyerSupplierExt at line 71 column 42.

 

@isTest
private class BuyerSupplier_Test {

        private Buyer__c buyer;  
        
        static testmethod void testSearchBuyers(){
        
            // Create dummy data for test purposes.
            Buyer__c b = new Buyer__c(
                Region__c = 'Americas',
                Site__c = 'Rochester',
                Division__c = 'Vision Care',
                Category__c = 'Advertising',
                Buyer__c = 'Test Buyer',
                Supplier__c = 'Test Supplier');
            
            System.debug('******************Inserting the test buyer record...');
            insert b;
            
            ApexPages.StandardSetController controller = new ApexPages.StandardSetController(b); 
            BuyerSupplierExt bsExt = new BuyerSupplierExt(controller);
    
            //Call controller.search() and assert the list contains the expected records.
            List<Buyer__c> results = bsExt.search();
            //List<Buyer__c> results = [select Region__c, Site__c, Division__c, Category__c, Buyer__c from Buyer__c where Site__c = 'Rochester' and Division__c = 'Vision Care' and Category__c = 'Advertising'];
            
            system.assertEquals(results.size(),1);
    
        }           
}

 

Any help would be appreciated!!

 

Thanks!

All,

 

Having some difficulty with what I think should be pretty simple.  I am putting together a no-frills survey, so I have a parent Survey__c object, a child Survey_Question__c object, and a child Survey_Resonse__c object.  In Survey_Question__c, there is a picklist field (Question_Field_Type__c) that determines what widget should be used for the answer to that question (text box, textarea, picklist, etc.)  Then there is a textarea field (called Question_HTML__c) that stores the HTML that should be renedered for each question, based on the field type.  For example, if the field type is "text box", then the Question_HTML__c would be "<input type="text" id="123"/>

 

Everything seems to be kind of working, except that I can't get the HTML content to render as HTML.  It just gets output as text.  Can anyone be of assistance??

 

Thanks in advance.

Craig

Hello,

 

I have written a few test classes for triggers and such, but am having difficulty with my test class for controller extension.  This is how the app works:  There is a VF page with 4 picklists, at least one is required.  Then user presses the Search button, and the extension performs the search (using the values of the picklists in the SOQL). 

 

Here's the code for the class:

 

 

public with sharing class BuyerSupplier {
         
    private ApexPages.StandardController controller {get; set;}
    public List<Buyer__c> searchResults {get;set;}
    public string searchText {get;set;}
  
    public String site {get; set;}
    public String region {get;set;}
    public String division {get;set;}
    public String category {get;set;}
    //public String hiddenSite {get; set;}
    
    public Boolean needsAnd;
 
    // standard controller
    public BuyerSupplier(ApexPages.StandardController controller) {  }
 
    // fired when the search button is clicked
    public PageReference search() {
        
        needsAnd = false;
        
        site = ApexPages.currentPage().getParameters().get('hiddenSite');
        region = ApexPages.currentPage().getParameters().get('hiddenRegion');
        division = ApexPages.currentPage().getParameters().get('hiddenDivision');
        category = ApexPages.currentPage().getParameters().get('hiddenCategory');
        
        //FOR SOME REASON, VALUES OF PICKLISTS ARE COMING OVER AS "__".  IF THAT HAPPENS, REMOVE THEM.
        if(site == '__') site = '';
        if(region == '__') region = '';
        if(division == '__') division = '';
        if(category == '__') category = '';

        
        //FIRST CHECK TO SEE IF AT LEAST ONE FIELD IS COMPLETED
        if((site == '' || site == '__') && (region == '' || region == '__') && (division == '' || division == '__') && (category == '' || category == '')) {
            ApexPages.addmessage(new ApexPages.message(ApexPages.severity.FATAL,'Please make a selection for at least ONE of the fields below.'));
            return null;
        }        
        
        String qry = 'select Buyer__c, Buyer_Email__c, Category__c, Division__c, Region__c, Supplier__c, Site__c, Supplier_URL__c from Buyer__c where ';
        
        if(site != '') {
            if (needsAnd == true) {
                qry = qry + 'and Site__c = \'' + site + '\' ' ;
            }
            
            else {
                qry = qry + 'Site__c = \'' + site + '\' ' ;
                needsAnd = true;
            }
        }
    
        if(region != '') {
            if (needsAnd == true) {
                qry = qry + 'and Region__c = \'' + region + '\' ' ;
            }
            
            else {
                qry = qry + 'Region__c = \'' + region + '\' ' ;
                needsAnd = true;
            }
        }
        
        if(division != '') {
            if (needsAnd == true) {
                qry = qry + 'and Division__c = \'' + division + '\' ';
            }
            
            else {
                qry = qry + 'Division__c = \'' + division + '\' ' ;
                needsAnd = true;
            }
        }
        
        if(category != '') {
            if (needsAnd == true) {
                qry = qry + 'and Category__c = \'' + category + '\' ' ;
            }
            
            else {
                qry = qry + 'Category__c = \'' + category + '\' ' ;
                needsAnd = true;
            }
        }
    
        qry = qry + ' order by Site__c, Region__c, Division__c, Category__c Limit 1000';
        
        searchResults = Database.query(qry);
        return null;
  }
}

 

 

Then here is the code for the Test Class so far.  I get the following error:  Error: Compile Error: Invalid type: BuyerSupplierExt at line 71 column 42.

 

@isTest
private class BuyerSupplier_Test {

        private Buyer__c buyer;  
        
        static testmethod void testSearchBuyers(){
        
            // Create dummy data for test purposes.
            Buyer__c b = new Buyer__c(
                Region__c = 'Americas',
                Site__c = 'Rochester',
                Division__c = 'Vision Care',
                Category__c = 'Advertising',
                Buyer__c = 'Test Buyer',
                Supplier__c = 'Test Supplier');
            
            System.debug('******************Inserting the test buyer record...');
            insert b;
            
            ApexPages.StandardSetController controller = new ApexPages.StandardSetController(b); 
            BuyerSupplierExt bsExt = new BuyerSupplierExt(controller);
    
            //Call controller.search() and assert the list contains the expected records.
            List<Buyer__c> results = bsExt.search();
            //List<Buyer__c> results = [select Region__c, Site__c, Division__c, Category__c, Buyer__c from Buyer__c where Site__c = 'Rochester' and Division__c = 'Vision Care' and Category__c = 'Advertising'];
            
            system.assertEquals(results.size(),1);
    
        }           
}

 

Any help would be appreciated!!

 

Thanks!

All,

 

Having some difficulty with what I think should be pretty simple.  I am putting together a no-frills survey, so I have a parent Survey__c object, a child Survey_Question__c object, and a child Survey_Resonse__c object.  In Survey_Question__c, there is a picklist field (Question_Field_Type__c) that determines what widget should be used for the answer to that question (text box, textarea, picklist, etc.)  Then there is a textarea field (called Question_HTML__c) that stores the HTML that should be renedered for each question, based on the field type.  For example, if the field type is "text box", then the Question_HTML__c would be "<input type="text" id="123"/>

 

Everything seems to be kind of working, except that I can't get the HTML content to render as HTML.  It just gets output as text.  Can anyone be of assistance??

 

Thanks in advance.

Craig

I was looking for a way to populate a Contact's city and state based on a zip code. Basically, when I enter a zip code and save the record, I would like the state and city fields to be updated with the appropriate information. I am not sure if it would be easiest to use a web service, API, or trigger. I would rather not build this "table" myself since it would be a bear to maintain. I thought there would be some sort of web service that you could use in conjunction with a formula "state" field that would take the zip, look up the state, and populate that state formula field.
Has anyone else done this?
Thanks, Jeff