• thomasarnold81
  • NEWBIE
  • 25 Points
  • Member since 2010

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

Hi,

 

Does anyone have example code or classes for outputting data from a custom object to plot features on the Google Maps Data API?

 

The authentication bit is confusing me.

 

I just need something to get me started. There are a lot of examples for google maps but not just what I am looking for.

 

Anyone have any ideas? I have seen the developer guide on Google so I have KML structure - I just need to wrap this APEX to kick start the plotting of data. 

 

Thanks.

 

 

Hi Guys,

 

I think I am pretty close here.

 

The GET HTTP should send out a custom built URL from two fields on a custom object (not all together different from a Case style page). The return information is XML and I am trying to pull down a specific field and insert that back onto into the custom record.

 

Any ideas where I am going wrong. I am certainly struggling with the update part of the APEX code. 

 

Any thoughts would be helpful;

 

 

trigger LatLong on Incident__c (before insert, before update) {
    
    public void parseResponseDom(String url){
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        // url that returns the XML in the response body  
    
        req.setEndpoint('http://www.uk-postcodes.com/latlng/{!latitude__c},{!longitude__c}.xml');
        req.setMethod('GET');
        HttpResponse res = h.send(req);
        Dom.Document doc = res.getBodyDocument();
        
        //Retrieve the root element for this document.  
    
        Dom.XMLNode result = doc.getRootElement();
        
        String postcode = result.getChildElement('postcode', null).getText();
        // print out specific elements  
        
        System.debug('postcode: ' + postcode);
        for(Dom.XMLNode child : result.getChildElements()) {
        System.debug(child.getText());
        }
        
        Incident__c I = [select Council_Name_Text__c from Incident__c 
             where Council_Name_Text__c = null limit 1];
             
        I.Council_Name_Text__c = postcode;
       
        update I;
        
  
        }
    }

Ok,

 

I am trying to add in a field from an external API source and I am wondering the best way to do and what I would need.

 

I have found a website whereby if I construct a URL from pieces of data from SFDC it will return a list of fields, one of which I want to pull into my platform.

 

So the URL I construct brings back geo-location information about a specific latitude and longitude. I want to grab one field from a list of fields presented back on a web page. This page can be constructed in JSON or XML which I can control.

 

This is all releated to a custom object but acts very much like a Case would.

 

So on the insert of this case data through the API I want a trigger to go away and pull back one field from the URL API to complete the geographical information on the case

 

What call would I use to going out of Salesforce to do that? Any thoughts on how I call and insert the new data into my custom object? I am assuming APEX can do this and return me a value?

 

Hope that all meakes sense.

 

I look forward to hearing your suggestions.

 

Hi Guys,


I am looking for some help in regards to a trigger I am writing on the case object.


The case is currently orphaned as it has no account ID inserted with it. However, on the case I do have the name of the account in a text field wriiten exactly as it is shown on the account page. Why I have this data structured like this is a long dull story and I know there were probably better ways to do this when setting up my process but I am new at this.


Here's what I want to - I want a trigger to look at the text field with the account name, search for the AccountID and link the case to the correct account so it's not orphaned any more.


My code is below - where am I going wrong?

 

trigger CaseAccountUpdater2 on Case (before insert, before update) {

 

 for(Case cas : Trigger.New){  

 

   if(cas.AccountId != null) {  

      cas.Account = [Select ID    

      From Account    

      Where Name = :Cas.Council_Name_Text__c    

      Limit 1];  

    }

  }

}

Guys,

 

Any idea why this visualforce page is not letting a guest user view the page (despite having the correct rights) when a Case Id is passed through the URL?

 

I can see the page without the additional info at the end of the URL - but obviously theres no data for the subject or account ID.

 

Thanks in advance.

 

<apex:page standardcontroller="Case"> test This is an issue type of {!Case.subject} for {!Case.AccountId}. </apex:page>

Hi there,

 

Currently struggling with a problem relating to new caess being created.

 

When new cases come through the API I want to take a certain piece of information within that case, actually a URL and pass it through Bitly to shorten it.

 

I found this code on the forum and I have added in the field that I want on there which I want it to shorten - the question is. How do I invoke this class - do I need to set it as a trigger on the Case?

 

I have tried doing that but it doesn't like the code below due to the "static" elements in there. 

 

Effectively what I am asking is, I have the code (which when tested in the class page does not return errors) it's just how do I get it to do it's stuff?

 

Thanks in advance

 

/*
Class to connect to bit.ly API to shorten a long URL
*/
global class bitly {
    private static final String APIKEY = 'R_b56894694361ab39ab856f69893b3911';
    private static final String LOGIN = 'mujowax';
    
    global static String shorten(String url) {
        Http h = new Http();
        HttpRequest request = new HttpRequest();
        request.setEndPoint('http://api.bit.ly/shorten?version=2.0.1&format=xml&login='+LOGIN+'&apiKey='+APIKEY+'&longUrl='+'Geohash__c');
        request.setMethod('GET');
        
        try {
            HttpResponse response = h.send(request);
            
            if (response.getStatusCode() == 200) {
                XMLStreamReader reader = response.getXmlStreamReader();
                String shortUrl = parseResponse(reader);
                return shortUrl;
            }
        } catch (System.CalloutException e) {
            System.debug('\n**** bit.ly CalloutException: '+e);
        }

        // if the callout was unsuccessful for any reason
        return null;
    }
    
    private static String parseResponse(XmlStreamReader reader) {
        String shortUrl;
        while (reader.hasNext()) {
            if (reader.getEventType() == XmlTag.START_ELEMENT && reader.getLocalName() == 'shortUrl') {
                reader.next();
                shortUrl = reader.getText();
                break;
            }

            if (reader.getEventType() == XmlTag.START_ELEMENT && reader.getLocalName() == 'errorMessage') {
                reader.next();
                if (reader.getEventType() != XmlTag.END_ELEMENT) {
                    String errorMessage = reader.getText();
                    System.debug('\n* Error message from bit.ly: '+errorMessage);
                    return null;
                }
            }
            reader.next();
        }
        
        return shortUrl;
    }
    
    private static testMethod void testBitly0() {
        bitly.shorten('http://www.salesforce.com/');
    }
    
    private static testMethod void testBitly1() {
        String responseXml = '<bitly><errorCode>0</errorCode><errorMessage></errorMessage><results><nodeKeyVal><userHash>15pXjJ</userHash><shortKeywordUrl></shortKeywordUrl><hash>M2FqH</hash><nodeKey><![CDATA[http://www.salesforce.com]]></nodeKey><shortUrl>http://bit.ly/15pXjJ</shortUrl></nodeKeyVal></results><statusCode>OK</statusCode></bitly>';
        XmlStreamReader reader = new XmlStreamReader(responseXml);
        Test.startTest();
        String shortUrl = parseResponse(reader);
        System.assertNotEquals(null, shortUrl);
    }

    private static testMethod void testBitly2() {
        String responseXml = '<bitly><errorCode>203</errorCode><errorMessage>You must be authenticated to access shorten</errorMessage><statusCode>ERROR</statusCode></bitly>';
        XmlStreamReader reader = new XmlStreamReader(responseXml);
        Test.startTest();
        String shortUrl = parseResponse(reader);
        System.assertEquals(null, shortUrl);
    }
}

Hi Guys,

 

I am trying to figure if it's possible to strip/parse an email body and take one of the lines to then use to attach a case to an account?

 

At the moment I have castoemail working just fine with lots of lines (strings) going into simple text fields. But it doesn't seem to want to take.....

 

Account: Test County Council

 

... form the body of the email and insert that into the Account Name on the case most likely because the field is a look up. Can I convert this somehow in APEX so that the lookup will take the data from the email body?

 

Or do I need to write a trigger so that I pull in the string into a simple Account Name text field and copy that over to the look up on insert?

 

Any help would be appreciated.

 

Currently I can see that you may be able to take the email address and use that to attach the case to a contact so clearly there are ways to attach cases to other objects when using emailtocase

 

Thanks in advance.

Hi Guys,

 

This is my first post so any help you could throw my way would be very helpful.

 

So heres the issue. Currently I have emails coming into Salesforce which are being pushed through EmailtoCase (On Demand) which strips the data line by line in the body plus any attachments and adds that into various custom fields in a case.

 

So far so good. However, now on creation of that case I want to send an email OUT of salesforce with some of this information plus the attachment from the case. There will only ever be one attachment of each case. The attachments will always be images.

 

The fields are easy. The attachment bit isn't.  With visualforce it seems you can create attachments from data but I don't want to do that. I want to attach an existing attachment and send it out within a template. Can anyone point me in the right direction of the correct visual code that checks the case for attachments and attaches it to an outgoing email.

Hi Guys,

 

I think I am pretty close here.

 

The GET HTTP should send out a custom built URL from two fields on a custom object (not all together different from a Case style page). The return information is XML and I am trying to pull down a specific field and insert that back onto into the custom record.

 

Any ideas where I am going wrong. I am certainly struggling with the update part of the APEX code. 

 

Any thoughts would be helpful;

 

 

trigger LatLong on Incident__c (before insert, before update) {
    
    public void parseResponseDom(String url){
        Http h = new Http();
        HttpRequest req = new HttpRequest();
        // url that returns the XML in the response body  
    
        req.setEndpoint('http://www.uk-postcodes.com/latlng/{!latitude__c},{!longitude__c}.xml');
        req.setMethod('GET');
        HttpResponse res = h.send(req);
        Dom.Document doc = res.getBodyDocument();
        
        //Retrieve the root element for this document.  
    
        Dom.XMLNode result = doc.getRootElement();
        
        String postcode = result.getChildElement('postcode', null).getText();
        // print out specific elements  
        
        System.debug('postcode: ' + postcode);
        for(Dom.XMLNode child : result.getChildElements()) {
        System.debug(child.getText());
        }
        
        Incident__c I = [select Council_Name_Text__c from Incident__c 
             where Council_Name_Text__c = null limit 1];
             
        I.Council_Name_Text__c = postcode;
       
        update I;
        
  
        }
    }

Ok,

 

I am trying to add in a field from an external API source and I am wondering the best way to do and what I would need.

 

I have found a website whereby if I construct a URL from pieces of data from SFDC it will return a list of fields, one of which I want to pull into my platform.

 

So the URL I construct brings back geo-location information about a specific latitude and longitude. I want to grab one field from a list of fields presented back on a web page. This page can be constructed in JSON or XML which I can control.

 

This is all releated to a custom object but acts very much like a Case would.

 

So on the insert of this case data through the API I want a trigger to go away and pull back one field from the URL API to complete the geographical information on the case

 

What call would I use to going out of Salesforce to do that? Any thoughts on how I call and insert the new data into my custom object? I am assuming APEX can do this and return me a value?

 

Hope that all meakes sense.

 

I look forward to hearing your suggestions.

 

Hi Guys,


I am looking for some help in regards to a trigger I am writing on the case object.


The case is currently orphaned as it has no account ID inserted with it. However, on the case I do have the name of the account in a text field wriiten exactly as it is shown on the account page. Why I have this data structured like this is a long dull story and I know there were probably better ways to do this when setting up my process but I am new at this.


Here's what I want to - I want a trigger to look at the text field with the account name, search for the AccountID and link the case to the correct account so it's not orphaned any more.


My code is below - where am I going wrong?

 

trigger CaseAccountUpdater2 on Case (before insert, before update) {

 

 for(Case cas : Trigger.New){  

 

   if(cas.AccountId != null) {  

      cas.Account = [Select ID    

      From Account    

      Where Name = :Cas.Council_Name_Text__c    

      Limit 1];  

    }

  }

}

Guys,

 

Any idea why this visualforce page is not letting a guest user view the page (despite having the correct rights) when a Case Id is passed through the URL?

 

I can see the page without the additional info at the end of the URL - but obviously theres no data for the subject or account ID.

 

Thanks in advance.

 

<apex:page standardcontroller="Case"> test This is an issue type of {!Case.subject} for {!Case.AccountId}. </apex:page>

Hi Guys,

 

I am trying to figure if it's possible to strip/parse an email body and take one of the lines to then use to attach a case to an account?

 

At the moment I have castoemail working just fine with lots of lines (strings) going into simple text fields. But it doesn't seem to want to take.....

 

Account: Test County Council

 

... form the body of the email and insert that into the Account Name on the case most likely because the field is a look up. Can I convert this somehow in APEX so that the lookup will take the data from the email body?

 

Or do I need to write a trigger so that I pull in the string into a simple Account Name text field and copy that over to the look up on insert?

 

Any help would be appreciated.

 

Currently I can see that you may be able to take the email address and use that to attach the case to a contact so clearly there are ways to attach cases to other objects when using emailtocase

 

Thanks in advance.

Hi Guys,

 

This is my first post so any help you could throw my way would be very helpful.

 

So heres the issue. Currently I have emails coming into Salesforce which are being pushed through EmailtoCase (On Demand) which strips the data line by line in the body plus any attachments and adds that into various custom fields in a case.

 

So far so good. However, now on creation of that case I want to send an email OUT of salesforce with some of this information plus the attachment from the case. There will only ever be one attachment of each case. The attachments will always be images.

 

The fields are easy. The attachment bit isn't.  With visualforce it seems you can create attachments from data but I don't want to do that. I want to attach an existing attachment and send it out within a template. Can anyone point me in the right direction of the correct visual code that checks the case for attachments and attaches it to an outgoing email.