• Arek Stegienko Dev
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 0
    Replies

I need to get a list of lead history objects between two dates.  I've come up with this approach:

 

[SELECT (SELECT LeadId, CreatedDate, Field, OldValue, NewValue FROM Histories WHERE CreatedDate >= :fromDate AND CreatedDate <= :toDate) FROM Lead]

 

however, that returns a list of all leads that I then would have to go through and check if they actually contain any history.  Is there a way to directly access the lead history object and query that table?

 

Thanks,

Harry

I need to add questionnaires to the leads/accounts/contacts in my database and I'm looking for advice on the best way to implement this.

 

My questionnaires consist of a set of questions that one of my employees fills out about the lead/account/contact they are working with.  The questions are a combination of text fields, checkboxes, picklists, etc.  Also I'd like to have the ability down the road to implement some sort of scoring of the answers to provide a summary of the questionnaire (ie: based on the questions the lead is % likely to be interested in X, Y, Z, products).  I'd like to be able to add multiple questionnaires sort of like you can add tasks to a lead/account/contact.

 

At first I thought I could approach this by simply creating a new task record type and having my questionnaire be a task, but I'm pretty sure there's got to be a better non hack way of doing this.  Also using a task record type would probably prevent me (in the future) from summarizing the answers and providing some sort of score of the questionnaire.

 

Thank you in advance for any help you can offer in how to approach and solve this.  Btw, I've only been using/developing SalesForce for about 1 month so in depth step by step answers are highly appreciated, but high level overviews are also welcome if you don't have the time to write longer response.

 

Thanks.

Anyone know what this exception means:

 

System.SObjectException: Field XXX is inaccessible in this context

 

The XXX in my case is Lead.CompanyDunsNumber, which doesn't seem to be an actual field.  Btw, I'm getting this exception when converting a lead using the code sample provided here: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_dml_convertLead.htm .

 

Any help is highly appreciated.

 

Thanks.

I'm writing an event trigger that will convert a lead when an event of a specific record type is created.  Here's what I've got so far, however, I'm getting stuck on checking for the right record type in the trigger and/or creating the right record type event in the test class:

 

trigger ConvertLead on Event (after insert)
{
  // Loop through all the events
  for (Event event : trigger.new)
  {
    // Check if this is a 1st tour event
    if (event.RecordType ==
        [SELECT Id FROM RecordType WHERE Name = '1st Tour' AND SObjectType = 'Event' LIMIT 1])
    {
      // Get the lead that's associated with this event
      Lead lead = [SELECT Id FROM Lead WHERE Id =: event.WhoId];

      // Create a new LeadConvert object
      Database.LeadConvert convert = new database.LeadConvert();
    
      // Get and set the converted lead status
      LeadStatus convertStatus = [SELECT MasterLabel FROM LeadStatus WHERE IsConverted = true LIMIT 1];
      convert.setConvertedStatus(convertStatus.MasterLabel);
    
      // Set the owner
      convert.setOwnerId(event.OwnerId);

      // Convert the lead
      Database.LeadConvertResult result = Database.convertLead(convert);
      System.assert(result.isSuccess());
    }
  }
}

 

  static testMethod void ConvertLeadTestMethod()
  {
    // Create the lead, insert it, and add the event
    Lead lead = new Lead(FirstName = 'Test', LastName = 'Lead');
    insert lead;
    Event event = new Event(WhoId = lead.Id,
                  RecordType = [SELECT Id FROM RecordType WHERE Name = '1st Tour' AND SObjectType = 'Event' LIMIT 1],
                  DurationInMinutes = 60, ActivityDateTime = datetime.now());
    insert event;
  }

 I'm fairly new to apex so any and all help is very much appreciated.

 

Thanks.

I'm new to writing Apex code and I need to create a trigger that runs when a task is created and have this trigger update a field in the task's parent object (in this case a lead).  I learn great from examples, so if anyone has a trigger that does exactly this and is willing to post it that would be great.  Or at the very least if you could let me know how I go about getting access to the parent object of the task that would help too.

 

Thanks.