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
DorababuDorababu 

how to auto populate contact name in opportunities when using person account.

HI Friends,

I am working on person accounts.

For detail page of Accounts I have two custom VF pages. I have opportunity as a related list on detail page of Person account. When i click the 'new opportunity'  button on the related list I am redirected to Opportunity creation page(also a custom VF page). Here, on Opportunity creation page, Account name is auto populated while contact name is not. In case of person Acc. as acc. name and contact name are same, the contact name should also be autopopulated. How can I achieve this? How can i write java script code for the button on (opportunity)related list of Account, which is a standard button.


Please help me with any good solution.

 

Thanks in advance

 

asish1989asish1989

HI

You can create custom button in opportunity object type must be list type and choose behaivour as execute in javascript.

then add that button pagelayout.

here I am sharing some javascript code for that button

 

{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}

var idsToDelete = {!GETRECORDIDS( $ObjectType.Contact )};
var deleteWarning = 'Are you sure you wish to delete '+
idsToDelete.length + ' contacts?';

if (idsToDelete.length && (window.confirm(deleteWarning))) {
sforce.connection.deleteIds(idsToDelete,
function() {navigateToUrl(window.location.href);} ) ;


}
else if (idsToDelete.length == 0) {
alert("Please select the contacts you wish to delete.");
}

 

If this post answers your questions please mark it as solved and give kudos for this post if it helps you.

 

Thanks