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
anjuanju 

How to embed scontrol in visualforce?

Hi,
 
I have an scontrol page. I want to remove the scontrol and need to embed that scontrol in visualforce. Is it possible? If so then how?
I don't want to use -
 <apex:page>
         <apex:outputLink value="{!$SControl.HelloWorld}">Open theHelloWorld s-control</apex:outputLink>
</apex:page>
 
and
 
<apex:page>
        <apex:scontrol controlName="HelloWorld" />
</apex:page>
 
Is it possible to copy and paste scontrol in visualforce? Please help me.
mtbclimbermtbclimber
There are a few things in scontrols that are not supported in visualforce like address merge fields, pointing to merge fields on objects that are not really in context (Visualforce actually validates such things) and the automatic initialization of the AJAX toolkit.

Outside of the above, you should be able to copy and paste it in. HOWEVER, you should think twice before doing this. For one, what is the benefit? simply a named container around your scontrol?  For another, you are missing out on many of the benefits of visualforce vis-a-vis scontrols.

If you have some time you might want to watch this webinar recording
anjuanju
I know I will miss visualforce benefits if I am copying scontrol like that. But it is a big scontrol. And I am inseting records into 3 different objects from a single scontrol page.
 
For example -
I am displaying scontrol in CustObj1__c and the fields displaying are A (from CustObj1__c), B (CustObj1__c), C ,D.
When I click on Save button A&B feilds will be saved on CustObj1__c, B will be saved on CustObj_2__c and D will be saved on CustObj_3__c. There is no C & D fields in CustObj1__c.
 
I am a starter in visualforce. I tried a lot. But I didn't get any solution for this.
I saw the visualforce webinar. From there I got the idea that we can embed scontrol in visualforce.
 
I tried this way. I am not sure this is right. This is a sample code only. Please see my code and bug I am getting.
 
Code
<apex:page >
<html>
<head>
<script src="/soap/ajax/10.0/connection.js"></script>
<script language="Javascript" type="text/javascript">
function savevalues()
{
    var strServiceRequestId="{!$CurrentPageReference.parameters.id};"
   // var strServiceRequestId="{!Service_Request__c.Id}";
   var obj=new sforce.SObject("Service_Request__c");
   obj.Id=strServiceRequestId;      
   obj.Status__c="Closed";
   alert("000");
   try
   {
    var updateServiceRequestResult=sforce.connection.update([obj]);  
   }
   catch(e)
   {
    alert("Error in updating : "+e);
   }
}
</script>
</head>
<body>
<input type="button" onclick="savevalues();" value="Click" />
</body>
</html>
</apex:page>
 
Bug
 

Error in updating: {faultcode:sf:INVALID_SESSION_ID’,faultstring: INVALID_SESSION_ID’: invalid Session Id found in session Header: Illegal Session’, detail:{UnexpectedErrorFault:{exceptionCode: ‘INVALID_SESSION_ID’, exceptionMessage: ‘Invalid Sesssion ID found in sessionHeader: Illegal Session’,},},}

 

Please give me a solution for this.

 

 

 

aballardaballard
Take a look at the <apex:scontrol /> component which may be what you are looking for.
aballardaballard

 

Sorry, I see you said you don't want to use <apex:scontrol />.   Why not?

anjuanju

Is it possible to copy and paste my existing scontrol code in visual force tag - <apex:scontrol/>?

 If so then please tell me how can i do that. I tried but got some error.

 

mtbclimbermtbclimber
No you can not copy/paste anything into the body of the scontrol tag - that is not how that component works.

We'd be happy to help you if you would take a moment to answer the questions we have raised.  It's possible you are heading down a path that is going to cause you unnecessary pain which we are trying to help you avoid by qualifying a couple of things.

Can you please respond to aballard's question? I'd still like to know why you want to move this to a Visualforce page - what is the benefit you are looking for if you are just copying and pasting it?

Also, perhaps if you described the functionality of your scontrol you might get someone to respond with a basic Visualforce page that could get you started down the right path.


anjuanju

Actually we have an existing scontrol. It is a custom object new & edit page. Save button in the custom object we will update other 3 objects along with creation/updation of this record. It is a lengthy scontrol with so many validation rules. We have done this scontrol in Salesforce Standard CRM application.

 

Now we want to do this scontrol in Force.com(This app is a copy of the previous one). As per the requirement, we want to convert all scontrols to Visualforce (scontrols will be deleted once we convert it into VF).

 

I heard that we can copy and paste a scontrol inside Visualforce <apex:page/> tag(but I didn't find any doc for this).

 

If we are writing this from scratch in VF we need to do all validations again in <script/> tag in VF and we need to design the UI in VF. In scontrol we are using 2 Create and 3 Update SOQL statements. So for this we need to create custom Controller. I would like to avoid this double work.

 

That's why I am ask this question. Is there is any way to copy and paste scontrol in VF?