0

I am getting the following error when I include resource script for sforce connection

"Error: Function REQUIRESCRIPT may not be used in this type of formula". Please provide me a solution and thanks in advance !!

here is my code :

<head>
    <link rel="stylesheet" href="{!URLFOR($Resource.web2caseResources,'web2case/css/validationEngine.jquery_Dacia.css')}" type="text/css" media="screen" title="no title" charset="utf-8" />
    <!-- MaskValidation -->
    <apex:includeScript value="{!$Resource.MaskFuntion}" />
    <!---ValidationPlugin---->
    <script src="{!URLFOR($Resource.web2caseResources,'web2case/js/jquery_min.js')}" type="text/javascript" charset="UTF-8"></script>
    <script src="{!URLFOR($Resource.web2caseResources,'web2case/js/jquery.validationEngine-es.js')}" type="text/javascript"></script>
    <script src="{!URLFOR($Resource.web2caseResources,'web2case/js/jquery.validationEngine.js')}" type="text/javascript"></script>
    <script src="{!URLFOR($Resource.web2caseResources,'web2case/js/Rforce_ESWebtoCase.js')}" type="text/javascript"></script>

    <style>
        form {
            width: 540px;
            background-color: #EDEDED;
            font-family: Arial, "Trebuchet ms", Verdana, sans-serif;
            font-size: 11px;
            font-family: Arial, "Trebuchet ms", Verdana, sans-serif;
            padding: 7px 7px 0px 7px;
        }
        div #button {
            float: right;
            margin-right: 3px;
        }
        input.text {
            border: 1px solid #DADCDE;
            color: #484848;
            font-size: 12px;
            height: 16px;
            padding-top: 4px;
        }
        p {
            font-family: Arial, "Trebuchet ms", Verdana, sans-serif;
            color: #A2A5A4;
            font-size: o.70em;
        }
        h2 {
            line-height: 1.5px;
            font-family: Arial, "Trebuchet ms", Verdana, sans-serif;
        }
        #CPF_Web__c,
        #email,
        #Phone,
        #Fname1,
        #Lname1,
        #description,
        #VIN_Web__c,
        #License_Number_Web__c,
        #Address,
        #CEP,
        #Complemento,
        #Cidade,
        #Estado,
        #ContactMobile {
            width: 410px;
        }
        #Numero {
            width: 150px;
        }
        #Endereço {
            width: 410px;
        }
        #left {
            float: left;
        }
        #right {
            width: 50%;
            padding: 0 0 0 10px;
        }
        div #backbutton {
            float: right;
        }
    </style>
</head>

<form id="formID">
    <Label>Si quiere realizar una consulta, una reclamación o hacer una sugerencia, cumplimente por favor el formulario a continuación.Para poder gestionar su petición, necesitamos por favor algunos datos personales.
    </Label>
    <br></br>
    <hr color="white"></hr>
    <br></br>

    <label for="Title_Web__c"> Tratamiento</label>
    <br/>
    <select id="Title_Web__c">
        <option value="Mr.">Sr.</option>
        <option value="Mrs.">Sra.</option>
        <option value="Miss.">Sta.</option>
    </select>
    <br/>
    <hr color="white"></hr>


    <Label for="Lname">APELLIDO 1*</Label>
    <br></br>
    <input id="Lname" class="validate[required,length[2,20]] text-input " maxlength="20" size="20" type="text" style="width:500px" />
    <br></br>

    <span>       
<Label for="Fname" >NOMBRE*</Label>
&nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
<Label for="Surname" >APELLIDO 2*</Label>
<br></br>
<input id="Fname" class="validate[required,length[2,20]] text-input" maxlength="30" size="20" type="text" style="width:250px" /> 
&nbsp;
<input id="Surname" class="validate[required,length[2,20]] text-input" maxlength="20" size="20" type="text" style="width:235px" />
</span>

    <hr color="white"></hr>

    <Label for="email">E-mail*</Label>
    <br></br>
    <input id="email" maxlength="80" size="48" class="validate[required,custom[email]]" style="width:500px" />

    <hr color="white"></hr>

    <Label for="phone">Teléfono fijo</Label>
    <br></br>
    <input id="phone" maxlength="10" name="phone" size="48" style="width:500px" />
    <hr color="white"></hr>

    <Label for="Mobile">Teléfono móvil*</Label>
    <br></br>
    <input id="ContactMobile" class="validate[required,custom[telephone]]" maxlength="10" size="48" style="width:500px" />
    <hr color="white"></hr>
    <span>       
<Label for="Dnumber" >Nº</Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;     
<Label for="Street" >Calle</Label>
<br></br>
<input id="number" maxlength="20" size="20" type="text" style="width:250px" />
&nbsp;
<input id="Street" maxlength="20" size="20" type="text" style="width:238px" />
</span>

    <br></br>
    <hr color="white"></hr>

    <span>        
<Label for="flat" >Piso</Label>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<Label for="door" >Puerta</Label>
<br></br>
<input id="flat" maxlength="20" size="20" type="text" style="width:250px" />
&nbsp;
<input id="door" maxlength="20" size="20" type="text" style="width:238px" />
</span>
    <br></br>
    <hr color="white"></hr>

    <span>        
<Label for="city" >Ciudad</Label>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp;&nbsp; 
<Label for="state" >Provincia</Label>
<br></br>
<input id="city" maxlength="20" size="20" type="text" />
&nbsp;
<input id="state" maxlength="20" size="20" type="text" />
</span>
    <br></br>
    <hr color="white"></hr>
    <span>       
<Label for="vin" >Chasis</Label>
&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; 
<Label for="regno" >Matricula</Label>
<br></br>
<input id="vinno" maxlength="17" size="20" type="text" />
&nbsp;
<input id="RegNo" maxlength="20" size="20" type="text" />
</span>

    <br></br>
    <hr color="white"></hr>

    <Label for="km">Kilómetros</Label>
    <br></br>
    <input id="km" type="number" />
    <br></br>
    <hr color="white"></hr>
    <Label for="casetype">Tipo*</Label>
    <br></br>
    <select id="Type" name="casetype">
        <option value="Information Request">Solicitud de información</option>
        <option value="Complaint">Reclamación</option>
        <option value="Service Request">Sugerencia</option>
        <option value="Other">otro</option>
    </select>
    <br/>
    <br></br>
    <hr color="white"></hr>
    <Label for="description">Descripción*</Label>
    <br></br>
    <Textarea id="description" class="validate[required]" maxlength="800" rows="8" cols="57" />
    <br></br>
    <hr color="white"></hr>

    <apex:includeScript value="{!$Resource.jquery}" />
    <script type="text/javascript">
        var __sfdcSessionId = '{!GETSESSIONID()}';
        var filesToUpload = [];
        var uploadedFile = 0;
    </script>
    <style>
        .FilebuttonStyle {
            font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;
            font-size: 13px;
            color: #FFFFFF;
            background-color: #169fcc !important;
            text-decoration: none;
            text-align: center;
            border: 1px solid #1691ba !important;
            line-height: 25px;
            !important;
            border-radius: 4px;
            display: inline-block;
            cursor: pointer;
            width: 40px;
        }
        td.fileRow {
            overflow: hidden;
            font-family: Arial, 'Helvetica Neue', Helvetica, sans-serif;
            font-size: 13px;
            color: #ffffff;
            background-color: #8db728;
            text-decoration: none;
            text-align: center;
            border: 1px solid #6c8049;
            line-height: 32px;
            !important;
            border-radius: 4px;
            //padding-left:10px; 
            //padding-right:10px; 
            background-image: linear-gradient(top, #9dcc3d, #7da223);
            background-image: -o-linear-gradient(top, #9dcc3d, #7da223);
            background-image: -moz-linear-gradient(top, #9dcc3d, #7da223);
            background-image: -webkit-linear-gradient(top, #9dcc3d, #7da223);
            background-image: -ms-linear-gradient(top, #9dcc3d, #7da223);
            display: inline-block;
            cursor: pointer;
            width: 120px;
            overflow: hidden;
        }
        td.fileRow input {
            display: block !important;
            width: 157px !important;
            height: 57px !important;
            opacity: 0 !important;
            overflow: hidden !important;
        }
        .fileCheckBox {
            width: 16px;
            height: 16px;
            display: inline-block;
            margin: 3px 5px 3px 3px;
            background-color: white;
            //box-shadow: 0px 0px 1px #b0b3ae; 
            text-align: center;
            vertical-align: top;
        }
        .FilebuttonGroup {
            float: right;
            padding-right: -70px!important;
        }
    </style>
    <script src="/soap/ajax/32.0/connection.js" type="text/javascript"></script>

    <script type="text/javascript">
        < body > {
            !REQUIRESCRIPT("/soap/ajax/13.0/connection.js")
        } < /body> 

        function uploadFile() {
            alert('Inside uploadFile');
            var cas = new sforce.SObject("Case");
            alert(cas);
            cas.description = document.getElementById("description").value;
            alert(cas.description);
            alert('inside');

            var caseResult = sforce.connection.create([cas]);
            alert(caseResult);
            alert('If Creation');

            cas.Title_Web__c = document.getElementById("Title_Web__c").value;
            cas.FirstName_Web__c = document.getElementById("Fname").value;
            cas.Second_name_Web__c = document.getElementById("Surname").value;
            cas.LastName_Web__c = document.getElementById("Lname").value;
            cas.SuppliedEmail = document.getElementById("email").value;
            cas.SuppliedPhone = document.getElementById("phone").value;
            cas.Cell_Phone_Web__c = document.getElementById("ContactMobile").value;
            cas.City_Web__c = document.getElementById("city").value;
            cas.State_Web__c = document.getElementById("state").value;
            cas.License_Number_Web__c = document.getElementById("RegNo").value;
            cas.VIN_Web__c = document.getElementById("vinno").value;
            cas.Type = document.getElementById("Type").value;
            cas.Subject = document.getElementById("Type").value;
            cas.description = document.getElementById("description").value;
            alert(cas.description);

            cas.Language_Web__c = "Spanish";
            cas.CaseBrand__C = "Dacia";
            cas.Priority = "Normal";
            cas.Status = "New";
            cas.Origin = "DACIA SITE";
            cas.CaseSubSource__c = "Webform";
            cas.From__c = "Customer";
            cas.RecordTypeId = "012b0000000cQKC";
            cas.CountryCase__c = "Spain";

            $("input[type=file]").each(function() {

                filesToUpload.push($(this)[0].files[0]);
            });
            var casCreationCheck = false;
            var fileSize = 0;
            var attSelect = document.getElementById('fileID').value;
            alert(attSelect);
            if (attSelect !== '') {
                for (var i = 0, f; f = filesToUpload[i]; i++) {
                    var reader = new FileReader();

                    // Keep a reference to the File in the FileReader so it can be accessed in callbacks 
                    reader.file = f;
                    fileSize = fileSize + f.size;
                    if (fileSize <= 1000) {
                        alert(fileSize);
                    } else {
                        casCreationCheck = true;
                        alert('The file ' + f.name + ' is more than 25MB which is not acceptable');
                    }

                }
                if (casCreationCheck == false) {
                    for (var i = 0, f; f = filesToUpload[i]; i++) {
                        alert('inside');
                        alert(sforce.connection.create([cas]));
                        var caseResult = sforce.connection.create([cas]);
                        alert('If Creation');
                        var caseId = caseResult[0].id;



                        reader.onload = function(e) {
                            var att = new sforce.SObject("Attachment");
                            att.Name = this.file.name;
                            att.ContentType = this.file.type;
                            att.ParentId = caseId;


                            var binary = "";
                            var bytes = new Uint8Array(e.target.result);
                            var length = bytes.byteLength;


                            for (var i = 0; i < length; i++) {
                                binary += String.fromCharCode(bytes[i]);
                            }

                            att.Body = (new sforce.Base64Binary(binary)).toString();


                            sforce.connection.create([att], {
                                onSuccess: function(result, source) {
                                    if (result[0].getBoolean("success")) {
                                        console.log("new attachment created with id " + result[0].id);
                                    } else {
                                        console.log("failed to create attachment " + result[0]);
                                    }
                                },

                                onFailure: function(error, source) {
                                    console.log("an error has occurred " + error);
                                }
                            });

                        };
                        reader.readAsArrayBuffer(f);

                    }
                }
            } else {
                var a = sforce.connection.create([cas]);
                alert('Else creation');
                var b = a[0].id;
                alert(b);
            }

        }


        function addRow(tableID) {

            var row = '<tr><td><input type="checkbox" onclick="processCheckbox()" name="chk" class="fileCheckBox"/</td><td class="fileRows"><input type="file" onchange="createuploadAttachment(this)" </td></tr>';
            $('#' + tableID).append(row);

        }

        function deleteRow(tableID) {
            try {
                var table = document.getElementById(tableID);
                var rowCount = table.rows.length;
                for (var i = 0; i < rowCount; i++) {
                    var row = table.rows[i];
                    var chkbox = row.cells[0].childNodes[0];
                    if (null != chkbox && true == chkbox.checked) {
                        table.deleteRow(i);

                        filesToUpload.splice(i, 1);
                        // console.log(filesToUpload); 
                        rowCount--;
                        i--;
                    }
                }
                processCheckbox();
            } catch (e) {
                alert(e);
            }
        }

        function processCheckbox() {
            $("[id$='_remove']").hide();
            var checkCount = 0;
            $("#dataTable input[type='checkbox']").each(function() {
                if ($(this).is(':checked')) {
                    checkCount++;
                }
            });
            if (checkCount > 0) {
                $("[id$='_remove']").show();
            }

        }
    </script>
    <div class="FilebuttonGroup">
        <input type="button" value="-" id="_remove" onclick="deleteRow('dataTable')" class="FilebuttonStyle" title="Delete Row" />

        <input type="button" value="+" onclick="addRow('dataTable')" id="_add" class="FilebuttonStyle" title="Add Row" />
    </div>
    <table id="dataTable">
        <tbody>
            <tr>
                <td> </td>
                <td class="fileRows">
                    <input type="file" id="fileID" class="fileInput" onchange="createuploadAttachment(this);" /> </td>
                <td></td>
            </tr>
        </tbody>
    </table>
    <input type="button" name="submit" value="Enviar" onclick="uploadFile()" />

    <div id="statusid"></div>
    <script>
        $(document).ready(function() {
            $("[id$='_remove']").hide();
            $("[id$='attachmentBlock']").find('.pbSubsection').attr({
                'style': 'margin-right:-70px !important;'
            });
        });
    </script>

</form>

  • 1
    Thats pretty untidy. Please edit your question with proper and required information. And as far as REQUIRESCRIPT goes, put it as the very first line in the script. – Santanu Halder Sep 30 '15 at 12:05
0

You can add sforce connection js via <script> or <apex:includescript> tag or serve it from your static resources like you are doing it for other resources.

<apex:includescript value="/soap/ajax/13.0/connection.js" />

There are lots of other question which answer this problem.

Ex: Developerforce

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.