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
NasirNasir 

how to create a record from one object to other object by using java script and web services.

Hi 

 

I have  object called "Sales order" and "week management".Week management have some records.i have created a button on week management called "create sales order".When a user  select a record in weekmanagement by clicking it,and then click "Create sales order"  then record in a sales order record is created in sales order object.

 

I have to do this by using java script coz i had choosed use javascript to create that button. and i have to use web services.

 

How can i do that.

 

Plz help

 

Nasir

Best Answer chosen by Admin (Salesforce Developers) 
CLKCLK

Hi Nasir,

 

write the creating record logic into button click javascript only.

if you are using web service for doig that , then you can directaly call web service from javascript.

All Answers

CLKCLK

do it using apex.

call <action:function> on onClick of that button through javascript.

Then use future method to make webservice call & make @future(callout=true).

NasirNasir

i had created a custom button in week management object and used CONTENT SOURCE=ON CLICK JAVA SCRIPT,

 

then i had used this code :

 

 

{!requireScript("/soap/ajax/19.0/connection.js")}
{!requireScript("/soap/ajax/19.0/apex.js")}
var records = {!GETRECORDIDS($ObjectType.TMS__Week_Management__c)}; 
if (records[0] == null) { 
  alert("Please select at least one row") 
else { 
  for (var n=0; n<records.length; n++) { 
    alert(records[n]);
    
    sforce.connection.sessionId = '{!$Api.Session_ID}';
    var returnValue = sforce.apex.execute( "weekmanage", "pick", {box:records[n]});
  }
}

 

after this i created a apex classfor web services...

 

now when i click the record in week management and click the button sales order its should create a record in the sales order object.

 

Plz help

CLKCLK

then whats problem r u facing right now?

NasirNasir

i want to write a controller for the web services.I am not able to write it.

 

Can u please help me doin that.

 

Thanks

 

NAsir

CLKCLK

Hi Nasir,

 

write the creating record logic into button click javascript only.

if you are using web service for doig that , then you can directaly call web service from javascript.

This was selected as the best answer
NasirNasir

Hi ,

 

I have done the same way as u had mentioned.

 

But  can i use VF and apex controller to do the same.I will use extension and will create a button and will write the custom logic.

 

Thanks

 

NAsir

CLKCLK

yes you can

and actually its a better way of doing it.

Create VF Page & use it on Custom button you have created on object.