function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
dotnetericdotneteric 

Creating an OpportunityTeamMember record when changing Opportunity ownership

Hello.  I am hoping someone can help me out.  I created an S-Control that changes the ownership of an opportunity, we call it "referring the opportunity".  The problem we are having is in keeping the team members of the opportunity when the ownership is changed via the S-Control.  The team members get deleted when the ownership is changed.  If I could at least add the previous owner as a team member after ownership has changed (which in turn is after the team members get deleted), we could bear with it.  But, I can't even do that because after the ownership of the opportunity changes, and the logic that creates the OpportunityTeamMember record runs, the logged in user doesn't have rights to create the record because they are not the owner of the opportunity anymore. 
 
How can I change the owner of the Opportunity without losing my team members?  If there is no way to prevent losing the team members, how can I at least create one team member record (the person who is the previous owner; who is referring the opportunity to the other person)?
 
Thanks in advance.
 
-E.R.
The_FoxThe_Fox
Hello,

just thinking out loud, why not "saving" in your scontrol the team members changing the owner and repplaing team mebers after that

Regards
dotnetericdotneteric
That results in an error since the logged in user is no longer the owner of the opportunity.  It would throw an error like the following:
 
StatusCode: INSUFFICIENT_ACCESS_CROSS_REFERENCE_ENTITY
Message:  insufficient access rights on cross-reference id

Message Edited by dotneteric on 11-07-2006 05:36 AM

michaelforcemichaelforce
Code:
<form  action="/setup/own/entityowneredit.jsp" id="editPage" name="editPage" method="POST" >

<input type="hidden" name="cancelURL" id="cancelURL" value="/[Opportunity ID]"><input type="hidden" name="id" id="id" 

value="[Opportunity ID]">

<input type="hidden" name="retURL" id="retURL" value="/ [Opportunity ID] ">

<input type="hidden" name="save_new_url" id="save_new_url" value="/setup/own/entityowneredit.jsp—retURL=%2F[Opportunity ID]">

<input type="hidden" name="p2_lkid" id="p2_lkid" value="000000000000000">

<input type="hidden" name="p2_lkold" id="p2_lkold" value="null">

<input type="hidden" name="p2_lktp" id="p2_lktp" value="005">

<input type="hidden" name="p2_lspf" id="p2_lspf" value="0">

<input type="hidden" name="p2_mod" id="p2_mod" value="0">

<input  maxlength="80" type="text" onchange="document.getElementById('p2_lkid').value='';document.getElementById('p2_mod').value='1';" 

id="p2" size="20" name="p2"><a href="JavaScript: openLookup('https://na1.salesforce.com/_ui/common/data/LookupPage–

lknm=p2&lkfm=editPage&lktp=' + document.getElementById('p2_lktp').value,670,document.getElementById('p2_mod').value,'&lksrch=' + 

escapeUTF(document.getElementById('p2').value),'maxw')" title="Owner Lookup (New Window)" onclick="setLastMousePosition(event)" 

id="p2_lkwgt"><img src="https://na1.salesforce.com/s.gif" alt="Owner Lookup (New Window)"  class="lookupPopup"></a>


<input  value="1" type="checkbox" id="p10" name="p10" /><label for="p10">Keep Sales Team</label>

<input  value="1" type="checkbox" id="p3" name="p3" /><label for="p3">Send Notification Email</label></td></tr>

<input value=" Save "  class="btn" type="submit" title="Save" name="save">

<input value="Cancel"  class="btn" type="submit" title="Cancel" name="cancel">

</form>

 
Above I have pasted the simplified form which salesforce.com displays when manually submitting an owner change.  The "keep sales team" field (id=p10) is the one you wish to leverage.  It should then be possible to populate the fields in this form and submit it within an app.
 
This is just a quick idea I came up with... never actually done it myself.  Hope it helps.
 
-Michael
dotnetericdotneteric
Thanks Michael.  It's a coincidence, but I was actually just trying that.  I set all the values of the form fields and submit my form to the same "action" page (/setup/own/entityowneredit.jsp) as the sfdc form, but it just arrives at the "change owner" page with the fields prepopulated based on the values I submitted my form with.  The owner does not change (I'm assuming "p2_lkid" is the new owner's id).  I tried changing the values of some of the other form elements ("pd_mod" to 1, "p2_lspf" to 1), but no luck.
customDevcustomDev
Salesforce allows only one individual to be assigned a single role in the opportunity team for a given opportunity. here is how we have done it -
1. delete record for the individual and opportunity for the role to be assigned
2. insert individual/opportunity with the assigned role
 
In your case, you want to add the individual deleted in step 1 back into the team. You should be able to do that, however the role will need to be different.
 
Hope this helps.
dotnetericdotneteric

I was able to get my form to submit to the salesforce.com change ownership page.  The reason why it wasn't submitting is because I had document.editPage.submit() instead of document.editPage.save.click().  I didn't really want to do it like that since a change in salesforce will cause the functionality to break, but it is a short term solution until the winter or subsequent release when we can develop a solution that we have more control over.

The code now does the following: 
1) Modifies custom fields of the opportunity record
2) Adds the current owner to the team members of the opportunity
3) Submits my form to the salesforce.com page which changes the ownership of the opportunity (there is a field that when set to 1 maintains the team members)

Here is what I took from the saleforce.com form and what I added:

document.getElementById("p2_lkid").value = beanUser.get("Id");
........

document.editPage.save.click();
........

function
SetFormValues() {
document.getElementById("id").value = OPPORTUNITY_ID;
document.getElementById(
"retURL").value = "javascript&colon;window.top.location.replace(\\\'/" + OPPORTUNITY_ID + \\\');";
document.getElementById(
"save_new_url").value = "/setup/own/entityowneredit.jsp?retURL=%2F" + OPPORTUNITY_ID;
}
.......

<form action="/setup/own/entityowneredit.jsp" id="editPage" name="editPage" method="POST">
<input type="hidden" name="id" id="id">
<input type="hidden" name="retURL" id="retURL">
<input type="hidden" name="save_new_url" id="save_new_url">
<input type="hidden" name="p2_lkid" id="p2_lkid">
<input value="R" type="hidden" id="p11R" name="p11" /> <!-- gives previous owner read access to the opportunity -->
<input value="1" type="hidden" id="p3" name="p3" /> <!-- email notification -->
<input value="1" type="hidden" id="p10" name="p10" /> <!-- keep team members -->\
<input value=" Save " style="visibility:hidden;" class="btn" type="submit" title="Save" name="save">
</form>


Works rather nicely. 

Message Edited by dotneteric on 11-08-2006 05:47 AM

Message Edited by dotneteric on 11-08-2006 05:49 AM

michaelforcemichaelforce

That's good stuff... I'm going to bookmark that one.  Glad you got it working.