• bdbagley
  • NEWBIE
  • 25 Points
  • Member since 2013

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

As I've seen on here a couple times, I'm trying to do an HTTP request and grab the xml data returned from google.  However, I've hit a wall while reading up on these things (I've been teaching myself coding for about 3 weeks now so sorry if this is a simple matter).  I think I have my HTTP request working and I'm attempting to grab the entire XML document and list it in a text box while also specifically grabbing the Longitude and Lattitude.  My overall goal is to type in a city and state but I want to just get it working before I dive into that (that's why it is commented out).  Honestly I think I'm on the right track buy having difficulty transcribing the info into a visualforce page.  Here's my attempted code:

 

public class interview6 {

    public String city {get;set;}
    public String state {get;set;}
    
public void Coordinates()
{
            Http http = new Http();
            HttpRequest req = new HttpRequest();
            String url = 'http://maps.googleapis.com/maps/api/geocode/xml?address=Kennesaw,+GA&sensor=false';
            // generate the url for the request
            //String url = 'http://maps.google.com/maps/api/geocode/xml?address='+ EncodingUtil.urlEncode(city,'UTF-8')+',+'
                //+ EncodingUtil.urlEncode(state,'UTF-8')
               // +'&sensor=false';
            // set the method
            req.setMethod('GET');
            // add the endpoint to the request
            req.setEndpoint(url);
HttpResponse res = http.send(req);
string responseBody = res.getBody().replace('\n','');
 string longitude;
 string latitude;
dom.Document doc = res.getBodyDocument();
//geometry
dom.XmlNode location = doc.getRootElement().getChildElement('result',null).getChildElement('geometry',null).getChildElement('location',null);         

longitude = location.getChildElement('lng', null).getText();
latitude = location.getChildElement('lat', null).getText();

    }

}

 

<apex:page controller="interview6">
  <apex:sectionHeader title="Interview Six"/>
    <apex:form >
        <apex:pageBlock >
          <apex:pageBlockSection title="Input" Columns="1">
            <apex:pageBlockSectionItem >
                  <apex:outputLabel for="City">City</apex:outputLabel>
               <apex:panelGroup >
                  <apex:inputText id="City" value="{!city}"/>
               </apex:panelGroup>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                 <apex:outputLabel for="State">State</apex:outputLabel>
               <apex:panelGroup >
                 <apex:inputText id="State" value="{!State}"/>
               </apex:panelGroup>
            </apex:pageBlockSectionItem>
         </apex:pageBlockSection>
         
         <apex:pageblockSection title="Output" Columns="1">
            <apex:pageBlockSectionItem >
                  <apex:outputLabel for="HTTP Response">HTTP Response</apex:outputLabel>
               <apex:panelGroup >
                  <apex:InputTextarea Cols="40" rows="20" />
               </apex:panelGroup>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                  <apex:outputLabel for="Lattitude">Lattitude</apex:outputLabel>
               <apex:panelGroup >
                  <apex:InputText id="Lattitude" />
               </apex:panelGroup>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                 <apex:outputLabel for="Longitude">Longitude</apex:outputLabel>
               <apex:panelGroup >
                 <apex:InputText id="Longitude" />
               </apex:panelGroup>
            </apex:pageBlockSectionItem>
         </apex:pageBlockSection>                 
       </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

Again I'm sure there are some issues with the above sample, but if I could just get some help with displaying the entire code in the text box I feel I could work from there without much issue.  Thanks for taking the time to look.

So I've been playing around with selectRadio but I'm having trouble getting a page message to render on the selection of an account.  My original thought was to take a wrapper class and convert it into radio buttons instead of a pick list like others on this site, but I can't seem to get the right setup.  I then decided I would try and use a command link and param tag and see if it was possible to just add a selectradio component.  Needless to say I am completely new to this and I am using borrowed code and tutorials to teach myself this. From what I've read and understand at this point I believe I need to create an action function for the radio that changes the page message, but honestly I can't figue this out. Below is my code where the actual account names return a message, should I scrap this approach and try the wrapper class again?

 

<apex:page title="radiotest" controller="radiotest" sidebar="false">

  <apex:form >
 
      <apex:pageBlock title="Interview Five" id="Test">
         <apex:pageMessages > </apex:pageMessages>
        
          <apex:pageBlockTable value="{!Data}" var="acc">
            <apex:column >
                <apex:commandLink value="{!acc.name}" action="{!Calling}" reRender="Test">
                    <apex:param name="Txt" value="{!acc.id}"/>
                </apex:commandLink>
            </apex:column>
            <apex:column value="{!acc.Name}"/>
            <apex:column value="{!acc.BillingState}"/>
            <apex:column value="{!acc.Phone}"/>
            <apex:column value="{!acc.Website}"/>
        
          </apex:pageBlockTable>
      
      </apex:pageBlock>
  </apex:form>
 
</apex:page>

 

public class radiotest {
    public radiotest(){
 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,' Select an Account by Clicking its name.'));
 }
    List<Account> Varacc;
    public List<Account> getData()
    {
        string str1=Apexpages.currentpage().getParameters().get('id');
        Varacc =[Select id,Name,BillingState,Phone,Website from Account];      
        if(varacc.size()>0)
        {
            return Varacc;
        }
        return null;
    }
    public void Calling() {
        string str1=Apexpages.currentpage().getParameters().get('txt');
        Account varacc=[select id,name from Account where id=:str1];
        String ex=varacc.name;
        {
             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,' You have Selected the '+varacc.name+' Account'));
        }
    }   
}

 Any help appreciated as I feel like I've exhausted all the reading material on the subjest but can't grasp it.

I am completeley new to apex and coding in general so I was hoping I could get some help with a question.  I'm attempting to teach myself as much as I can by manipulating examples Wrapper Example so here we go.  I'm looking to do what I believe should be fairly simple: Take a list of accounts, from a wrapper class, that are selectable and then simply relist those selected in another column.

 

public class WrapperclassController {

    //Our collection of the class/wrapper objects cContact 
    public List<aAccount> AccountList {get; set;}

    //This method uses a simple SOQL query to return a List of Contacts
    public List<aAccount> getAccounts() {
        if(AccountList == null) {
            AccountList = new List<aAccount>();
            for(Account a: [select Id, Name, Phone from Account Order by Name]) {
                // As each contact is processed we create a new cContact object and add it to the contactList
                AccountList.add(new aAccount(a));
            }
        }
        return AccountList;
    }


    public PageReference processSelected() {

                //We create a new list of Contacts that we be populated only with Contacts if they are selected
        List<Account> selectedAccounts = new List<Account>();

        //We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list
        for(aAccount aAcc: getAccounts()) {
            if(aAcc.selected == true) {
                selectedAccounts.add(aAcc.acc);
            }
        }

        // Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
        System.debug('These are the selected Contacts...');
        for(Account acc: selectedAccounts) {
            system.debug(acc);
        }
        return null;
    }


    // This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
    public class aAccount {
        public Account acc {get; set;}
        public Boolean selected {get; set;}

        //This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
        public aAccount(Account a) {
            acc = a;
            selected = false;
        }
    }
}

 

<apex:page controller="WrapperclassController">
  <apex:sectionHeader title="Interview Three"/>
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Show Selected Accounts" action="{!processSelected}" rerender="table"/>
            </apex:pageBlockButtons>
            <!-- In our table we are displaying the cContact records -->
        <apex:pageBlockSection title="All Accounts">
            <apex:pageBlockTable value="{!Accounts}" var="a" id="table">
                <apex:column >
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:inputCheckbox value="{!a.selected}"/>
                </apex:column>
                <!-- This is how we access the contact values within our cContact container/wrapper -->
                <apex:column value="{!a.acc.Name}" />
                <apex:column value="{!a.acc.Phone}" />
            </apex:pageBlockTable>
          </apex:pageBlockSection>
          
       <apex:pageBlockSection title="Selected Accounts">

        </apex:pageblocksection>
        
        </apex:pageBlock>
    </apex:form>
</apex:page>

So what I believe still needs to be done is possibly an action statement that takes the selected accounts withing the wrapper list and relists them in a new column on the visual force page but I am having trouble putting it together without errors.  I'd like the seleced accounts to be beside not below all accounts as well.

 

Any help would be appreciated as I am literally just getting into apex and coding as of about 3 weeks ago.

 

 

 

As I've seen on here a couple times, I'm trying to do an HTTP request and grab the xml data returned from google.  However, I've hit a wall while reading up on these things (I've been teaching myself coding for about 3 weeks now so sorry if this is a simple matter).  I think I have my HTTP request working and I'm attempting to grab the entire XML document and list it in a text box while also specifically grabbing the Longitude and Lattitude.  My overall goal is to type in a city and state but I want to just get it working before I dive into that (that's why it is commented out).  Honestly I think I'm on the right track buy having difficulty transcribing the info into a visualforce page.  Here's my attempted code:

 

public class interview6 {

    public String city {get;set;}
    public String state {get;set;}
    
public void Coordinates()
{
            Http http = new Http();
            HttpRequest req = new HttpRequest();
            String url = 'http://maps.googleapis.com/maps/api/geocode/xml?address=Kennesaw,+GA&sensor=false';
            // generate the url for the request
            //String url = 'http://maps.google.com/maps/api/geocode/xml?address='+ EncodingUtil.urlEncode(city,'UTF-8')+',+'
                //+ EncodingUtil.urlEncode(state,'UTF-8')
               // +'&sensor=false';
            // set the method
            req.setMethod('GET');
            // add the endpoint to the request
            req.setEndpoint(url);
HttpResponse res = http.send(req);
string responseBody = res.getBody().replace('\n','');
 string longitude;
 string latitude;
dom.Document doc = res.getBodyDocument();
//geometry
dom.XmlNode location = doc.getRootElement().getChildElement('result',null).getChildElement('geometry',null).getChildElement('location',null);         

longitude = location.getChildElement('lng', null).getText();
latitude = location.getChildElement('lat', null).getText();

    }

}

 

<apex:page controller="interview6">
  <apex:sectionHeader title="Interview Six"/>
    <apex:form >
        <apex:pageBlock >
          <apex:pageBlockSection title="Input" Columns="1">
            <apex:pageBlockSectionItem >
                  <apex:outputLabel for="City">City</apex:outputLabel>
               <apex:panelGroup >
                  <apex:inputText id="City" value="{!city}"/>
               </apex:panelGroup>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                 <apex:outputLabel for="State">State</apex:outputLabel>
               <apex:panelGroup >
                 <apex:inputText id="State" value="{!State}"/>
               </apex:panelGroup>
            </apex:pageBlockSectionItem>
         </apex:pageBlockSection>
         
         <apex:pageblockSection title="Output" Columns="1">
            <apex:pageBlockSectionItem >
                  <apex:outputLabel for="HTTP Response">HTTP Response</apex:outputLabel>
               <apex:panelGroup >
                  <apex:InputTextarea Cols="40" rows="20" />
               </apex:panelGroup>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                  <apex:outputLabel for="Lattitude">Lattitude</apex:outputLabel>
               <apex:panelGroup >
                  <apex:InputText id="Lattitude" />
               </apex:panelGroup>
            </apex:pageBlockSectionItem>
            <apex:pageBlockSectionItem >
                 <apex:outputLabel for="Longitude">Longitude</apex:outputLabel>
               <apex:panelGroup >
                 <apex:InputText id="Longitude" />
               </apex:panelGroup>
            </apex:pageBlockSectionItem>
         </apex:pageBlockSection>                 
       </apex:pageBlock>
    </apex:form>
</apex:page>

 

 

Again I'm sure there are some issues with the above sample, but if I could just get some help with displaying the entire code in the text box I feel I could work from there without much issue.  Thanks for taking the time to look.

So I've been playing around with selectRadio but I'm having trouble getting a page message to render on the selection of an account.  My original thought was to take a wrapper class and convert it into radio buttons instead of a pick list like others on this site, but I can't seem to get the right setup.  I then decided I would try and use a command link and param tag and see if it was possible to just add a selectradio component.  Needless to say I am completely new to this and I am using borrowed code and tutorials to teach myself this. From what I've read and understand at this point I believe I need to create an action function for the radio that changes the page message, but honestly I can't figue this out. Below is my code where the actual account names return a message, should I scrap this approach and try the wrapper class again?

 

<apex:page title="radiotest" controller="radiotest" sidebar="false">

  <apex:form >
 
      <apex:pageBlock title="Interview Five" id="Test">
         <apex:pageMessages > </apex:pageMessages>
        
          <apex:pageBlockTable value="{!Data}" var="acc">
            <apex:column >
                <apex:commandLink value="{!acc.name}" action="{!Calling}" reRender="Test">
                    <apex:param name="Txt" value="{!acc.id}"/>
                </apex:commandLink>
            </apex:column>
            <apex:column value="{!acc.Name}"/>
            <apex:column value="{!acc.BillingState}"/>
            <apex:column value="{!acc.Phone}"/>
            <apex:column value="{!acc.Website}"/>
        
          </apex:pageBlockTable>
      
      </apex:pageBlock>
  </apex:form>
 
</apex:page>

 

public class radiotest {
    public radiotest(){
 ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,' Select an Account by Clicking its name.'));
 }
    List<Account> Varacc;
    public List<Account> getData()
    {
        string str1=Apexpages.currentpage().getParameters().get('id');
        Varacc =[Select id,Name,BillingState,Phone,Website from Account];      
        if(varacc.size()>0)
        {
            return Varacc;
        }
        return null;
    }
    public void Calling() {
        string str1=Apexpages.currentpage().getParameters().get('txt');
        Account varacc=[select id,name from Account where id=:str1];
        String ex=varacc.name;
        {
             ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO,' You have Selected the '+varacc.name+' Account'));
        }
    }   
}

 Any help appreciated as I feel like I've exhausted all the reading material on the subjest but can't grasp it.

I am completeley new to apex and coding in general so I was hoping I could get some help with a question.  I'm attempting to teach myself as much as I can by manipulating examples Wrapper Example so here we go.  I'm looking to do what I believe should be fairly simple: Take a list of accounts, from a wrapper class, that are selectable and then simply relist those selected in another column.

 

public class WrapperclassController {

    //Our collection of the class/wrapper objects cContact 
    public List<aAccount> AccountList {get; set;}

    //This method uses a simple SOQL query to return a List of Contacts
    public List<aAccount> getAccounts() {
        if(AccountList == null) {
            AccountList = new List<aAccount>();
            for(Account a: [select Id, Name, Phone from Account Order by Name]) {
                // As each contact is processed we create a new cContact object and add it to the contactList
                AccountList.add(new aAccount(a));
            }
        }
        return AccountList;
    }


    public PageReference processSelected() {

                //We create a new list of Contacts that we be populated only with Contacts if they are selected
        List<Account> selectedAccounts = new List<Account>();

        //We will cycle through our list of cContacts and will check to see if the selected property is set to true, if it is we add the Contact to the selectedContacts list
        for(aAccount aAcc: getAccounts()) {
            if(aAcc.selected == true) {
                selectedAccounts.add(aAcc.acc);
            }
        }

        // Now we have our list of selected contacts and can perform any type of logic we want, sending emails, updating a field on the Contact, etc
        System.debug('These are the selected Contacts...');
        for(Account acc: selectedAccounts) {
            system.debug(acc);
        }
        return null;
    }


    // This is our wrapper/container class. A container class is a class, a data structure, or an abstract data type whose instances are collections of other objects. In this example a wrapper class contains both the standard salesforce object Contact and a Boolean value
    public class aAccount {
        public Account acc {get; set;}
        public Boolean selected {get; set;}

        //This is the contructor method. When we create a new cContact object we pass a Contact that is set to the con property. We also set the selected value to false
        public aAccount(Account a) {
            acc = a;
            selected = false;
        }
    }
}

 

<apex:page controller="WrapperclassController">
  <apex:sectionHeader title="Interview Three"/>
    <apex:form >
        <apex:pageBlock >
            <apex:pageBlockButtons >
                <apex:commandButton value="Show Selected Accounts" action="{!processSelected}" rerender="table"/>
            </apex:pageBlockButtons>
            <!-- In our table we are displaying the cContact records -->
        <apex:pageBlockSection title="All Accounts">
            <apex:pageBlockTable value="{!Accounts}" var="a" id="table">
                <apex:column >
                    <!-- This is our selected Boolean property in our wrapper class -->
                    <apex:inputCheckbox value="{!a.selected}"/>
                </apex:column>
                <!-- This is how we access the contact values within our cContact container/wrapper -->
                <apex:column value="{!a.acc.Name}" />
                <apex:column value="{!a.acc.Phone}" />
            </apex:pageBlockTable>
          </apex:pageBlockSection>
          
       <apex:pageBlockSection title="Selected Accounts">

        </apex:pageblocksection>
        
        </apex:pageBlock>
    </apex:form>
</apex:page>

So what I believe still needs to be done is possibly an action statement that takes the selected accounts withing the wrapper list and relists them in a new column on the visual force page but I am having trouble putting it together without errors.  I'd like the seleced accounts to be beside not below all accounts as well.

 

Any help would be appreciated as I am literally just getting into apex and coding as of about 3 weeks ago.