• JohnPCutler
  • NEWBIE
  • 0 Points
  • Member since 2007

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 7
    Replies
I am trying the following code in an OnClick SControl

Code:
{!requireScript("/soap/ajax/11.1/connection.js")}

sforce.debug.trace = true;
sforce.debug.log("Hello World");

and I am getting a browser error which says "log is not defined"

When I use Firebug to inspect connections.js I see the following code ...

Code:
sforce.internal.Debug = function() {

...

this.log = function(str) {
  this.println(str, "print");
}

sforce.debug = new sforce.internal.Debug();

 I am confused. Shouldn't this be working? This stopped working in an old SControl I built, so I am sure something has changed.

Any help would be appreciated

John

 

Hello Folks

I am very new to this, but was able to cobble together an S-Control to acommplish the following:

Case Roles are very powerful, but often underutilized. Make a button that ...
  1. Creates a new Case
  2. Populates the accountId, ContactId, Status, and Origin fields of the new Case with information from the current Contact (or Person Account)
  3. Creates a new Case Role with the current Contact (or Person Account)
  4. Navigates to the edit Case screen
Ideally, we would use Apex Code for this, but we are a non profit with donated licenses (enterprise)

What can I do to make this more robust, catch errors, etc? Any critiques would be helpful (and may help others)

Code:
makeCaseAndRolls("Customer")
function makeCaseAndRolls(Role) {
 var c = new sforce.SObject("Case");
 var account = "{!Account.Id}";

 if ({!Account.IsPersonAccount}==true) {

   // Ids argument for retrieve only takes an array, so we create an array called accounts
   var accounts=new Array()
   accounts[0] = account

   // Use retrieve to get the Account object, so we can find its PersonContactID
   result = sforce.connection.retrieve("PersonContactId,Id", "Account", accounts)

   var contact = result[0].PersonContactId;

   } else {
     var contact = "{!Contact.Id}"
   }

 // Set field values
 c.AccountId = account;
 c.ContactId = contact;
 c.Status = "New";
 c.Origin = "Phone";

 var caseResult = sforce.connection.create([c]);

 var cr = new sforce.SObject("CaseContactRole");

 // Set field values for Case Role
 cr.ContactId = contact
 cr.Role = Role;
 cr.CasesId = caseResult[0].id;

 // Create Role
 var roleResult = sforce.connection.create([cr]);

 // Redirect
 window.parent.location.href = "/" + caseResult[0].id + "/e—retURL=%2F" + caseResult[0].id
}

 


I have a best practices question. Before I go too far down one particular road, I was hoping to get some feedback from those with more experience.

The Requirement
We are a non-profit dealing with complex cases involving many players. Therefore, it is highly likely that the person calling (or emailing) the advocate will NOT be listed as the primary contact on the Case. For example, in some cases, you might have a social worker, caretaker, client, and/or family member call with information and questions. We intend to use the Case Roles related list for Cases, but this has the disadvantage of only being accessible via reports. It can't show up as a related list in related objects.

Ideally, we'd have a "Case Relationships" object that could appear as a related list on Accounts / Person Accounts / and Contacts. This would allow the advocate to field a call, locate the contact, and from the related list find the case.

I have tried two approaches thus far ...

S-Control
Create an S-Control that simulates a related list. The S-Control queries Case Contact Roles, and displays all the records with a matching account / contact Id. This works well, but has some major drawbacks. First, it doesn't appear with other related lists. Second, it has none of the functionality enjoyed by related lists, and I am hesitant to make a bulky S-Control.

Apex Trigger and Custom Object
Writing the Apex code for the trigger was pretty easy, even for a beginner. I basically created a new Case Roles object with Account, Contact, and Case lookup fields, as well as Case Subject and Role fields. I automatically populate the account field before  update. I wrote another trigger on the case object to sync the Case subject with a custom field on the Case Roles object after update. On Case delete, all the child Case Roles were also deleted.

Case_Roles__c
-- Account (always set to Contact's account)
-- Subject (always set to Case's subject. On case update, all child Case_Roles are updated)
-- Case
-- Contact
-- Role
-- Role Notes

This had the major advantage of acting like a related list, and having all the normal functionality of a custom object. That said, I am inexperienced, this will require an upgrade to Unlimited (I wonder if SF will allow this since the licenses were donated), and deploying triggers seems pretty complicated. Basically, even though I was able to accomplish this in my Developer edition, I wonder if Apex is over my head.

Any thoughts? Sorry for the long post. I guess this all stems from a non-standard requirement, but I am interested to see how other people might approach this.

Thanks

John



Hello. I am making some progress with Apex, but I am stumped on the following. My understanding is that you can use SOQL for loops to do batch update / delete (200 records at a time). In my example below, I looping once for each record. When I try to adapt the code based on the docs (Apex Language Reference), I get an error saying I need an SObject List object. Any help would be appreciated ...   how do I convert this SOQL for loop to do batch processing?

And yes, I realize that there is a Case Contact Roles related list, but the client requires related lists on the Account and Contact objects displaying Case roles. :smileyhappy:

Code:
// we check to see if the subject has changed
if (casenew.subject != caseold.subject) {

  // we try to batch update all case_roles with this case id
  // this seems to do one at a time, instead of 200 at a time
  for(case_role__c cr: [select id,case_subject__c from case_role__c where case__c = :casenew.id ]){
    cr.case_subject__c = casenew.subject;
    update cr;
  } 
}
Message Edited by JohnPCutler on 08-25-200703:48 PM

Message Edited by JohnPCutler on 08-26-200707:04 PM

Hello, and thanks in advance for your time. I have created an S-Control to implement a specialized related list. The list shows the Contact's (or Person Account's) roles on all Cases. This is an advantage over the current Cases related list which only shows Cases for whom the Contact is a the primary contact on the case.

The Problems
1) I am forced to display this S-Control in a field section, which doesn't look right. You'd expect to find this in a related list. Is there any way to display the S-Control as a related list instead?

2) I am forced to specifiy a height for the S-Control. This height is static. This means that I either need to turn on the scrollbar for the Iframe (which is ugly, and requires more user interaction and time), or make the Iframe unnaturaly high.

Any thoughts? Thanks again.

John

Update. I think this is a hack, but it works.

....
    resizeIframe(line_height);
    }
  }

    function resizeIframe(height) {
      var id = new String(window.name);
      var iframeElement = parent.document.getElementById(id);
      iframeElement.style.height = height + "px"
 }



Message Edited by JohnPCutler on 08-25-200712:01 AM

Message Edited by JohnPCutler on 08-25-200712:19 AM

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 best practices question. Before I go too far down one particular road, I was hoping to get some feedback from those with more experience.

The Requirement
We are a non-profit dealing with complex cases involving many players. Therefore, it is highly likely that the person calling (or emailing) the advocate will NOT be listed as the primary contact on the Case. For example, in some cases, you might have a social worker, caretaker, client, and/or family member call with information and questions. We intend to use the Case Roles related list for Cases, but this has the disadvantage of only being accessible via reports. It can't show up as a related list in related objects.

Ideally, we'd have a "Case Relationships" object that could appear as a related list on Accounts / Person Accounts / and Contacts. This would allow the advocate to field a call, locate the contact, and from the related list find the case.

I have tried two approaches thus far ...

S-Control
Create an S-Control that simulates a related list. The S-Control queries Case Contact Roles, and displays all the records with a matching account / contact Id. This works well, but has some major drawbacks. First, it doesn't appear with other related lists. Second, it has none of the functionality enjoyed by related lists, and I am hesitant to make a bulky S-Control.

Apex Trigger and Custom Object
Writing the Apex code for the trigger was pretty easy, even for a beginner. I basically created a new Case Roles object with Account, Contact, and Case lookup fields, as well as Case Subject and Role fields. I automatically populate the account field before  update. I wrote another trigger on the case object to sync the Case subject with a custom field on the Case Roles object after update. On Case delete, all the child Case Roles were also deleted.

Case_Roles__c
-- Account (always set to Contact's account)
-- Subject (always set to Case's subject. On case update, all child Case_Roles are updated)
-- Case
-- Contact
-- Role
-- Role Notes

This had the major advantage of acting like a related list, and having all the normal functionality of a custom object. That said, I am inexperienced, this will require an upgrade to Unlimited (I wonder if SF will allow this since the licenses were donated), and deploying triggers seems pretty complicated. Basically, even though I was able to accomplish this in my Developer edition, I wonder if Apex is over my head.

Any thoughts? Sorry for the long post. I guess this all stems from a non-standard requirement, but I am interested to see how other people might approach this.

Thanks

John



Hello. I am making some progress with Apex, but I am stumped on the following. My understanding is that you can use SOQL for loops to do batch update / delete (200 records at a time). In my example below, I looping once for each record. When I try to adapt the code based on the docs (Apex Language Reference), I get an error saying I need an SObject List object. Any help would be appreciated ...   how do I convert this SOQL for loop to do batch processing?

And yes, I realize that there is a Case Contact Roles related list, but the client requires related lists on the Account and Contact objects displaying Case roles. :smileyhappy:

Code:
// we check to see if the subject has changed
if (casenew.subject != caseold.subject) {

  // we try to batch update all case_roles with this case id
  // this seems to do one at a time, instead of 200 at a time
  for(case_role__c cr: [select id,case_subject__c from case_role__c where case__c = :casenew.id ]){
    cr.case_subject__c = casenew.subject;
    update cr;
  } 
}
Message Edited by JohnPCutler on 08-25-200703:48 PM

Message Edited by JohnPCutler on 08-26-200707:04 PM

Hello, and thanks in advance for your time. I have created an S-Control to implement a specialized related list. The list shows the Contact's (or Person Account's) roles on all Cases. This is an advantage over the current Cases related list which only shows Cases for whom the Contact is a the primary contact on the case.

The Problems
1) I am forced to display this S-Control in a field section, which doesn't look right. You'd expect to find this in a related list. Is there any way to display the S-Control as a related list instead?

2) I am forced to specifiy a height for the S-Control. This height is static. This means that I either need to turn on the scrollbar for the Iframe (which is ugly, and requires more user interaction and time), or make the Iframe unnaturaly high.

Any thoughts? Thanks again.

John

Update. I think this is a hack, but it works.

....
    resizeIframe(line_height);
    }
  }

    function resizeIframe(height) {
      var id = new String(window.name);
      var iframeElement = parent.document.getElementById(id);
      iframeElement.style.height = height + "px"
 }



Message Edited by JohnPCutler on 08-25-200712:01 AM

Message Edited by JohnPCutler on 08-25-200712:19 AM