+ Start a Discussion
Dman100Dman100 

help with s-control and possible governor limits

I'm trying to debug an old s-control that has been working fine, but recently encountered an error.

 

Here is the s-control code:

 

<html> <head> <script type="text/javascript" src="/js/functions.js"></script> <script src="/soap/ajax/12.0/connection.js"></script> <script language="javascript1.2" type="text/javascript"> // Update Related Records function updateRelatedRecords() { //Get Records - Contact Roles for Account var AccountId = "{!Account.Id}"; var ParentId="{!Account.ParentId}"; var childAccounts; var parentContactRoles; var childContactRoles; var hasParentContactRoles = false; var hasChildAccounts = false; var strSQL; var result; //If the Account is a child Account which means it has ParentId then //nothing should happen if(ParentId != ''){ alert("This is a child Account"); } else { strSQL="Select Id, AccountId,Role,ContactID From AccountContactRole where AccountId='{!Account.Id}'"; result = sforce.connection.query(strSQL); parentContactRoles = result.getArray("records"); //If the Parent Account has no Contact Roles then it should //not do anything No update or insert to anything not even Child records if(parentContactRoles.length==0){ alert("There are no Contact Roles for this Account '{!Account.Name}'"); } else { hasParentContactRoles = true; } //If the Parent Account has no child Accounts then //do not do anything either strSQL="Select Id,Name from Account where ParentId='{!Account.Id}'"; result = sforce.connection.query(strSQL); childAccounts = result.getArray("records"); if(childAccounts.length==0){ alert("There are no child Accounts for '{!Account.Name}'"); } else { hasChildAccounts = true; } if(hasParentContactRoles && hasChildAccounts){ var newContactRoles = []; var contactRoleExists = false; var i,j,k; for (i in childAccounts){ //Get Contacts Roles for each child account strSQL="Select Id, AccountId, Role, ContactId From AccountContactRole where AccountId=" + "'" + childAccounts[i].Id + "'"; result = sforce.connection.query(strSQL); childContactRoles = result.getArray("records"); for(j in parentContactRoles){ contactRoleExists = false; for(k in childContactRoles){ if(parentContactRoles[j].Role == childContactRoles[k].Role) {contactRoleExists = true;} } if(!contactRoleExists){ var newContactRole = new sforce.SObject("AccountContactRole"); newContactRole.AccountId = childAccounts[i].Id; newContactRole.ContactId = parentContactRoles[j].ContactId; newContactRole.Role = parentContactRoles[j].Role; newContactRoles.push(newContactRole); } } } if(newContactRoles.length > 0){ result = sforce.connection.create(newContactRoles); document.write(newContactRoles.length + " new Contact Roles were created in child accounts."); } else { document.write("No Contact Roles assigned. All child accounts already have all roles defined."); } } } } </script> </head> <body onload="updateRelatedRecords()";> </body> </html>

 

I believe, the s-control is erroring out when it gets to this section:

 

 

for (i in childAccounts){ //Get Contacts Roles for each child account strSQL="Select Id, AccountId, Role, ContactId From AccountContactRole where AccountId=" + "'" + childAccounts[i].Id + "'"; result = sforce.connection.query(strSQL); childContactRoles = result.getArray("records");

 

 

I just get a blank window that opens and it just times out and nothing happens.  No errors, but the s-control does not update the child accounts.

 

This only happens with one account.  The s-control has been working fine.  It seems like a governor limit issue?

 

I'm not overly proficient with javascript.  Is there a way I can display the error and see what is happening?  If it is a governor limit issue, is there a way to get around the limit?

 

Thanks for any help.

aalbertaalbert

It won't be an issue with governor limits since I don't believe you are executing any apex code.

 

I recommend using the Firefox plugin "FireBug" to troubleshoot javascript. 

 

Dman100Dman100

Firebug shows the following error when I hit the page:

 

ActiveXObject is not defined:

 

this.connection = new ActiveXObject('Microsoft.XMLHTTP');

 

Any ideas?