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
Nirmal9114Nirmal9114 

Create Record when Related list custom buttom is clicked

My requirement is:

Create a button on the Key Staff related list within the Opportunity Record called "Add Key Staff."

When clicked, the button should insert Key Staff records identical to those on the Account, EXCEPT:
- The Account lookup should not be populated
- The Opportunity lookup should be populated with the Opportunity record id:

Please Suggest

ManojSankaranManojSankaran
Dear Nirmal,

Below are the steps that you have to follow 
1. Create a List button in the child object
2. Create VF Page and Make is available for standard set controller. (add your logic to create a new record in this page controller).
3. Create an action function with return type page reference and then call this method from the page action tag.
4. Add this to the List Button you have created and add this to page layout.


If you still need more clarity or procedure. Let me know.


Thanks
Manoj S 
Nirmal9114Nirmal9114
H Manoj,

I dont want to create the VF page. my Req is when i click on ADD KEY STAFF the record shoulld be created with the infomation from account :

i have written this JS code: PLEASE HELP

{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')}

getDate = function(dateObj){
var day = dateObj.getDay() < 9 ? '0'+dateObj.getDay() : dateObj.getDay();
var month = dateObj.getMonth() < 9 ? '0'+dateObj.getMonth() : dateObj.getMonth();
 
return dateObj.getFullYear()+'-'+month+'-'+day;
}

var KeyStaff = new sforce.SObject('Opportunity');
 
KeyStaff.Name = '{!Key_Staff__c.Name} ;
//KeyStaff.Accenture_Resource__c = '{!contact.Id}';
//KeyStaff.Grant__c = '{!Opportunity.Id}';
 
result = sforce.connection.create([KeyStaff]);
 
if(result[0].success == 'true'){
    alert('An New KeyStaff with Name - ' + KeyStaff.Name + ' was Created Successfully.');
}
ManojSankaranManojSankaran
Dear Nirmal,

Below code will create a new opportunity and relate that to an account. You can make use of this code. if you wish. Also it will refresh the screen after creating the new opportunity.

Create a list button in opportunity. copy the below code and add the list button in opportunity related list of account and click the newly created button you will be able to understand how this code/javascript works.


Thanks
Manoj S

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js" )}
var connection = sforce.connection;

var newopportunity= new sforce.SObject("Opportunity");
newopportunity.Name = "my new opportunity";
newopportunity.StageName="Prospecting";
newopportunity.CloseDate=new Date();
newopportunity.AccountId="{!Account.Id}";
alert('{!Account.Id}');
result = sforce.connection.create([newopportunity]);
alert(result );
location.reload();
Nirmal9114Nirmal9114

Hi manoj,

Thanks for quick help.

i modified the code accordingly and i am getting this error
User-added image

my code:

{!REQUIRESCRIPT("/soap/ajax/22.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/22.0/apex.js" )}
var connection = sforce.connection;

var KeyStaff= new sforce.SObject("Key_Staff__c");
KeyStaff.Name = "new KeyStaff";
KeyStaff.Accenture_Resource__c="abcd";
KeyStaff.Grant__c="{!Opportunity.Id}";
KeyStaff.AccountId="{!Account.Id}";
alert('{!Account.Id}');
result = sforce.connection.create([KeyStaff]);
alert(result );
location.reload();