• LooseLips
  • NEWBIE
  • 25 Points
  • Member since 2010

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

Hi,

 

I've scoured the board and there seems to be plenty of examples of how to create new records in objects based on other submissions but my requirement seems a little more complex.

 

I currently have a mobile app submitting incident tickets into SFDC.

 

At present when a new incident__c record is created an APEX trigger finds the correct account that needs to fix that incident and attachs the account ID onto the ticket through a related field.

 

Then I can go to my account and see a list of related incident tickets that have been created on the account page.

 

So far, so good. What I now need to do is take this a bit further. I have created a new object called App_User__c and I want to do the same. However, the amount of Accounts is fixed, so I already have them created in SFDC. The users aren't known to me until they submit so I would like to 

 

a) Check if the app_user__C already exists based on their email in the incident__C object.

b) If not, create the app_user__C and copy 5 fields from the incident__c to populate the object

c) On creation or successful query, link the App_user__C ID to the incident__C ticket so I can see all incident's linked to my users on their page in SFDC, just like I can with Accounts.

 

Is this one trigger?  Many?

 

Any thoughts gratefully received!

 

Hi,

 

I want to check if this is even possible.

 

I have created a stand alone Visuaforce page based on a  custom controller pulling campaign members onto a single page that I want to be visible from the Account page.

 

Of course it seems to link a visualforce page by adding it as a section on the Account page, it needs to be powered by the Account standard controller.

 

Is it possible to write a visualforce page from the standard controller that can get data from as low down as Account>Contact>CampaignMember>Campaign so I can get all my fields?

 

Or alternatively is there a way to put a customer controller powered visualforce page on the Account page? Does the controller need to be 'Account' and add the following class as an extension?

 

I know this is basic stuff but after trawling the internet for an hour I'm alittle stuck.

 

Here's my current code for the stand alone page I have working;

 

public class myCampaignMembers {

 /// Create a list
 /// <OBJECT_NAME>
 List<CampaignMember> rqs;

 /// getReq() - Reffer to the list in the
 /// visualforce page with "Req" minus the "get" from
 /// controller name.
 public List<CampaignMember> getReq() {

  /// Get the data for the list
  rqs = [select id, Campaign.Name, CreatedDate, Contact.ID, Contact.Title, Contact.FirstName, Contact.LastName, Contact.AccountID, Status FROM CampaignMember];
  return  rqs;
 }
}

 

And my Visualforce Page....

 

<apex:page showHeader="false" sidebar="false" controller="myCampaignMembers" tabStyle="Contact">
 <apex:pageBlock title="Campaign Members" id="CamMem">
  <apex:dataTable value="{!Req}" var="CampaignMembers" cellPadding="4" border="1">
   <apex:column >
    <apex:facet name="header">Created Date</apex:facet>
    <apex:outputField value="{!CampaignMembers.CreatedDate}"/>
   </apex:column>
   <apex:column >
    <apex:facet name="header">Campaign Name</apex:facet>
    <apex:outputField value="{!CampaignMembers.Campaign.Name}"/>
   </apex:column>
   <apex:column >
    <apex:facet name="header">Status</apex:facet>
    <apex:outputField value="{!CampaignMembers.Status}"/>
   </apex:column>
      <apex:column >
    <apex:facet name="header">First Name</apex:facet>
    <apex:outputField value="{!CampaignMembers.Contact.FirstName}"/>
   </apex:column>
   <apex:column >
    <apex:facet name="header">Last Name</apex:facet>
    <apex:outputLink value="{!CampaignMembers.Contact.LastName}">{!CampaignMembers.Contact.LastName}</apex:outputLink>
   </apex:column>
   <apex:column >
    <apex:facet name="header">Title</apex:facet>
    <apex:outputField value="{!CampaignMembers.Contact.Title}"/>
   </apex:column>
   <apex:column >
    <apex:facet name="header">Account</apex:facet>
    <apex:outputField value="{!CampaignMembers.Contact.AccountID}"/>
   </apex:column>
  </apex:dataTable>
 </apex:pageBlock>
 
</apex:page>


 

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);
  }

}

 

 

 

 

 

Hi,

 

I've scoured the board and there seems to be plenty of examples of how to create new records in objects based on other submissions but my requirement seems a little more complex.

 

I currently have a mobile app submitting incident tickets into SFDC.

 

At present when a new incident__c record is created an APEX trigger finds the correct account that needs to fix that incident and attachs the account ID onto the ticket through a related field.

 

Then I can go to my account and see a list of related incident tickets that have been created on the account page.

 

So far, so good. What I now need to do is take this a bit further. I have created a new object called App_User__c and I want to do the same. However, the amount of Accounts is fixed, so I already have them created in SFDC. The users aren't known to me until they submit so I would like to 

 

a) Check if the app_user__C already exists based on their email in the incident__C object.

b) If not, create the app_user__C and copy 5 fields from the incident__c to populate the object

c) On creation or successful query, link the App_user__C ID to the incident__C ticket so I can see all incident's linked to my users on their page in SFDC, just like I can with Accounts.

 

Is this one trigger?  Many?

 

Any thoughts gratefully received!

 

Hi,

 

I want to check if this is even possible.

 

I have created a stand alone Visuaforce page based on a  custom controller pulling campaign members onto a single page that I want to be visible from the Account page.

 

Of course it seems to link a visualforce page by adding it as a section on the Account page, it needs to be powered by the Account standard controller.

 

Is it possible to write a visualforce page from the standard controller that can get data from as low down as Account>Contact>CampaignMember>Campaign so I can get all my fields?

 

Or alternatively is there a way to put a customer controller powered visualforce page on the Account page? Does the controller need to be 'Account' and add the following class as an extension?

 

I know this is basic stuff but after trawling the internet for an hour I'm alittle stuck.

 

Here's my current code for the stand alone page I have working;

 

public class myCampaignMembers {

 /// Create a list
 /// <OBJECT_NAME>
 List<CampaignMember> rqs;

 /// getReq() - Reffer to the list in the
 /// visualforce page with "Req" minus the "get" from
 /// controller name.
 public List<CampaignMember> getReq() {

  /// Get the data for the list
  rqs = [select id, Campaign.Name, CreatedDate, Contact.ID, Contact.Title, Contact.FirstName, Contact.LastName, Contact.AccountID, Status FROM CampaignMember];
  return  rqs;
 }
}

 

And my Visualforce Page....

 

<apex:page showHeader="false" sidebar="false" controller="myCampaignMembers" tabStyle="Contact">
 <apex:pageBlock title="Campaign Members" id="CamMem">
  <apex:dataTable value="{!Req}" var="CampaignMembers" cellPadding="4" border="1">
   <apex:column >
    <apex:facet name="header">Created Date</apex:facet>
    <apex:outputField value="{!CampaignMembers.CreatedDate}"/>
   </apex:column>
   <apex:column >
    <apex:facet name="header">Campaign Name</apex:facet>
    <apex:outputField value="{!CampaignMembers.Campaign.Name}"/>
   </apex:column>
   <apex:column >
    <apex:facet name="header">Status</apex:facet>
    <apex:outputField value="{!CampaignMembers.Status}"/>
   </apex:column>
      <apex:column >
    <apex:facet name="header">First Name</apex:facet>
    <apex:outputField value="{!CampaignMembers.Contact.FirstName}"/>
   </apex:column>
   <apex:column >
    <apex:facet name="header">Last Name</apex:facet>
    <apex:outputLink value="{!CampaignMembers.Contact.LastName}">{!CampaignMembers.Contact.LastName}</apex:outputLink>
   </apex:column>
   <apex:column >
    <apex:facet name="header">Title</apex:facet>
    <apex:outputField value="{!CampaignMembers.Contact.Title}"/>
   </apex:column>
   <apex:column >
    <apex:facet name="header">Account</apex:facet>
    <apex:outputField value="{!CampaignMembers.Contact.AccountID}"/>
   </apex:column>
  </apex:dataTable>
 </apex:pageBlock>
 
</apex:page>


 

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);
  }

}