• hpatel
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 6
    Replies
I wrote the following trigger.

Code:
trigger Create_CampaignMember_For_New_Leads on Lead (after insert) {
 
 List <CampaignMember> cm = new list<CampaignMember>();
 
 for(Lead L : Trigger.new) {
  
  String cname = L.leadsource;
  
  List <Campaign> c = [select id, name from Campaign where name = :cname limit 1];
  
  if(!c.isEmpty()){
   CampaignMember cml = new CampaignMember();
   cml.campaignid = c[0].id;
   cml.leadid = l.id;
   cm.add(cml);
  }
 }
 
 if(!cm.isEmpty()){
  insert cm;
 }
}

 
The code adds a Campaign Member record automatically if it can find a Campaign with a name matching the Lead Source name. 

All is great when I use the application and with web-to-lead.  However, License Manager submitted a Lead/License today and I got the following email.

Code:
Apex script unhandled trigger exception by user/organization: 0053000000125N9/00D300000007gjY

Create_CampaignMember_For_New_Leads: compiling trigger body

caused by: line 15, column 29: sObject type 'Campaign' is not supported.

 
That user id is one of the License Manager users that gets created behind the scenes.  The end result is that the License record gets created, but the Lead does not.

Is there anything I can do to make this get fixed?  I was thinking I could edit the API Access Restrictions on the License Manager installed package to give access to Campaigns.  Will that help?

If that won't help, do I need to edit my Apex Code to do a user lookup to make sure it's not an LMA user?  Or can I do a describeGlobal type of query to make sure the user has access to Campaign?  If that's the route to take, I could use a little help.

Thanks.
  • April 20, 2008
  • Like
  • 0
I have the new Eclipse toolkit and it's all up to date.  When using it to edit s-controls, I always get an error that I don't have enough test coverage and it won't save it to the server ("Test coverage of selected Apex Class and Trigger is 0%, at least 75% test coverage is required"). 

The only way I can get the s-Control to work is by copy/pasting the code into the s-Control text box in the Salesforce UI.  Then it works fine.  This is not a good long-term solution for development.

Not sure if I am on the right track, but this issue only seems to occur in 2 orgs, both of which have the License Manager Application (LMA) installed.  Other than what comes in the LMA, I don't have any Apex Code in my org.  I am able to save s-Controls in other orgs I have.

Ideas?  Things I can check?
  • April 07, 2008
  • Like
  • 0