You need to sign in to do that
Don't have an account?
Mahitha Vaka 9
creating java button in lightning componenets
Hi, Can some one please help me on creating lightning button and class for this below Java script button.
Thanks in advance.
{!requireScript("/soap/ajax/18.0/connection.js")}
{!requireScript("/soap/ajax/18.0/apex.js")}
{!requireScript("/js/functions.js")}
Opportunity = new sforce.SObject("Opportunity");
// Populate the ID and the fields we're updating.
Opportunity["Id"] = "{!Opportunity.Id}";
// Get the related account name
var accId = "{!Opportunity.AccountId}";
var oppProducer = "{!Opportunity.Producer__c}";
var oppResource = "{!Opportunity.Resouce__c}";
var oppDept = "{!Opportunity.Department__c}";
var oppCat1 = "{!Opportunity.Cat1__c}";
var oppCat2 = "{!Opportunity.Cat2__c}";
var oppOppType = "{!Opportunity.Business_Unit__c}";
var oppOffice = "{!Opportunity.Office__c}";
var oppSentToSagita = "{!Opportunity.Send_To_Sagitta__c }";
var oppStatus = "{!Opportunity.Approval_Status__c}";
function validateopp() {
var query = "Select Name, Sic, BillingStreet, BillingCity, BillingState from account where id = '" + accId + "'";
result = sforce.connection.query(query);
records = result.getArray("records");
// alert("Account name:" + records[0]);
var errT = "The following information must be completed before sending an account to Sagitta: ";
var errAdditional="";
if ((records[0]).Name == null || (records[0]).Name == "") {
errAdditional += "Account Name, ";
}
if (oppProducer == null || oppProducer == "") {
errAdditional += "Producer, ";
}
if ((records[0]).BillingStreet == null || (records[0]).BillingStreet == "") {
errAdditional += "Primary Street, ";
}
if ((records[0]).BillingCity == null || (records[0]).BillingCity == "") {
errAdditional += "City, ";
}
if ((records[0]).BillingState == null || (records[0]).BillingState == "") {
errAdditional += "State, ";
}
if ((records[0]).Sic == null || (records[0]).Sic == "") {
errAdditional += "SIC Code, ";
}
if (oppResource == null || oppResource == "") {
errAdditional += "Resource Assignment, ";
}
if (oppOppType == "Employee Benefits Services"){
if (oppCat2 == null || oppCat2 == "") {
errAdditional += "CAT2, ";
}
}
else{
if (oppCat1 == null || oppCat1 == "") {
errAdditional += "CAT1, ";
}
}
if (oppOffice == null || oppOffice == "") {
errAdditional += "Office, ";
}
if (oppDept == null || oppDept == "") {
errAdditional += "Department";
}
if (errAdditional == "" && oppStatus=="Approved") {
updateopp();
alert('Account successfully sent to Sagitta');
}else{
if (oppStatus!="Approved") {
alert('Opportunity cannot be sent to Sagitta since it is currently not approved');
}else{
errT += errAdditional;
alert(errT);
}
}
}
function updateopp(){
Opportunity["Send_To_Sagitta__c"] = "true";
// Try to update the object.
saveResults = sforce.connection.update([Opportunity]);
if(saveResults[0].errors != null)
alert(saveResults[0].errors.message);
// Refresh the page.
window.top.location.href = window.top.location.href;
}
try{
if (oppSentToSagita == "true") {
alert('Account is already in Sagitta. Thanks.');
}else{
validateopp();
}
}
catch(Exception){
// alert("Error: "+Exception);
}
Thanks in advance.
{!requireScript("/soap/ajax/18.0/connection.js")}
{!requireScript("/soap/ajax/18.0/apex.js")}
{!requireScript("/js/functions.js")}
Opportunity = new sforce.SObject("Opportunity");
// Populate the ID and the fields we're updating.
Opportunity["Id"] = "{!Opportunity.Id}";
// Get the related account name
var accId = "{!Opportunity.AccountId}";
var oppProducer = "{!Opportunity.Producer__c}";
var oppResource = "{!Opportunity.Resouce__c}";
var oppDept = "{!Opportunity.Department__c}";
var oppCat1 = "{!Opportunity.Cat1__c}";
var oppCat2 = "{!Opportunity.Cat2__c}";
var oppOppType = "{!Opportunity.Business_Unit__c}";
var oppOffice = "{!Opportunity.Office__c}";
var oppSentToSagita = "{!Opportunity.Send_To_Sagitta__c }";
var oppStatus = "{!Opportunity.Approval_Status__c}";
function validateopp() {
var query = "Select Name, Sic, BillingStreet, BillingCity, BillingState from account where id = '" + accId + "'";
result = sforce.connection.query(query);
records = result.getArray("records");
// alert("Account name:" + records[0]);
var errT = "The following information must be completed before sending an account to Sagitta: ";
var errAdditional="";
if ((records[0]).Name == null || (records[0]).Name == "") {
errAdditional += "Account Name, ";
}
if (oppProducer == null || oppProducer == "") {
errAdditional += "Producer, ";
}
if ((records[0]).BillingStreet == null || (records[0]).BillingStreet == "") {
errAdditional += "Primary Street, ";
}
if ((records[0]).BillingCity == null || (records[0]).BillingCity == "") {
errAdditional += "City, ";
}
if ((records[0]).BillingState == null || (records[0]).BillingState == "") {
errAdditional += "State, ";
}
if ((records[0]).Sic == null || (records[0]).Sic == "") {
errAdditional += "SIC Code, ";
}
if (oppResource == null || oppResource == "") {
errAdditional += "Resource Assignment, ";
}
if (oppOppType == "Employee Benefits Services"){
if (oppCat2 == null || oppCat2 == "") {
errAdditional += "CAT2, ";
}
}
else{
if (oppCat1 == null || oppCat1 == "") {
errAdditional += "CAT1, ";
}
}
if (oppOffice == null || oppOffice == "") {
errAdditional += "Office, ";
}
if (oppDept == null || oppDept == "") {
errAdditional += "Department";
}
if (errAdditional == "" && oppStatus=="Approved") {
updateopp();
alert('Account successfully sent to Sagitta');
}else{
if (oppStatus!="Approved") {
alert('Opportunity cannot be sent to Sagitta since it is currently not approved');
}else{
errT += errAdditional;
alert(errT);
}
}
}
function updateopp(){
Opportunity["Send_To_Sagitta__c"] = "true";
// Try to update the object.
saveResults = sforce.connection.update([Opportunity]);
if(saveResults[0].errors != null)
alert(saveResults[0].errors.message);
// Refresh the page.
window.top.location.href = window.top.location.href;
}
try{
if (oppSentToSagita == "true") {
alert('Account is already in Sagitta. Thanks.');
}else{
validateopp();
}
}
catch(Exception){
// alert("Error: "+Exception);
}