You need to sign in to do that
Don't have an account?
Angelina Muddamalle
Accept Button on Lead Detail Page
I have a requirement where the accept button should be available on the lead detail page. I came across the javascript custom button code shared in this link https://salesforce.stackexchange.com/questions/167037/accept-button-on-lead-detail-page which works well for admins and other manager profiles but is giving issues with Sales rep profiles.
Any suggestions what the issue might be?
Any suggestions what the issue might be?
I think ,It's issue come because of role hierarchy or sales rep profile does not permission to update the record.
var LeadObj = new sforce.SObject("Lead");
var previousOwner = "{!Lead.OwnerId}";
var currentOwner = "{!$User.Id}";
LeadObj.Id = "{!Lead.Id}";
LeadObj.OwnerId = "{!$User.Id}";
//if previousOwner is queue
var ownerRec = sforce.connection.query("SELECT owner.type, ownerid, Id from Lead WHERE owner.type= 'Queue' AND OwnerId='"+ previousOwner + "' AND Id='" + LeadObj.Id + "'");
var records1 = ownerRec.getArray('records');
if(records1 !=null && records1.length>0)
{
//currentOwner is part of queue
var currentOwnerRec = sforce.connection.query("SELECT g.UserOrGroupId From GroupMember g WHERE groupId ='" + previousOwner + "' AND g.UserOrGroupId ='" + currentOwner + "'");
var records2 = currentOwnerRec.getArray('records');
if(records2 !=null && records2.length>0)
{
var result = sforce.connection.update([LeadObj]);
location.reload();
}
else
{
alert("You cannot take this Lead because you are not part of the queue");
}
}
else
{
if(previousOwner == currentOwner)
{
alert("You are already the Lead Owner ");
}
else
{
var result = sforce.connection.update([LeadObj]);
location.reload();
}
}
Put alert on line where you are updating the record and than click on button and check where is the value not come.
{!REQUIRESCRIPT("/soap/ajax/31.0/connection.js")}
var LeadObj = new sforce.SObject("Lead");
var previousOwner = "{!Lead.OwnerId}";
var currentOwner = "{!$User.Id}";
LeadObj.Id = "{!Lead.Id}";
LeadObj.OwnerId = "{!$User.Id}";
//if previousOwner is queue
var ownerRec = sforce.connection.query("SELECT owner.type, ownerid, Id from Lead WHERE owner.type= 'Queue' AND OwnerId='"+ previousOwner + "' AND Id='" + LeadObj.Id + "'");
var records1 = ownerRec.getArray('records');
if(records1 !=null && records1.length>0)
{
//currentOwner is part of queue
var currentOwnerRec = sforce.connection.query("SELECT g.UserOrGroupId From GroupMember g WHERE groupId ='" + previousOwner + "' AND g.UserOrGroupId ='" + currentOwner + "'");
var records2 = currentOwnerRec.getArray('records');
alert('......'+records2);
if(records2 !=null && records2.length>0)
{
var result = sforce.connection.update([LeadObj]);
alert(result+'......');
location.reload();
}
else
{
alert("You cannot take this Lead because you are not part of the queue");
}
}
else
{
if(previousOwner == currentOwner)
{
alert("You are already the Lead Owner ");
}
else
{
alert('......');
var result = sforce.connection.update([LeadObj]);
alert(result+'......');
location.reload();
}
}