• RiverChaser
  • NEWBIE
  • 30 Points
  • Member since 2007

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 23
    Replies
Hi All,

I'm having difficulty figuring out how to test my trigger so that I can put it in my production environment. My trigger is simple and checks to see if a field has been changed and if so it updates another field with the current date and time like so:

trigger PIFDateUpdate on Account bulk (before update) {
for (Account an : Trigger.new) {for (Account ao : Trigger.old) {
if (an.PIF_Available_Balance__c ao.PIF_Available_Balance__c) {
an.As_of_2__c = System.Now();
}
}
}
}

However, I can't figure out how to get 75% test coverage for this. Any thoughts?
I've turned on field history for selected fields in the Account and Contact objects, as well as in a couple of custom objects.

Now I need to access the history from an external application. Custom objects are easy (and slick): just read and process the contents of the object's history table, such as Membership__History.

I can find no such history tables for Account and Contact. Some standard objects have tables with names like CaseHistory, but not Account and Contact. I also don't see where it might be hiding within the objects themselves, but it's certainly possible that I've not used the right tool or query.

How can I get access to Account and Contact history?

Thanks,
Don
I am using the SingleemailMessage object to send an update email to a Contact. As you can see in the snippet below, I'm using a template for the email. This is in a custom button on the View Contact form, and contactId contains the current Contact's Id. That part is all working great.

Code:
var email = new sforce.SingleEmailMessage();

email.replyTo = "memberservices@example.com";

var a = new Array(1);
a[0] = contactId;

email.targetObjectId = a;
email.setBccSender = true;
email.setSenderDisplayName = "Member Services";
email.saveAsActivity = true;
email.templateId = templateID;
var result = sforce.connection.sendEmail([email]);

The problem is that I'm trying to use the setBccSender and setSenderDisplayName properties, but both give me an error "<property> invalid at this location".

I realize that some properties are not available when using a template, but neither of these are indicated as such in the Winter 08 Apex API reference document.

Or does "at this location" mean something different? This is the Unlimited Edition of SalesForce, so does something need to be turned on?

Thanks,
Don

P.S. Thanks, SalesForce, for allowing the use of templates with the SingleEmailMessage object!
I have a custom Membership object that has a master-detail relationship with Account, and a lookup relationship with Contact (an Account owns the membership and a Contact uses it). I have a list of Membership objects on the Account page as well as the Contact page, so that a user can edit a membership from either location.

The question I have concerns when a user adds a new Membership object from either the Account or Contact page. When they add a new instance from Account, SF automatically fills in the Account name. That's fine. From the Contact page, it fills in the Contact name. Also fine.

But from the Contact page, I'd also like the Contact's Account be the default for the Account field, but it is blank. A Contact only has one Account, so it is unambiguous which Account should be used.

But I can't find a way to populate the Account field on the New Membership page. A trigger won't work, since those fire when the user tries to save the new Membership object. I looked to set the default value for the Account field, but that isn't an option for master-details with standard objects.

How can I do this? Is an s-control my only option?

Thanks for any suggestions or pointers!
Don
I need to do a mass delete of records for a custom object. I'm running into a problem with "Too many SOQL queries" though. I have a trigger on the custom object and that is causing me to exceed the limit.

Is there a way to suspend triggers for an object for an operation like this? There is an Is Active property on the trigger, but I see no way to change the setting.

Interestingly, there is no Edit/Delete link on the trigger when I look at the custom object, and when I look at the code there is no option to edit it. Is this because I created it using the Apex Toolkit for Eclipse? Is there a way to make it inactive using the toolkit?

My only idea at this point would be to delete the trigger and its tests and class methods, do the delete, then add the code back. But that is going to be a mess that I'd rather not deal with.

By the way, I'm doing the deletion through the Apex Data Loader. I don't seen any option around the problem in that tool either. Have I missed something?

What options do I have?

Thanks!
Don
I have some custom Apex Code that runs this query, which works beautifully:

Code:
SELECT Id, Expiration_Date__c, Product__r.Name 
from Membership__c
WHERE Contact__r.Id = :contact.Id
AND Product__r.Name = 'Membership'
ORDER BY Expiration_Date__c DESC Limit 1
I'm now trying to run this same query in sforce Explorer, in preparation for doing a similar query using the Apex API from a custom application. The only change I've made is to include a string for the ContactID:

Code:
SELECT Id, Expiration_Date__c, Product__r.Name 
from Membership__c
WHERE Contact__r.Id = 'XXXXXXXXXXXXXXXXXX'
AND Product__r.Name = 'Membership'
ORDER BY Expiration_Date__c DESC Limit 1
But Explorer reports an error: "Query failed: MALFORMED_QUERY: SOQL statements can't query related data."

Why can I query related data in one usage but not another?

Thanks for any insight!
Don
 



 

I'm starting to plan the integration of our Web site with SalesForce. For the Apex API, what login should I use? The only option seems to be my login, something I'm not thrilled about. My login has a far higher privilege level than is needed by the integration code.

Are there any other options? Does SalesForce provide an integration login?

Thanks,
Don
When I send emails using MassEmailMessage, it shows up fine in the Mass Email Monitoring page in SalesFroce. But the Mass Email Name field in the list is blank, and I don't see any properties of either MassEmailMessage or its base class for setting the name.

Is there a way to set the value of this field using the Apex API?

Thanks,
Don
I have a custom Membership object that has a master-detail with Account, a lookup relationship with Contact, and a lookup relationship with Product. This is because a membership is owned by an account and is non-transferable, while a Contact uses the membership but is transferable to other employees of the Account. And there are various types of memberships available, thus the lookup to Product.

When I create a new Membership from an Account, the Account is populated, good. The user has to select a contact from the Account's employees, no problem.

Creating a new Membership from a Contact, the Contact field is populated. Also good. But in the latter case, I'd like to populate the Account, which is, of course, the Contact's Account. How can I do this? A trigger won't work, because they fire when the record is being saved. There are no default fields for master-detail relationships. I can't figure out how to run any code in the New Membership window to do this.

Is an s-control the answer? Even if I figure out how to make that work, I'd prefer that the user not have to click a button for something that can only be one thing, the Contact's Account.

Also, how can I put a default Product in that field?

Thanks for any ideas!
Don
I am having trouble sending email using MassEmailMessage. At this point I am only sending a single email to one contact, but MassEmailMessage seems to be the only way to programmatically send an email using an existing template.

I'm using the code below in an s-control attached to a button on the Contact form, and everything seems to run fine. The alert() pops up a message that says {success:'true',}, and the resulting page says Email sent! as shown in the code. If I look at Setup | Monitoring | Mass Email Monitoring, the send is shown there as successful. But the email never arrives. (For testing, I'm sending it to myself. No, it's not in my spam filter.)

I am able to use SingleEmailMessage with no problem.

What am I doing wrong? Thanks for any pointers!

Don

Code:
<html>
   <head>
   <script src="/soap/ajax/10.0/connection.js" type="text/javascript"></script>
   <script>
      var contactId = "{!Contact.Id}";
      function sendEmail() {
            var result = "";
            try {
                        var templResp = sforce.connection.query("select id from emailtemplate where name = 'Welcome!'");
                        var templateID = templResp.getArray("records")[0].Id;
                        var mass = new sforce.MassEmailMessage();
            
                        mass.replyTo = "donkiely@computer.org";
                        mass.subject = "Mass Email from SF!";
                        var a = new Array(1);
                        a[0] = contactId;
                        mass.targetObjectIds = a;
                        mass.saveAsActivity = true;
                        mass.templateId = templateID;
                        var sendMailRes = sforce.connection.sendEmail([mass]);
                        
                        alert(sendMailRes);

                     output.innerHTML = "Email sent! " + "result: " + result;
            } catch(error) {
                        output.innerHTML = error + ":result = " + result;
            }
      }
   </script>
   <body onload="sendEmail()">
      <div id="output"></div>
   </body>
</html>

Message Edited by RiverChaser on 09-09-2007 12:30 PM

I am trying to get my head around all the ways that you can run Apex code. I think I went off on wrong tangents reading about all the wonderful things that Apex Code can do, making some wrong assumptions about it. For example, I initially thought that I could run it directly in response to a button click without an intermediate s-control.

As near as I can tell, there are exactly two ways to cause Apex code to run:
  • As part of a trigger, either code directly in the body of the trigger or by calling class code, or
  • Through the Apex Web Services API, using the sforce.apex.execute method to call WebService type methods.
The second item allows use through s-controls (including the AJAX toolkit) and external applications using Java or .NET or whatever.

Is my understanding right? Are there any other ways to execute Apex Code?

Thanks!
Don
There seems to be a bug in the Create New Trigger wizard in the toolkit. When I selected the checkboxes for four events After Insert, After Update, After Delete, and After Undelete, I ended up with the method signature below. Note the lack of a comma between the first two events. Easy enough to fix manually, but I assume that it is not the design behavior.

trigger temptemp on Membership__c (after deleteafter undelete, after insert, after update) {

Is there another place I should report stuff like this? I didn't see anything obvious on the toolkit's info page or release notes. Or is here in the forum where it should be?

Don
I just had a weird problem when creating a new trigger on a custom object in my testing sandbox. I fired up Eclipse and opened my SF project, and all was well. I had added a couple of custom fields to my Contact object, but the schema was updated to reflect that. I had no error messages at that point.

Then I created a new trigger on the custom Membership__c object, setting it to fire After Insert, After Update, After Delete, After Undelete. The purpose of the trigger is to update the custom fields in the Contact object, making no changes to the child (lookup) Membership object.

But then the toolkit gave me an error, preventing me from saving the new trigger to the sandbox: "Conflict found while saving trigContactMembershipInfo.tgr. Remote instance has been updated since last save or sync. Use the Synchronize Perspective to resolve the conflict." I checked in SF, and the new trigger didn't yet exist on the Membership object.

So I tried explicitly sync'g, but the error wouldn't go away. When I deleted the new trigger, everything sync'd fine.

I have admin rights in SF and can author Apex code, so that's not the problem.

The only thing that finally worked was to create it using the toolkit wizard as a Before Insert trigger, then manually change the signature for the events I needed. Then I could save the trigger, no problem.

Any thoughts about why this is happening?

Thanks,
Don
Users can select a template when sending an email to a contact. Why can I not seem to the same thing with the Apex API? Only the MassEmailMessage has the templateId property.

Or is there something I'm missing? I'd love to be able to use a template with SingleEmailMessage.

Thanks!
Don
I have created an email template that reads both standard and custom data from the Contact object; no problem there.

But I also have a custom Membership object that I need to grab an expiration date from. The Available Merge Fields in the content editors show the Membership object and the field I need, and I can copy and pasted it into the content perfectly.

I have two questions:

1) The expiration date is not being pulled into the field in the template when I send an email. The Contact does definitely have a Membership object associated with it, and it has an expiration date. Why might it not be apearing?

2) A Contact could have multiple Membership objects as s/he renews over time. I want the data pulled from the latest Membership object only, the one with the latest expiration date. I don't see any way to do that in the email template editor. How can I do that?

Thanks!
Don
I've turned on field history for selected fields in the Account and Contact objects, as well as in a couple of custom objects.

Now I need to access the history from an external application. Custom objects are easy (and slick): just read and process the contents of the object's history table, such as Membership__History.

I can find no such history tables for Account and Contact. Some standard objects have tables with names like CaseHistory, but not Account and Contact. I also don't see where it might be hiding within the objects themselves, but it's certainly possible that I've not used the right tool or query.

How can I get access to Account and Contact history?

Thanks,
Don
I've got a project that is a production org. When I try to make custom field changes I get this:

Unable to perform save on all files: AxisFault: INVALID_OPERATION: rollbackOnError option must be true on a production org

Any clue on what this means and how to get around it?

Thanks!

Steve
I have a custom Membership object that has a master-detail relationship with Account, and a lookup relationship with Contact (an Account owns the membership and a Contact uses it). I have a list of Membership objects on the Account page as well as the Contact page, so that a user can edit a membership from either location.

The question I have concerns when a user adds a new Membership object from either the Account or Contact page. When they add a new instance from Account, SF automatically fills in the Account name. That's fine. From the Contact page, it fills in the Contact name. Also fine.

But from the Contact page, I'd also like the Contact's Account be the default for the Account field, but it is blank. A Contact only has one Account, so it is unambiguous which Account should be used.

But I can't find a way to populate the Account field on the New Membership page. A trigger won't work, since those fire when the user tries to save the new Membership object. I looked to set the default value for the Account field, but that isn't an option for master-details with standard objects.

How can I do this? Is an s-control my only option?

Thanks for any suggestions or pointers!
Don
I need to do a mass delete of records for a custom object. I'm running into a problem with "Too many SOQL queries" though. I have a trigger on the custom object and that is causing me to exceed the limit.

Is there a way to suspend triggers for an object for an operation like this? There is an Is Active property on the trigger, but I see no way to change the setting.

Interestingly, there is no Edit/Delete link on the trigger when I look at the custom object, and when I look at the code there is no option to edit it. Is this because I created it using the Apex Toolkit for Eclipse? Is there a way to make it inactive using the toolkit?

My only idea at this point would be to delete the trigger and its tests and class methods, do the delete, then add the code back. But that is going to be a mess that I'd rather not deal with.

By the way, I'm doing the deletion through the Apex Data Loader. I don't seen any option around the problem in that tool either. Have I missed something?

What options do I have?

Thanks!
Don
I have some custom Apex Code that runs this query, which works beautifully:

Code:
SELECT Id, Expiration_Date__c, Product__r.Name 
from Membership__c
WHERE Contact__r.Id = :contact.Id
AND Product__r.Name = 'Membership'
ORDER BY Expiration_Date__c DESC Limit 1
I'm now trying to run this same query in sforce Explorer, in preparation for doing a similar query using the Apex API from a custom application. The only change I've made is to include a string for the ContactID:

Code:
SELECT Id, Expiration_Date__c, Product__r.Name 
from Membership__c
WHERE Contact__r.Id = 'XXXXXXXXXXXXXXXXXX'
AND Product__r.Name = 'Membership'
ORDER BY Expiration_Date__c DESC Limit 1
But Explorer reports an error: "Query failed: MALFORMED_QUERY: SOQL statements can't query related data."

Why can I query related data in one usage but not another?

Thanks for any insight!
Don
 



 

I'm starting to plan the integration of our Web site with SalesForce. For the Apex API, what login should I use? The only option seems to be my login, something I'm not thrilled about. My login has a far higher privilege level than is needed by the integration code.

Are there any other options? Does SalesForce provide an integration login?

Thanks,
Don
When I send emails using MassEmailMessage, it shows up fine in the Mass Email Monitoring page in SalesFroce. But the Mass Email Name field in the list is blank, and I don't see any properties of either MassEmailMessage or its base class for setting the name.

Is there a way to set the value of this field using the Apex API?

Thanks,
Don
I am having trouble sending email using MassEmailMessage. At this point I am only sending a single email to one contact, but MassEmailMessage seems to be the only way to programmatically send an email using an existing template.

I'm using the code below in an s-control attached to a button on the Contact form, and everything seems to run fine. The alert() pops up a message that says {success:'true',}, and the resulting page says Email sent! as shown in the code. If I look at Setup | Monitoring | Mass Email Monitoring, the send is shown there as successful. But the email never arrives. (For testing, I'm sending it to myself. No, it's not in my spam filter.)

I am able to use SingleEmailMessage with no problem.

What am I doing wrong? Thanks for any pointers!

Don

Code:
<html>
   <head>
   <script src="/soap/ajax/10.0/connection.js" type="text/javascript"></script>
   <script>
      var contactId = "{!Contact.Id}";
      function sendEmail() {
            var result = "";
            try {
                        var templResp = sforce.connection.query("select id from emailtemplate where name = 'Welcome!'");
                        var templateID = templResp.getArray("records")[0].Id;
                        var mass = new sforce.MassEmailMessage();
            
                        mass.replyTo = "donkiely@computer.org";
                        mass.subject = "Mass Email from SF!";
                        var a = new Array(1);
                        a[0] = contactId;
                        mass.targetObjectIds = a;
                        mass.saveAsActivity = true;
                        mass.templateId = templateID;
                        var sendMailRes = sforce.connection.sendEmail([mass]);
                        
                        alert(sendMailRes);

                     output.innerHTML = "Email sent! " + "result: " + result;
            } catch(error) {
                        output.innerHTML = error + ":result = " + result;
            }
      }
   </script>
   <body onload="sendEmail()">
      <div id="output"></div>
   </body>
</html>

Message Edited by RiverChaser on 09-09-2007 12:30 PM

Hi All,

I'm having difficulty figuring out how to test my trigger so that I can put it in my production environment. My trigger is simple and checks to see if a field has been changed and if so it updates another field with the current date and time like so:

trigger PIFDateUpdate on Account bulk (before update) {
for (Account an : Trigger.new) {for (Account ao : Trigger.old) {
if (an.PIF_Available_Balance__c ao.PIF_Available_Balance__c) {
an.As_of_2__c = System.Now();
}
}
}
}

However, I can't figure out how to get 75% test coverage for this. Any thoughts?
Users can select a template when sending an email to a contact. Why can I not seem to the same thing with the Apex API? Only the MassEmailMessage has the templateId property.

Or is there something I'm missing? I'd love to be able to use a template with SingleEmailMessage.

Thanks!
Don