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
denissisdenissis 

Ideas Plsss

I have an object called "Lease".When i create a record in Lease it gets saved.I should have a button "Generate Office " in the record which automatically creates an office record which is exactly same as record created earlier in Lease In " office" all the fields which are there in "lease" are present and also they are formula fields I am in a confusion as i didnot understand d req properly or how do i need approach Do i need to visual force page for the button
Dirk GronertDirk Gronert

What about a button on the page layout which executes javascript (remote APEX)?? This could be a sample:

 

{!requireScript("/soap/ajax/15.0/apex.js")}
{!requireScript("/soap/ajax/15.0/connection.js")}
var oID = sforce.apex.execute("OfficeGenerator","generateOffice",{Idnt:"{!Id }"});
if(oID == 'failed'){
alert("An error has occured, the Office could not be created! Please contact your administrator.");
} else {
alert("Generate Office failed");
}

 

And here the is the APEX class:

 

global with sharing class OfficeGenerator {
    webservice static String generateOffice(String Idnt){
//query the info you need for office creation
        Lease__c l = [Select id, name from Lease__c where Id=:Idnt limit 1];
Office__c o = new Office__(lease__c=l.id);
// do what you want .... with the office
        insert o;
        return 'true';
    }

 

I've wrote the code down without testing ist .... so pls excuse any typos ....

 

Cheers,

--dirk

vivek12345vivek12345

Hello,

 

Why don't you try a trigger, put a check box on the object if you check it and save it, trigger will create office record.

 

Let me know if you need any other information on this.

 

Thanks