• Kyle Buzza
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 2
    Replies
I'm using an aura:iteration component to display a list of items in a lightning component. I'd like to only show a maximum of 5 list items at a time with a scrollbar to access the rest, but I can't figure out how to add a scrollbar to the component.
 
<aura:component controller="geolocationAccountController">
    <aura:registerEvent name="accountsLoaded" type="c:geoAccountsLoaded"/>
    <aura:attribute name="accounts" type="Account[]"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    
    <aura:iteration items="{!v.accounts}" var="account">
        <c:geoAccountListItem account="{!account}"/>
    </aura:iteration>
</aura:component>

 
Hi, I'm using an apex class to connect to an external API, but the test class I wrote only covers 62%. How exactly would I write test classes to cover the http callouts in my code.

Here's the original code:
public class AccountGeocodeAddress {
	private static Boolean geocodingCalled = false;
	public static void DoAddressGeocode(id accountId) {
        if(geocodingCalled || System.isFuture()) {
    		System.debug(LoggingLevel.WARN,'***Address Geocoding Future Method Already Called - Aborting...');
    		return;
        }
		
        geocodingCalled = true;
		geocodeAddress(accountId);
	}
    

	@future (callout=true)
	static private void geocodeAddress(id accountId){ 
  		// Key for Google Maps Geocoding API
  		String geocodingKey = 'XXXXXXXXXXXXXXXXXXXXXXXXX';
  		// get the passed in address
  		Account geoAccount = [SELECT BillingStreet, BillingCity, BillingState, BillingCountry, BillingPostalCode FROM Account WHERE id = :accountId];
    
  		// check that we have enough information to geocode the address
		if((geoAccount.BillingStreet == null) || (geoAccount.BillingCity == null)) {
    		System.debug(LoggingLevel.WARN, 'Insufficient Data to Geocode Address');
    		return;
  		}
  		// create a string for the address to pass to Google Geocoding API
  		String geoAddress = '';
        if(geoAccount.BillingStreet != null){
            geoAddress += geoAccount.BillingStreet + ', ';
        }
        if(geoAccount.BillingCity != null){
    		geoAddress += geoAccount.BillingCity + ', ';
        }
        if(geoAccount.BillingState != null){
    		geoAddress += geoAccount.BillingState + ', ';
        }
        if(geoAccount.BillingCountry != null){
    		geoAddress += geoAccount.BillingCountry + ', ';
        }
        if(geoAccount.BillingPostalCode != null){
    		geoAddress += geoAccount.BillingPostalCode;
        }
  
  		// encode the string so we can pass it as part of URL
  		geoAddress = EncodingUtil.urlEncode(geoAddress, 'UTF-8');
  		// build and make the callout to the Geocoding API
  		Http http = new Http();
  		HttpRequest request = new HttpRequest();
  		request.setEndpoint('https://maps.googleapis.com/maps/api/geocode/json?address=' + geoAddress + '&key=' + geocodingKey + '&sensor=false');
  		request.setMethod('GET');
  		request.setTimeout(60000);
  		try {
    		// make the http callout
    		HttpResponse response = http.send(request);
    		// parse JSON to extract co-ordinates
    		JSONParser responseParser = JSON.createParser(response.getBody());
    		// initialize co-ordinates
    		double latitude = null;
    		double longitude = null;
    		while(responseParser.nextToken() != null) {
      			if((responseParser.getCurrentToken() == JSONToken.FIELD_NAME) && (responseParser.getText() == 'location')) {
        			responseParser.nextToken();
        			while(responseParser.nextToken() != JSONToken.END_OBJECT) {         
						String locationText = responseParser.getText();
						responseParser.nextToken();
                        if (locationText == 'lat'){
           					latitude = responseParser.getDoubleValue();
                        } else if (locationText == 'lng'){
           					longitude = responseParser.getDoubleValue();
                        }
        			}
      			}
    		}
    		// update co-ordinates on address if we get them back
    		if(latitude != null) {
      			geoAccount.Location__Latitude__s = latitude;
      			geoAccount.Location__Longitude__s = longitude;
                System.debug('well we got here');
      			update geoAccount;
    		}
  		} catch (Exception e) {
    		System.debug(LoggingLevel.ERROR, 'Error Geocoding Address - ' + e.getMessage());
  		}
	}
}

and here's my current test class:
@isTest
public class geocodeAccountAddressTest {
    private static testmethod void geocodeTest1(){
        Account acc = new Account();
        acc.Name = 'testName';
        acc.Last_Name__c = 'LastName';
        acc.Email__c = 'acc@acc.com';
        acc.User_ID__c = 900;
        insert acc;
        
        acc.BillingStreet = '1111 Name Street';
        update acc;
        acc.BillingCity = 'Test City';
        acc.BillingState = 'PA';
        acc.BillingCountry = 'US';
        acc.BillingPostalCode = '15108';
        update acc;
    }
}

Thanks
I have a VF page that inserts a related event using a custom controller extension. I'm trying to call another controller function that will return the created event Id. I'm testing the function using an alert, but for some reason it just alerts "false" and not the event Id.
<apex:page id="pg" standardController="Contact" extensions="JoinMeContactController">
    <script>
		function openPage (){
            alert(GettingEvent());
            var win = window.open('https://www.join.me', '_blank');
            win.focus();
		}
	</script>
    
    <apex:form >
        <apex:actionFunction name="GettingEvent" action="{! getEvent}" />
        <apex:commandbutton image="{!URLFOR($Resource.JoinMeLogo)}" style="width:125px; height:125px; background:black; margin:0" onClick="openPage()" action="{! newEvent}"/>        
    </apex:form>
    	
</apex:page>
 
public with sharing class JoinMeContactController {

    public Contact c{get;set;}
    public Event e;
    private final ApexPages.StandardController controller;
	
    public JoinMeContactController(ApexPages.StandardController controller) {
        this.controller = controller;
        c = new Contact();
        c = [select id from Contact where Id=: ApexPages.currentPage().getParameters().get('Id')];
    }
    
    public void newEvent(){
        e = new Event();
        e.WhoId = c.Id;
        e.Subject = 'Join.me Meeting';
        e.ActivityDateTime = DateTime.now();
        e.DurationInMinutes = 30;
        e.JoinmeV2__Join_Me_Activity__c = true;
        e.JoinmeV2__Meeting_Code__c = 'thewealthpool';

        insert e;
    }
    
    public String getEvent(){
        return e.Id;
    }
}

 
Hello,

I'm using a custom visualforce button that will create a related event record upon clicking it. Is there a way to open the edit page on this created event after it is created?

Here is the code:
<apex:page id="pg" standardController="Contact" extensions="JoinMeContactController">
    <script>
		function openPage (){
            var win = window.open('https://www.join.me', '_blank');
            win.focus();
		}
	</script>
    
    <apex:form >
        <apex:commandbutton image="{!URLFOR($Resource.JoinMeLogo)}" style="width:125px; height:125px; background:black; margin:0" onClick="openPage()" action="{! newEvent}"/>        
    </apex:form>
    	
</apex:page>
 
public with sharing class JoinMeContactController {

    public Contact c{get;set;}
    private final ApexPages.StandardController controller;
	
    public JoinMeContactController(ApexPages.StandardController controller) {
        this.controller = controller;
        c = new Contact();
        c = [select id from Contact where Id=: ApexPages.currentPage().getParameters().get('Id')];
    }
    
    public void newEvent(){
        Event e = new Event();
        e.WhoId = c.Id;
        e.Subject = 'Join.me Meeting';
        e.ActivityDateTime = DateTime.now();
        e.DurationInMinutes = 30;
        e.JoinmeV2__Join_Me_Activity__c = true;
        e.JoinmeV2__Meeting_Code__c = 'thewealthpool';

        insert e;
    }
}

 
I'm trying to both open a link and create a new event on the click of a custom button on the contact object. I'm able to open the link, but when I uncomment the line,
sforce.connection.create([e]);
it breaks the code and neither inserts the new event nor opens the link. I'm not sure what I'm missing. Any help would be appreciated.

Here is my full code:
<apex:page id="pg" standardController="Contact">
    <script>
		function openPage (){
            var e = new sforce.SObject("Event");
            e.Subject = "Join.me Meeting w/ " + "{! Contact.FirstName}" + " " + "{! Contact.LastName}";
            e.ActivityDate = "{! NOW()}";
            e.DurationInMinutes = 30;
            e.WhoId = "{! Contact.Id}";
            e.JoinmeV2__Join_Me_Activity__c = true;
        	e.JoinmeV2__Meeting_Code__c = "thewealthpool";
            
            //sforce.connection.create([e]);
            
            var win = window.open('https://www.join.me', '_blank');
            win.focus();            
        }

	</script>

    
    <apex:form >
        <apex:includeScript value="/soap/ajax/33.0/connection.js"/>
		<apex:includeScript value="/soap/ajax/33.0/apex.js"/>
        <apex:commandbutton image="{!URLFOR($Resource.JoinMeLogo)}" onClick="openPage()"/>
    </apex:form>
    	
</apex:page>


 
I'm trying to create a visualforce page on the contact that will first insert a related event and then open up a web page. For some reason, I can populate the field values of the record but when I try to insert the record it breaks my code.

Here is my code:
<apex:page id="pg" standardController="Contact">
    <script>
		function openPage (){
            var ev = new sforce.SObject("Event");
            ev.Subject = "Join.me Meeting w/ " + "{! Contact.FirstName}" + " " + "{! Contact.LastName}";
            ev.ActivityDate = "{! NOW()}";
            ev.DurationInMinutes = 30;
            ev.WhoId = "{! Contact.Id}";
            ev.JoinmeV2__Join_Me_Activity__c = true;
        	ev.JoinmeV2__Meeting_Code__c = "thewealthpool";
            
            sforce.connection.create([ev]);
            
            var win = window.open('https://www.join.me', '_blank');
            win.focus();            
        }

	</script>

    
    <apex:form >
        <apex:includeScript value="/soap/ajax/33.0/connection.js"/>
		<apex:includeScript value="/soap/ajax/33.0/apex.js"/>
        <apex:commandbutton image="{!URLFOR($Resource.JoinMeLogo)}" onClick="openPage()"/>
    </apex:form>
    	
</apex:page>

 
Hi,

I'm trying to delete a custom field on the Contact object, but it's telling me that it is associated with a Field Update that I created previously. For some reason, I can't seem to find a way to delete this field update as there is no option to delete it on the page. Any help is appreciated.User-added image
Hi,

I'm trying to delete a custom field on the Contact object, but it's telling me that it is associated with a Field Update that I created previously. For some reason, I can't seem to find a way to delete this field update as there is no option to delete it on the page. Any help is appreciated.User-added image