• FrankF
  • NEWBIE
  • 0 Points
  • Member since 2008

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

What I would like to do is get a list of Campaign Names for a given Lead.

 

I can do this via 2 soql queries - 

 

campaignids  = [select CampaignId from CampaignMember where LeadId='00Q7000000XXXXX]

 

and then 

 

campaignNames= [select Name from Campaign where Id in :campaignids]

 

is there a way to do this in one query?

 

I've tried select Name from Campaign where CampaignMembers__r.LeadId = '00Q7000000XXXXX'since I see that Campaign has a child relationship with CampaignMember but that doesn't seem to work.

 

Any help would be much appreciated.

 

Frank.

  • February 19, 2010
  • Like
  • 0

Hi all,

 

I'm trying to create an email template for to send lead information to our partner (who is not in SFDC).  I can create everything I need but one of the requirements is that we show the partner all the campaigns that are associated with the lead as well as the more pedantic Name, Address, Phone, etc.

 

I've tried adding {!CampaignMember.Campaign Name} and {!Campaign.Name}both to no avail (they're just blank). How can I specify a one-to-many join on CampaignMember to Lead?

 

Is VF the only way to achieve this (ugh I am a total VF newbie)? I can think of umpteen ways to solve this with .NET integration but I'd like to try to keep it simple and within SFDC.

 

Thanks very much.

 

  • February 17, 2010
  • Like
  • 0

A little backgroud:

 

We have a field - Qualifying_Campaign__c that is required to be filled when a lead's status changes from Prospect to Qualified Lead. The reason for the field is that a Lead may be a member of multiple Campaigns but the Qualifying Campaign is the campaign that actually qualified the change of status.

 

Now, we have a partner that pushes leads to us using a Web To Lead form. They are correcly setting the CampaignId on the Web to Lead form. The requirement is then that since these leads are prequalified, I need to set the Status to Qualified Lead when the Lead comes into SFDC and I need to set the Qualifying_campaign__c to the CampaignId that was pushed.

 

So I wrote a trigger that accomplishes this.

 

trigger Lead_AfterInsert on Lead (after insert) {

List<Id> leadids = new List<Id>();

for (Lead thisLead : Trigger.New)

leadids.add(thisLead.Id);

Lead[] leads = [select Id, LeadSource, Status, Qualifying_Campaign__c, custom_lead_src__c, (Select CampaignId from CampaignMembers order by CreatedDate limit 1) from Lead where Id in :leadids];

 

for (Lead l : leads) {

//Do the eTrigue thang

 if (l.LeadSource == 'eTrigue' && l.Custom_Lead_Src__c != '') {

try {System.debug(

'CampaignMembers isEmpty = ' + l.CampaignMembers.IsEmpty()); if (!l.CampaignMembers.IsEmpty()) {

l.LeadSource = l.Custom_Lead_Src__c;

l.Status = 'Qualified Lead';

l.Qualifying_Campaign__c = l.CampaignMembers[0].CampaignId;

update l;

}

} catch (DMLException e) {System.debug(

'DMLException Occurred:' + e.getMessage());

}

}

}

}

 

So all is well until it comes time to write the TestClass for this trigger. How the heck do I simulate the insertion of the Lead with a CampaignId?

 

If I create the Lead, and then insert the CampaignMember record, the Lead_AfterInsert trigger will already have fired!

 

Any ideas would be much appreciated.

 

Frank.

  • August 07, 2009
  • Like
  • 0

I'm trying to deploy some stuff from my Enterprise Sandbox (developer sandbox not full copy) to my DE account so that I can do some even more isolated development but the deployment dialog tells me that my custom objects are not deployable.

 

Can anyone shed some light on this? I've tried it on a couple of different machines with the same result.

I'm running Eclipse Europa 3.3.2 with the latest force.com ide on Windows XP.

 

Here's a screen shot my of deployment.

 

 

Thanks much,

Frank

I need to set a Lookup field's value in Salesforce.com's Lead object and am using the code below.

The Qualifying_Campaign__c field is a custom lookup field related to the Campaign object and the value I'm setting is the correct Campaign Id for the campaign which we want to set. A describesObject call to look at the Lead object reveals that the Qualifying_Campaign__c is indeed updateable.

The code snippet comes from a function called by an Outbound Message from SFDC on Lead creation for certain types of Leads.

The Exception I get when I call the update function  is as follows and I can't quite understand why it's happening...

Error message from catch (Exception ex)
A duplicate value was specified for field 'Id' in object 'Lead', duplicate value '00Q7000000OXbm5EAD' prior value '00Q7000000OXbm5EAD'

heh?!
Other troubleshooting showed that my code works when updating the OwnerID in the same way. The error only occurs when updating the Qualifying_Campaign__c field.
 
Thanks in advance,
Frank.
 
Code Snippet
QueryResult qrLead = RunQuery("select Id, Qualifying_Campaign__c from Lead where Id='" + leadid + "'");
sObject lead = null;
if (qrLead != null && qrLead.size > 0)
{
 lead = qrLead.records[0];
 //Update to new username
 //ld.Id = leadid;
 //lead.Any[1].InnerText = uid;
 lead.Any[1].InnerText = "70170000000KheRAAS";
 
 SaveResult[] saveResult = null; ;
 try
 {
  saveResult = _sfdcService.update(new sObject[] { lead });
 }
 catch (Exception ex)
 { }
 if (saveResult[0].success)
  res = 1;
 else {
  _log.Error(String.Format("Failure in UpdateLead: {0}", saveResult[0].errors[0].message));
  _log.Error("Lead ID : " + leadid + "      RSM : " + rsm);
 }
}
else
 res= 0;
 
  • November 27, 2008
  • Like
  • 0
Hey guys,
 
I'm pretty new to Apex programming and am just trying to understand something that our consultants wrote for us.
The code snippet is below:
 
Code:
trigger trg_custom1_req on custom1__c (after update) {
   for (custom1__c evalRec:System.Trigger.new) 
   {

      custom1__c oldEvalRec = System.Trigger.oldMap.get(evalRec.Id);
      if (!oldEvalRec.Evaluation_Approved__c && evalRec.Evaluation_Approved__c)
      {
         String templateId = '00X70000000XXXX';
         Opportunity oppRec = [SELECT Id, Account.Owner.Id, Account.Owner.Email ,Account.Owner.Alias_Email__c FROM Opportunity WHERE Id = :evalRec.Opportunity__c];
         String toEmail = oppRec.Account.Owner.Alias_Email__c;
         if (toEmail == null)
            toEmail = oppRec.Account.Owner.Email;
         String[] toEmailId = new String[] {toEmail};
         Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 
         mail.setToAddresses( toEmailId );
         mail.setWhatId (evalRec.Id);
         mail.setTemplateId (templateId);
         mail.setTargetObjectId ('003R0000001XXXX'); // Admin Contact         
         Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
      }
   }
}

So everything works just fine but the admin email in the mail.setTargetObjectId ('003R0000001XXXX'); is always emailed. I'd like to change this such that it is only emailed if the oppRec.Account.Owner.Alias_Email__c is null...
 
So I modified the code to add an if statement:
Code:
if (oppRec.Account.Owner.Alias_Email__c == null)
   mail.setTargetObjectId ('003R0000001XXXX'); // Admin Contact         

 However, SFDC then returns this on the trigger execute:
 
Validation Errors While Saving Record(s)

There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger trg_custom1_req caused an unexpected exception, contact your administrator: trg_custom1_req : execution of AfterUpdate caused by: System.EmailException: SendEmail failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Missing targetObjectId with template: Trigger.trg_prod_eval_req: line 22, column 13".

However, this link http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_email_outbound_single.htm suggests to me that the setTargetObjectId is optional.

What am I missing here?

Thanks a bunch.
Frank.


 

 
  • August 28, 2008
  • Like
  • 0
We currently use SFDC to track Support cases at our company and we're using a pretty stock Case tab. When editing the Case details, upon saving the record, the Last Modified date is updated as expected. However, the support engineers are very fond of using a related list - Case Comments to continually add comments to the case. They like that each Comment is encapsulated by itself (as opposed to a giant scrolling textbox) which keeps track of who when and what was happening. However, they'd like the Case Detail last modified date to be updated each time a comment is updated or created.
 
In talking with Basic support at SFDC, they didn't think this was possible. One solution that I could think of is to write some sort of scheduled job outside (like .NET) of SFDC that periodically checks all the cases and then update the last modified date of the Case detail if the max(last modified) field of any related comment is greater than the last modified date of the case detail. However, before going this route, I was wondering if there was another method that others have used that I haven't found in my (so far in vain) searching on the web.
I'm also questioning if I can/should be able to directly modify the last modified date field in the case details table in sfdc.
 
Thanks in advance,
Frank.
  • February 22, 2008
  • Like
  • 0

Hi all,

 

I'm trying to create an email template for to send lead information to our partner (who is not in SFDC).  I can create everything I need but one of the requirements is that we show the partner all the campaigns that are associated with the lead as well as the more pedantic Name, Address, Phone, etc.

 

I've tried adding {!CampaignMember.Campaign Name} and {!Campaign.Name}both to no avail (they're just blank). How can I specify a one-to-many join on CampaignMember to Lead?

 

Is VF the only way to achieve this (ugh I am a total VF newbie)? I can think of umpteen ways to solve this with .NET integration but I'd like to try to keep it simple and within SFDC.

 

Thanks very much.

 

  • February 17, 2010
  • Like
  • 0

A little backgroud:

 

We have a field - Qualifying_Campaign__c that is required to be filled when a lead's status changes from Prospect to Qualified Lead. The reason for the field is that a Lead may be a member of multiple Campaigns but the Qualifying Campaign is the campaign that actually qualified the change of status.

 

Now, we have a partner that pushes leads to us using a Web To Lead form. They are correcly setting the CampaignId on the Web to Lead form. The requirement is then that since these leads are prequalified, I need to set the Status to Qualified Lead when the Lead comes into SFDC and I need to set the Qualifying_campaign__c to the CampaignId that was pushed.

 

So I wrote a trigger that accomplishes this.

 

trigger Lead_AfterInsert on Lead (after insert) {

List<Id> leadids = new List<Id>();

for (Lead thisLead : Trigger.New)

leadids.add(thisLead.Id);

Lead[] leads = [select Id, LeadSource, Status, Qualifying_Campaign__c, custom_lead_src__c, (Select CampaignId from CampaignMembers order by CreatedDate limit 1) from Lead where Id in :leadids];

 

for (Lead l : leads) {

//Do the eTrigue thang

 if (l.LeadSource == 'eTrigue' && l.Custom_Lead_Src__c != '') {

try {System.debug(

'CampaignMembers isEmpty = ' + l.CampaignMembers.IsEmpty()); if (!l.CampaignMembers.IsEmpty()) {

l.LeadSource = l.Custom_Lead_Src__c;

l.Status = 'Qualified Lead';

l.Qualifying_Campaign__c = l.CampaignMembers[0].CampaignId;

update l;

}

} catch (DMLException e) {System.debug(

'DMLException Occurred:' + e.getMessage());

}

}

}

}

 

So all is well until it comes time to write the TestClass for this trigger. How the heck do I simulate the insertion of the Lead with a CampaignId?

 

If I create the Lead, and then insert the CampaignMember record, the Lead_AfterInsert trigger will already have fired!

 

Any ideas would be much appreciated.

 

Frank.

  • August 07, 2009
  • Like
  • 0

I'm trying to deploy some stuff from my Enterprise Sandbox (developer sandbox not full copy) to my DE account so that I can do some even more isolated development but the deployment dialog tells me that my custom objects are not deployable.

 

Can anyone shed some light on this? I've tried it on a couple of different machines with the same result.

I'm running Eclipse Europa 3.3.2 with the latest force.com ide on Windows XP.

 

Here's a screen shot my of deployment.

 

 

Thanks much,

Frank

I need to set a Lookup field's value in Salesforce.com's Lead object and am using the code below.

The Qualifying_Campaign__c field is a custom lookup field related to the Campaign object and the value I'm setting is the correct Campaign Id for the campaign which we want to set. A describesObject call to look at the Lead object reveals that the Qualifying_Campaign__c is indeed updateable.

The code snippet comes from a function called by an Outbound Message from SFDC on Lead creation for certain types of Leads.

The Exception I get when I call the update function  is as follows and I can't quite understand why it's happening...

Error message from catch (Exception ex)
A duplicate value was specified for field 'Id' in object 'Lead', duplicate value '00Q7000000OXbm5EAD' prior value '00Q7000000OXbm5EAD'

heh?!
Other troubleshooting showed that my code works when updating the OwnerID in the same way. The error only occurs when updating the Qualifying_Campaign__c field.
 
Thanks in advance,
Frank.
 
Code Snippet
QueryResult qrLead = RunQuery("select Id, Qualifying_Campaign__c from Lead where Id='" + leadid + "'");
sObject lead = null;
if (qrLead != null && qrLead.size > 0)
{
 lead = qrLead.records[0];
 //Update to new username
 //ld.Id = leadid;
 //lead.Any[1].InnerText = uid;
 lead.Any[1].InnerText = "70170000000KheRAAS";
 
 SaveResult[] saveResult = null; ;
 try
 {
  saveResult = _sfdcService.update(new sObject[] { lead });
 }
 catch (Exception ex)
 { }
 if (saveResult[0].success)
  res = 1;
 else {
  _log.Error(String.Format("Failure in UpdateLead: {0}", saveResult[0].errors[0].message));
  _log.Error("Lead ID : " + leadid + "      RSM : " + rsm);
 }
}
else
 res= 0;
 
  • November 27, 2008
  • Like
  • 0
We currently use SFDC to track Support cases at our company and we're using a pretty stock Case tab. When editing the Case details, upon saving the record, the Last Modified date is updated as expected. However, the support engineers are very fond of using a related list - Case Comments to continually add comments to the case. They like that each Comment is encapsulated by itself (as opposed to a giant scrolling textbox) which keeps track of who when and what was happening. However, they'd like the Case Detail last modified date to be updated each time a comment is updated or created.
 
In talking with Basic support at SFDC, they didn't think this was possible. One solution that I could think of is to write some sort of scheduled job outside (like .NET) of SFDC that periodically checks all the cases and then update the last modified date of the Case detail if the max(last modified) field of any related comment is greater than the last modified date of the case detail. However, before going this route, I was wondering if there was another method that others have used that I haven't found in my (so far in vain) searching on the web.
I'm also questioning if I can/should be able to directly modify the last modified date field in the case details table in sfdc.
 
Thanks in advance,
Frank.
  • February 22, 2008
  • Like
  • 0