You need to sign in to do that
Don't have an account?
JohnPCutler
Help making S-Control more robust (code included)
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 ...
What can I do to make this more robust, catch errors, etc? Any critiques would be helpful (and may help others)
Code:
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 ...
- Creates a new Case
- Populates the accountId, ContactId, Status, and Origin fields of the new Case with information from the current Contact (or Person Account)
- Creates a new Case Role with the current Contact (or Person Account)
- Navigates to the edit Case screen
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 }