You need to sign in to do that
Don't have an account?
ASF
how to change contact owner Name with related Account Owner Name
hi
First i create a button on Account. and if i click that button that related contacts owner name is changed as Account owner Name.
Please give me a solution for this...
Create a custom button on Account with
Display Type : Detail Page Button
Behaviour : Execute Javascript
and copy this code...
let me know if it doesnt work.
All Answers
Is the reason you are using a button for this because you don't intend for this to be done all of the time? The reason I ask is because if you intend to do this for Contacts based on some criteria, you can implement this through a trigger instead and remove the need for a user to manually click a button to effect the change.
Create a custom button on Account with
Display Type : Detail Page Button
Behaviour : Execute Javascript
and copy this code...
let me know if it doesnt work.
Thanks Mr.Naidu. Its Working.... Thank you so much.............
hi Mr.Naidu..
I have an another problem the same thing i want implement in campaign. I want create a button in Campaign. and if click that button i want to change the ownership of the campaign members. I tried your code. just modifying for campaign But i don't know how to make a query Because here i wnt to update three objects Contact Account and Lead. So i'm confused. If you Know please help me.....
This is the Modified code. Please tell me where did i make a mistake....
{!REQUIRESCRIPT("/soap/ajax/26.0/connection.js")}
var url = parent.location.href;
var AccId = "{!Account.Id}";
var CampId ="{!Campaign.Id}";
var CampOwnerId= "{!Campaign.OwnerId}";
var updateRecords = [];
var update_Cons = new sforce.SObject("Contact");
var result = sforce.connection.query("SELECT Id, Contact.OwnerId, Lead.OwnerId, campaignid FROM CampaignMember WHERE campaignid = "+CampId+"");
var recs = result.getArray("records");
if(confirm("Are you sure you want to update the name on related contacts?") )
{
for(var i = 0; i < recs.length; i++)
{
recs[i].Contact.OwnerId= CampOwnerId;
recs[i]. Lead.OwnerId= CampOwnerId;
recs[i].campaignid = CampOwnerId;
updateRecords.push(recs[i]);
}
var result = sforce.connection.update(updateRecords);
parent.location.href = url;
if(result[0].success == 'true')
{
alert("Related contacts updated successfully");
}
else
{
alert("Failed to update the related contacts");
}
}
Let me check the above code.. i will reply you shortly....
try this..