• Max Power
  • NEWBIE
  • 0 Points
  • Member since 2008

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

I've got an Apex trigger that I'm attempting to bulkify to handle multiple records.  Essentially what I want to do is to update a custom Number field on my Campaign records, which is a count of a number of Lead records that have a particular status (Note: Lead Status, not Campaign Member status), any time a Lead record is updated.

 

I did a proof of concept for a single record, using the following trigger:

 

trigger leadTrigger1 on Lead(after insert, after update, after delete) { CampaignMember cm = [select CampaignId from CampaignMember where LeadId = :Trigger.new[0].Id limit 1]; Campaign c = [select Id, name, Wastage__c from Campaign where Id = :cm.CampaignId limit 1]; Integer count = [select count() from CampaignMember where CampaignId = :cm.CampaignId and Lead.Status = 'Closed - Not Converted']; System.Debug( 'count = ' + count ); c.Wastage__c = (Double)count; update(c); }

 

 

This works great for one record, but it doesn't take into consideration updates of multiple Lead records that are possibly associated with different campaigns.  I'm attempting to write something to the effect of:

 

trigger leadTrigger1 on Lead(after insert, after update, after delete) { System.Debug( 'leadTrigger1 fired!' ); Set<Id> leadIds = new Set<Id>(); for( Lead l : Trigger.old ) leadIds.add(l.Id); for( Lead l : Trigger.new ) leadIds.add(l.Id); CampaignMember [] cms = [select CampaignId from CampaignMember where LeadId in :leadIds]; Set<Id> cIds = new Set<Id>(); for( CampaignMember cm : cms ) cIds.add( cm.CampaignId ); Campaign [] cList = [select Id, name, Wastage__c from Campaign where Id in :cIds]; Map<Id, Integer> counts = new Map<Id, Integer> = Some SOQL query that will give me a map of Ids and the counts associated with those Ids. for( Campaign c : cList ) { c.Wastage__c = (Double)counts.get(c.Id); update(c); } }

 

 

But I'm not having any luck coming up with a SOQL query to give me a map of the Ids with the count.  Can this be done?  Any help would be greatly appreciated.

 

Thanks in advance,

Max

I have a fairly stright forward problem, but I'm not sure how I should solve it.  Basically, I need a new custom field on the Campaign table that is a count of the number of leads that have a particular status.  Unfortunately, I can't simply create a Roll-Up Summary field on Campaigns, because it's not the master in a master-detail relationship.  In other words, I need a field on Campaigns that is essentially a count of the number of leads associated with that campaign that have a particular status.  How should I approach this?

 

The one possibility that I can see is that I could add a trigger that fires on insert/update/delete of leads that performs the appropriate SOQL query and updates the associated Campaign record(s); however, this seems a bit round-about, and my have to be done for all Campaign records every time that a Lead record is updated.  Is there a better way to do this?

 

Thanks in advance,

Max

 

I'm looking to create several packages for distribution on the AppExchange.  I intend to create a base package with core features that will be used by my other packages.  This will allow users to select only the packages that contain the features that they want, rather than giving them one large package with functionality that they will never use.

 

My problem is that in trying to develop one of the package extensions, I can't find any way to say that it depends on the core package.  I see in the Package Summary that Extension is set to 'no'.  How do I change this so that I can reference global Apex classes defined in the core package?  I'm currently unable to reference these classes in my extension package.

 

Thanks in advance,

Max

I'm currently in the process of developing my first application for publication on the AppExchange, and I've come across a bit of a problem.  Originally, the application was designed to perform some lookups using information found on an Account Detail Page.  The problem is, that some of the potential users for this application store the information required for the lookup in custom fields rather than in the default Account record fiels (that the majority of users will use).

 

Is there any way that I can set up my package to allow the user to specify where to get the information for the lookup (preferably when they install the package)?  Or will I be forced to do something less user friendly, like setting up a configuration object that stores the actual field names that should be used for the lookup?

 

Any help would be greatly appreciated.

 

Thanks in advance,

Max

I've developed an Apex web service that returns a custom Apex object.  The defined return type of the webservice method is an abstract base class, but the actual object returned by the method is an instance of one of two derived classes.  This webservice is being called from the onClick javascript for a custom button that I've added to one of my detail pages.  All the attributes that I want to be able to access are declared using webservice scope.  The problem that I've run into is that the javascript object that is returned as a result of the sforce.apex.execute( ) call contains only the webservice attributes from the derived class.  All of the webservice attributes from the base class are missing in the javascript object.
 
Why is this?  Is there something special that I have to do here?
 
To work around this issue, I have temporarily duplicated the data in both derived classes and simply used the base class as a makeshift interface (since Apex wouldn't let me return an interface from a webservice method), and this works, but I shouldn't have to do this.  Does anyone know how I can get this to work?  Any help would be greatly appreciated.
 
Thanks in advance,
Max
I'm writing an Apex application and I would like to use inheritance.  I read in the language reference that this is not enabled for all instances, and indeed when I tried to declare a virtual class in my instance, I got an error message from eclipse that said that virtual classes are not allowed in my instance.  My question is: How do I enable this feature?
 
As a follow up, if I use inheritance and then publish my application to the AppExchange, will anyone that uses this application need to enable inheritance on their instance as well, or is this required only on the development instance?
 
Thanks in advance,
Max
I'm using the AJAX toolkit to call an Apex web service method that returns an object.  I know the web service method works because I can test it using the System Log Console.  I wasn't really sure how this would work, so I added a call to 'debugger;' in my javascript function that calls sforce.apex.execute, so that I could examine what gets returned from the web service method.  But I just get an empty object back.
 
Can anyone help me out with this?  I'm at a loss as to what I can try, or why this isn't working.
 
Thanks in advance,
Max
Please forgive my lack of knowledge in this area, but this is my first Salesforce application.  I've created a custom object (called Cred) to store credentials to a 3rd party service.  This custom object has the standard Name field, a password field, and a lookup field that references the User object.  There should only be one entry in the Cred table per user, although there is nothing preventing multiple entries.  I have chosen to implement this way, as this does not require a modification to the User table.
 
I am implementing an Apex web service that will consume a 3rd party web service using the credentials associated with the current Salesforce user.  My problem is that I do not know how to retrieve this record.  I am passing the Apex web service the User.Id of the current user, and I would like to know how to write a SOQL statement to retrieve the Cred entry that references that User account.
 
Any help that you can provide would be greatly appreciated.
 
Thanks in advance,
Max
I'm attempting to write an application that will access a 3rd party service that requires a username and password (that is different than the Salesforce credentials).  Just to give a little background, this application is essentially an Apex web service that will invoke the appropriate methods to consume the 3rd party service, and update standard tables with the results it retrieves.  Seeing as how this is my first Salesforce application, I don't know what the best practices are for this type of an application.  For testing I've simply been using hard coded credentials in an Apex class, but this is not a viable solution once this application is made available on the AppExchange.
 
I would like to provide the user with some flexibility on how to do this, as they may have one username and password pair that are used by all members of that company, or want to use different credentials for all of their Salesforce users.
 
To me it seems I have the following options:
  1. I can extend the user table to add custom fields that store the new 3rd Party credentials.  I don't particularly care for this approach, as it doesn't seem like a good idea to extend such an essential, base table.
  2. I can provide a custom table that houses this information and associates it with a particular user.  This approach would require an administrator to set up all credentials as entries in the new table.
  3. I can simply allow the user to pass the credentials as arguments to the Apex web service.  This approach, although simplest from my perspective, requires the most work on the part of the administrator deploying the application, especially if they choose to use multiple different credentials.
Based on that, I believe that #2 is the best approach, but I wanted to get some opinions on this before I chose my implementation.  It is quite possible that I'm missing the best option.  Any help that can be offered would be greatly appreciated.
 
Thanks in advance.
Forgive me for asking, as I can see that this topic has a couple of threads dedicated to it, but I'm new to Apex (as of last Friday) and none of these threads discuss this issue to my liking.  I have a rather simple problem.  I'd like to do an external SOAP query when someone adds a new contact to Salesforce to see if I can automatically fill in a bunch of the fields in that record.  I already have a web service that will return this information, but seeing as how I am unable to do this from a trigger (I get the 'Callout from triggers are not currently supported' exception), I believe the following is my only option (correct me if I'm wrong):
 
  1. Create a new Outbound Message from Workflow
  2. Generate the WSDL associated with the outbound message
  3. Create a new web service on my server to handle the outbound message from Salesforce
  4. This new web service must query Salesforce if there is any additional information that I need because the Outbound Message is limited to sending the fields on the table for which the event is defined.
  5. Once I have this additional information I can then perform the actual web query that I wanted to perform from Salesforce, only now the response will come to my application.
  6. Once I have the response I can update the record accordingly, either by defining an Apex web service or by generating a SOAP message as defined by the WSDL for my particular instance.
If this is correct, then I actually find this quite surprising.  Why is this limitation in place?  This seems like a simple task that has been needlessly complicated by an artificial limitation.  I can't even define an Apex web service to handle the Outbound Message?  Why should I be forced to deploy a service to make this possible?
 
Any help or advice you can provide would be appreciated.
 
Thanks!

I've got an Apex trigger that I'm attempting to bulkify to handle multiple records.  Essentially what I want to do is to update a custom Number field on my Campaign records, which is a count of a number of Lead records that have a particular status (Note: Lead Status, not Campaign Member status), any time a Lead record is updated.

 

I did a proof of concept for a single record, using the following trigger:

 

trigger leadTrigger1 on Lead(after insert, after update, after delete) { CampaignMember cm = [select CampaignId from CampaignMember where LeadId = :Trigger.new[0].Id limit 1]; Campaign c = [select Id, name, Wastage__c from Campaign where Id = :cm.CampaignId limit 1]; Integer count = [select count() from CampaignMember where CampaignId = :cm.CampaignId and Lead.Status = 'Closed - Not Converted']; System.Debug( 'count = ' + count ); c.Wastage__c = (Double)count; update(c); }

 

 

This works great for one record, but it doesn't take into consideration updates of multiple Lead records that are possibly associated with different campaigns.  I'm attempting to write something to the effect of:

 

trigger leadTrigger1 on Lead(after insert, after update, after delete) { System.Debug( 'leadTrigger1 fired!' ); Set<Id> leadIds = new Set<Id>(); for( Lead l : Trigger.old ) leadIds.add(l.Id); for( Lead l : Trigger.new ) leadIds.add(l.Id); CampaignMember [] cms = [select CampaignId from CampaignMember where LeadId in :leadIds]; Set<Id> cIds = new Set<Id>(); for( CampaignMember cm : cms ) cIds.add( cm.CampaignId ); Campaign [] cList = [select Id, name, Wastage__c from Campaign where Id in :cIds]; Map<Id, Integer> counts = new Map<Id, Integer> = Some SOQL query that will give me a map of Ids and the counts associated with those Ids. for( Campaign c : cList ) { c.Wastage__c = (Double)counts.get(c.Id); update(c); } }

 

 

But I'm not having any luck coming up with a SOQL query to give me a map of the Ids with the count.  Can this be done?  Any help would be greatly appreciated.

 

Thanks in advance,

Max

I have a fairly stright forward problem, but I'm not sure how I should solve it.  Basically, I need a new custom field on the Campaign table that is a count of the number of leads that have a particular status.  Unfortunately, I can't simply create a Roll-Up Summary field on Campaigns, because it's not the master in a master-detail relationship.  In other words, I need a field on Campaigns that is essentially a count of the number of leads associated with that campaign that have a particular status.  How should I approach this?

 

The one possibility that I can see is that I could add a trigger that fires on insert/update/delete of leads that performs the appropriate SOQL query and updates the associated Campaign record(s); however, this seems a bit round-about, and my have to be done for all Campaign records every time that a Lead record is updated.  Is there a better way to do this?

 

Thanks in advance,

Max

 

I'm looking to create several packages for distribution on the AppExchange.  I intend to create a base package with core features that will be used by my other packages.  This will allow users to select only the packages that contain the features that they want, rather than giving them one large package with functionality that they will never use.

 

My problem is that in trying to develop one of the package extensions, I can't find any way to say that it depends on the core package.  I see in the Package Summary that Extension is set to 'no'.  How do I change this so that I can reference global Apex classes defined in the core package?  I'm currently unable to reference these classes in my extension package.

 

Thanks in advance,

Max

I am having difficulty uploading any managed packages (beta or released) on my developer's org after Winter '09 upgrade.  Every time I tried, the upload failed and the error message only mentioned "Your upload failed.  You will receive an e-mail containing additional information."  However, the email never arrived so I don't know what caused the upload failure.  The same package have been successfully uploaded many times before.
 
Any help is greatly appreciated.
 
I'm writing an Apex application and I would like to use inheritance.  I read in the language reference that this is not enabled for all instances, and indeed when I tried to declare a virtual class in my instance, I got an error message from eclipse that said that virtual classes are not allowed in my instance.  My question is: How do I enable this feature?
 
As a follow up, if I use inheritance and then publish my application to the AppExchange, will anyone that uses this application need to enable inheritance on their instance as well, or is this required only on the development instance?
 
Thanks in advance,
Max
I'm using the AJAX toolkit to call an Apex web service method that returns an object.  I know the web service method works because I can test it using the System Log Console.  I wasn't really sure how this would work, so I added a call to 'debugger;' in my javascript function that calls sforce.apex.execute, so that I could examine what gets returned from the web service method.  But I just get an empty object back.
 
Can anyone help me out with this?  I'm at a loss as to what I can try, or why this isn't working.
 
Thanks in advance,
Max
Please forgive my lack of knowledge in this area, but this is my first Salesforce application.  I've created a custom object (called Cred) to store credentials to a 3rd party service.  This custom object has the standard Name field, a password field, and a lookup field that references the User object.  There should only be one entry in the Cred table per user, although there is nothing preventing multiple entries.  I have chosen to implement this way, as this does not require a modification to the User table.
 
I am implementing an Apex web service that will consume a 3rd party web service using the credentials associated with the current Salesforce user.  My problem is that I do not know how to retrieve this record.  I am passing the Apex web service the User.Id of the current user, and I would like to know how to write a SOQL statement to retrieve the Cred entry that references that User account.
 
Any help that you can provide would be greatly appreciated.
 
Thanks in advance,
Max
I'm attempting to write an application that will access a 3rd party service that requires a username and password (that is different than the Salesforce credentials).  Just to give a little background, this application is essentially an Apex web service that will invoke the appropriate methods to consume the 3rd party service, and update standard tables with the results it retrieves.  Seeing as how this is my first Salesforce application, I don't know what the best practices are for this type of an application.  For testing I've simply been using hard coded credentials in an Apex class, but this is not a viable solution once this application is made available on the AppExchange.
 
I would like to provide the user with some flexibility on how to do this, as they may have one username and password pair that are used by all members of that company, or want to use different credentials for all of their Salesforce users.
 
To me it seems I have the following options:
  1. I can extend the user table to add custom fields that store the new 3rd Party credentials.  I don't particularly care for this approach, as it doesn't seem like a good idea to extend such an essential, base table.
  2. I can provide a custom table that houses this information and associates it with a particular user.  This approach would require an administrator to set up all credentials as entries in the new table.
  3. I can simply allow the user to pass the credentials as arguments to the Apex web service.  This approach, although simplest from my perspective, requires the most work on the part of the administrator deploying the application, especially if they choose to use multiple different credentials.
Based on that, I believe that #2 is the best approach, but I wanted to get some opinions on this before I chose my implementation.  It is quite possible that I'm missing the best option.  Any help that can be offered would be greatly appreciated.
 
Thanks in advance.
Forgive me for asking, as I can see that this topic has a couple of threads dedicated to it, but I'm new to Apex (as of last Friday) and none of these threads discuss this issue to my liking.  I have a rather simple problem.  I'd like to do an external SOAP query when someone adds a new contact to Salesforce to see if I can automatically fill in a bunch of the fields in that record.  I already have a web service that will return this information, but seeing as how I am unable to do this from a trigger (I get the 'Callout from triggers are not currently supported' exception), I believe the following is my only option (correct me if I'm wrong):
 
  1. Create a new Outbound Message from Workflow
  2. Generate the WSDL associated with the outbound message
  3. Create a new web service on my server to handle the outbound message from Salesforce
  4. This new web service must query Salesforce if there is any additional information that I need because the Outbound Message is limited to sending the fields on the table for which the event is defined.
  5. Once I have this additional information I can then perform the actual web query that I wanted to perform from Salesforce, only now the response will come to my application.
  6. Once I have the response I can update the record accordingly, either by defining an Apex web service or by generating a SOAP message as defined by the WSDL for my particular instance.
If this is correct, then I actually find this quite surprising.  Why is this limitation in place?  This seems like a simple task that has been needlessly complicated by an artificial limitation.  I can't even define an Apex web service to handle the Outbound Message?  Why should I be forced to deploy a service to make this possible?
 
Any help or advice you can provide would be appreciated.
 
Thanks!