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
Sangeetha EmpoweredSangeetha Empowered 

**URGENT && CRITICAL ****** - Visualforce for converting javascript to Lightning button -

<apex:page standardController="Opportunity">
        <apex:includeScript value="../../soap/ajax/20.0/connection.js"/>
    <script>
    sforce.connection.sessionId='{!GETSESSIONID()}';
var oppObj = new sforce.SObject("Opportunity");
var accCnt = sforce.connection.query("SELECT Id from Opportunity where accountid ='{!Opportunity.AccountId}' and recordtypeId = '0120J000000VFDN' ");
if(accCnt.size > 0){
oppObj.Id = '{!Opportunity.Id}';
oppObj.RecordTypeId = '0120J000000VFDS';
oppObj.stagename = 'Open';
var result = sforce.connection.update([oppObj]);
if (result[0].success=='false') {
alert(result[0].errors.message);
} else {

window.location = "/" + result[0].id + "/e" + "?retURL="+ result[0].id;
}
}else {
alert ('Please create a Parent Contract. Then convert this to Child Contract. Please close the pop-up window');
}
 </script>
</apex:page>

The above code works fine but i get popup with cancel button whih is not the present scope 

PLEASE HELP
Waqar Hussain SFWaqar Hussain SF
This is the default behavior of salesforce lightning buttons. You have created a VF page of your custom javascript button. 

When the button is clicko on lightning the VF page is opened in the popup with cancel button. 

try below code.
 
<apex:page standardController="Opportunity">
    <apex:includeScript value="../../soap/ajax/20.0/connection.js" />
    <script>
        sforce.connection.sessionId = '{!GETSESSIONID()}';
        var oppObj = new sforce.SObject("Opportunity");
        var accCnt = sforce.connection.query("SELECT Id from Opportunity where accountid ='{!Opportunity.AccountId}' and recordtypeId = '0120J000000VFDN' ");
        if (accCnt.size > 0) {
            oppObj.Id = '{!Opportunity.Id}';
            oppObj.RecordTypeId = '0120J000000VFDS';
            oppObj.stagename = 'Open';
            var result = sforce.connection.update([oppObj]);
            if (result[0].success == 'false') {
                alert(result[0].errors.message);
            } else {
                window.location.reload();
                //window.location = "/" + result[0].id + "/e" + "?retURL=" + result[0].id;
            }
        } else {
            alert ('Please create a Parent Contract. Then convert this to Child Contract. Please close the pop-up window');
        }
    </script>
</apex:page>

 
Waqar Hussain SFWaqar Hussain SF
Hi Sangeetha, 

Use below code. I am using apex controller instead of javascript.
<apex:page standardController="Opportunity" extensions="OppController" Action="{!UpdateOpportunity}">
    <apex:pagemessages ></apex:pagemessages>
</apex:page>
 
public class OppController{
    
    public opportunity opp;
    public OppController(ApexPages.StandardController controller) {
        List<String> fields = new List<String>();
        fields.add('AccountId');
        controller.addFields(fields);
        this.opp = (Opportunity)controller.getRecord();
    }

    public pageReference UpdateOpportunity(){
        
        list<Opportunity> accCnt = new list<Opportunity>();
        accCnt = [SELECT Id from Opportunity where accountid = :opp.AccountId and recordtypeId = '0120J000000VFDN'];
        if (accCnt.size() > 0) {
            opp.RecordTypeId = '0120J000000VFDS';
            opp.stagename = 'Open';
            try{
                update opp;
                ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.Info,'Record updated.');
                ApexPages.addMessage(myMsg);
                return null;
            }catch(exception ex){
                ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Error: '+ex.getMessage());
                ApexPages.addMessage(myMsg);
                return null;
            }
        } else {
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'Please create a Parent Contract. Then convert this to Child Contract. Please close the pop-up window');
            ApexPages.addMessage(myMsg);
            return null;
        }
    }

}

 
Sangeetha EmpoweredSangeetha Empowered
Hi Waqar

Still the popup comes :(
Waqar Hussain SFWaqar Hussain SF
Yes, You can not remove this popu, also Save and Cancel button from the standard layout in Lightning/Salesforce can not be removed.

These are the limitations from salesforce side.