• smills
  • NEWBIE
  • 35 Points
  • Member since 2007

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

Ok gentlemen - I need some assistance.

 

I'm a relative newbie to this although I making decent progress punctuated with a a few hours here of despair.

 

I currently have a custom object being part populated through the API - I then have written the following class which goes away to an external API and pulls back some more fields completed the data - and it works well. But at when I went live with this I wasn't too up on test methods. As such, the class has not got any and thankfully due to the pre-installed packages from Salesforce I am just hovering above 75% through pure luck.

 

As such, I have this in production and luckily working with triggers but I now need to update the test method or I can't deploy some updated functionality - if anyone have used the deployment functionality you will know what I mean.

 

Here's the class ignore the test at the bottom - that was purely to get trigger above 0%. My code coverage on the class for this is 0%.

 

Can you give me some pointers on the following code? Now I've seen the apex instructions on breaking your callouts in 3 sections but I can't seem to make that fit.

 

Any thoughts - any suggestions welcome... like I said currently at 0%....

 

 

public class IncidentCouncilUpdater {

  //Future annotation to mark the method as async.
  @Future(callout=true)
  public static void updateIncident(ID IncidentID) {
  
  Incident__c myCoordinates = [SELECT latitude__c, longitude__c
                             FROM Incident__c
                             WHERE Id = :IncidentID];  
  System.debug('myCoordinates: ' + myCoordinates);  
  
  String myLat = myCoordinates.latitude__c;
  String myLong = myCoordinates.longitude__c;          
  System.debug('myLat: ' + myLat);
  System.debug('myLong: ' + myLong);     
  
  //Create end point from fields in the database
  String StrEndPoint = 
  'http://www.uk-postcodes.com/latlng/'+myLat+','+myLong+'.xml';
  
  System.debug('StrEndPoint: ' + StrEndPoint);
  
    //construct an HTTP request
    HttpRequest req = new HttpRequest();
    req.setHeader('Content-Type', 'text/xml');
    //req.setEndpoint('http://www.uk-postcodes.com/latlng/53.24354,-2.34567.xml');
    req.setEndpoint(strEndPoint);
    req.setMethod('GET');
    req.setTimeout(60000);
    
    //send the request
    Http http = new Http();
    HttpResponse res = http.send(req);
    
    // Log the XML content  
    Dom.Document doc = res.getBodyDocument(); 
    
    // print out specific elements by finding the node address 
    dom.XmlNode location = doc.getRootElement()
    .getChildElement('administrative',null)
    .getChildElement('district',null);  
    
    System.debug('location: ' + location);   
    
    // print out specific elements by finding the node address 
    dom.XmlNode location2 = doc.getRootElement();
      System.debug('location2: ' + location2); 
      
    // gets the content from the XML
    String district_title;
    String postcode;
    district_title = location.getChildElement('title', null).getText();
    postcode = location2.getChildElement('postcode', null).getText();
    System.debug('district_title: ' + district_title);  
    System.debug('postcode: ' + postcode);
    
    //update Incident
    Incident__c Inc = new Incident__c(Id=IncidentID);
    Inc.Council_Name_Text__c = district_title;
    Inc.Incident_Postcode__c = postcode;
    update Inc; 
     
}

    static testMethod void testIncidentCouncilUpdater(){
   
    Incident__c Inc1 = new Incident__c(name='Other', latitude__c='53.54489', longitude__c='-2.44467');
    return inc1.id;
    String StrEndPoint = 'http://www.uk-postcodes.com/latlng/53.54489,-2.44467.xml';
    
    HttpRequest req = new HttpRequest();
    req.setEndpoint(strEndPoint);
    req.setMethod('GET');
    req.setTimeout(60000);
    
    
    Inc1.Council_Name_Text__c = 'Salford City Council';
    Inc1.Incident_Postcode__c = 'M30 9QU';
    update Inc1;
}

}

 

 

Here's the trigger...

 

 

trigger XMLUpdater on Incident__c (after insert) {

  System.debug('Making future call to update account');
  for (Incident__c Inc : Trigger.New) {
    //Call future method to update account
    //with data from external server.
    //This is a async calls, it returns right away, after
    //enqueuing the request.

    IncidentCouncilUpdater.updateIncident(Inc.Id);
  }

}

 

 

 

 

 

I am making future calls from APEX code and need to know when the calls complete so I can do other processing. If I use the GUI of Salesforce I can go to the Setup area and under 'Monitoring', I can use the 'Apex Jobs' selection to see the job is processing and if it completed.

 

Reason being, my APEX code breaks the future calls up into batches.  I usually end up doing 3 future calls, but need to know all three have completed before I can continue with some DML operations.


How can I get the future call status information programatically within my code?

 

  • October 29, 2010
  • Like
  • 1
Hi,
I have written a program in .NET that logins in to Sales Force and extracts data and reformats it in an excel file.  It works fine when run from the command line or within windows, but I want to run it within SalesForce.  Most probably create some type of s-control.  The main reason I would like to run it within SalesForce is because the user will already be authenticated, so it makes it easier for them to just click a button/link. 

Is there any samples/codes that I can be pointed to or any suggestions?

I have written an S-Control that shows me some Opportunity info and related Account Info.  I have added it to a button on my Opportunity Layout screen.  When I click this button, I want to use the Opportunity ID from the accoaciated 'Opportunity' to get the info from the Account.

The query is:

 sforce.connection.query("SELECT Id, StageName, Core_Consumer_Rep__c, Core_PhPromo_Rep__c, Account.Id, Account.Name, Account.Lead_Core_Consumer__c, Account.Lead_Core_PhPromo__c FROM Opportunity WHERE StageName='Pending' AND Id = ?????????   LIMIT 20", callback);

So how do I get the Id value of the Opportunity that I clicked the button from?

I am making future calls from APEX code and need to know when the calls complete so I can do other processing. If I use the GUI of Salesforce I can go to the Setup area and under 'Monitoring', I can use the 'Apex Jobs' selection to see the job is processing and if it completed.

 

Reason being, my APEX code breaks the future calls up into batches.  I usually end up doing 3 future calls, but need to know all three have completed before I can continue with some DML operations.


How can I get the future call status information programatically within my code?

 

  • October 29, 2010
  • Like
  • 1

I am making future calls from APEX code and need to know when the calls complete so I can do other processing. If I use the GUI of Salesforce I can go to the Setup area and under 'Monitoring', I can use the 'Apex Jobs' selection to see the job is processing and if it completed.

 

Reason being, my APEX code breaks the future calls up into batches.  I usually end up doing 3 future calls, but need to know all three have completed before I can continue with some DML operations.


How can I get the future call status information programatically within my code?

 

  • October 29, 2010
  • Like
  • 1

Ok gentlemen - I need some assistance.

 

I'm a relative newbie to this although I making decent progress punctuated with a a few hours here of despair.

 

I currently have a custom object being part populated through the API - I then have written the following class which goes away to an external API and pulls back some more fields completed the data - and it works well. But at when I went live with this I wasn't too up on test methods. As such, the class has not got any and thankfully due to the pre-installed packages from Salesforce I am just hovering above 75% through pure luck.

 

As such, I have this in production and luckily working with triggers but I now need to update the test method or I can't deploy some updated functionality - if anyone have used the deployment functionality you will know what I mean.

 

Here's the class ignore the test at the bottom - that was purely to get trigger above 0%. My code coverage on the class for this is 0%.

 

Can you give me some pointers on the following code? Now I've seen the apex instructions on breaking your callouts in 3 sections but I can't seem to make that fit.

 

Any thoughts - any suggestions welcome... like I said currently at 0%....

 

 

public class IncidentCouncilUpdater {

  //Future annotation to mark the method as async.
  @Future(callout=true)
  public static void updateIncident(ID IncidentID) {
  
  Incident__c myCoordinates = [SELECT latitude__c, longitude__c
                             FROM Incident__c
                             WHERE Id = :IncidentID];  
  System.debug('myCoordinates: ' + myCoordinates);  
  
  String myLat = myCoordinates.latitude__c;
  String myLong = myCoordinates.longitude__c;          
  System.debug('myLat: ' + myLat);
  System.debug('myLong: ' + myLong);     
  
  //Create end point from fields in the database
  String StrEndPoint = 
  'http://www.uk-postcodes.com/latlng/'+myLat+','+myLong+'.xml';
  
  System.debug('StrEndPoint: ' + StrEndPoint);
  
    //construct an HTTP request
    HttpRequest req = new HttpRequest();
    req.setHeader('Content-Type', 'text/xml');
    //req.setEndpoint('http://www.uk-postcodes.com/latlng/53.24354,-2.34567.xml');
    req.setEndpoint(strEndPoint);
    req.setMethod('GET');
    req.setTimeout(60000);
    
    //send the request
    Http http = new Http();
    HttpResponse res = http.send(req);
    
    // Log the XML content  
    Dom.Document doc = res.getBodyDocument(); 
    
    // print out specific elements by finding the node address 
    dom.XmlNode location = doc.getRootElement()
    .getChildElement('administrative',null)
    .getChildElement('district',null);  
    
    System.debug('location: ' + location);   
    
    // print out specific elements by finding the node address 
    dom.XmlNode location2 = doc.getRootElement();
      System.debug('location2: ' + location2); 
      
    // gets the content from the XML
    String district_title;
    String postcode;
    district_title = location.getChildElement('title', null).getText();
    postcode = location2.getChildElement('postcode', null).getText();
    System.debug('district_title: ' + district_title);  
    System.debug('postcode: ' + postcode);
    
    //update Incident
    Incident__c Inc = new Incident__c(Id=IncidentID);
    Inc.Council_Name_Text__c = district_title;
    Inc.Incident_Postcode__c = postcode;
    update Inc; 
     
}

    static testMethod void testIncidentCouncilUpdater(){
   
    Incident__c Inc1 = new Incident__c(name='Other', latitude__c='53.54489', longitude__c='-2.44467');
    return inc1.id;
    String StrEndPoint = 'http://www.uk-postcodes.com/latlng/53.54489,-2.44467.xml';
    
    HttpRequest req = new HttpRequest();
    req.setEndpoint(strEndPoint);
    req.setMethod('GET');
    req.setTimeout(60000);
    
    
    Inc1.Council_Name_Text__c = 'Salford City Council';
    Inc1.Incident_Postcode__c = 'M30 9QU';
    update Inc1;
}

}

 

 

Here's the trigger...

 

 

trigger XMLUpdater on Incident__c (after insert) {

  System.debug('Making future call to update account');
  for (Incident__c Inc : Trigger.New) {
    //Call future method to update account
    //with data from external server.
    //This is a async calls, it returns right away, after
    //enqueuing the request.

    IncidentCouncilUpdater.updateIncident(Inc.Id);
  }

}

 

 

 

 

 

I am amazed on how difficult I find it to set a checkbox to it's value.
Using a simple x = true on a custom field (checkbox) on 1 custom object, and I get nothing correct.
 
code is c#
Code:
        private static void createLicense()
        {
            if (!loggedIn())
                return;

            try
            {
                //Create an account object to send to the service
                sforce.OptiTex_License__c license = new sforce.OptiTex_License__c();
 
                //Set several properties
                license.X1_Marker__c = true;
                license.X2_Grading__c = false;

                //license.X4_Light_version__c.

                // Add the account to an array of SObjects
                sforce.sObject[] records = new sforce.sObject[] { license };

                // Invoke the create call, passing in the account properties
                // and saving the results in a SaveResult object
                sforce.SaveResult[] saveResults = binding.create(records);

                // Access the new ID
                String newID = saveResults[0].id;
                Console.WriteLine(newID.ToString());
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message + "\n" + e.StackTrace);
                return;
            }
        }

 I tried both true or false , 0, 1 (which offcourse failed cause it's a boolean and not int field.
 
any help is appreciated thanks.
I have written an S-Control that shows me some Opportunity info and related Account Info.  I have added it to a button on my Opportunity Layout screen.  When I click this button, I want to use the Opportunity ID from the accoaciated 'Opportunity' to get the info from the Account.

The query is:

 sforce.connection.query("SELECT Id, StageName, Core_Consumer_Rep__c, Core_PhPromo_Rep__c, Account.Id, Account.Name, Account.Lead_Core_Consumer__c, Account.Lead_Core_PhPromo__c FROM Opportunity WHERE StageName='Pending' AND Id = ?????????   LIMIT 20", callback);

So how do I get the Id value of the Opportunity that I clicked the button from?