+ Start a Discussion
muthuswimuthuswi 

Deleting records in Scontrol...HELP

Hi

I don't know what is the problem in the following query. I am getting "Expected identifier" error...

Can anyone help me find this?

Thanks

Muthu.

<html>
<head>
<script type="text/javascript" src="/soap/ajax/8.0/connection.js"></script>
<script type="text/javascript">

function init()
{
 deleteRecords();
}
function deleteRecords(fkId)
{       
    var sql = "Select Id FROM myEntity Where fkId__c = '" + fkId + "'";
   
    var qr1 = getRecords(sql); //getRecords returns queryResult...and I am getting records

    if (qr1.length > 0)
    {
 var p_ids = new Array(qr1.length);
    
 for (var i = 0; i < qr1.length; i++)
 {
  var record1 = qr1[i];
         p_ids[i] = record1.Id;        
 }    

        var p_csr = sforce.delete([p_ids]);
    }         
}

</script>
</head>
<body onload="init()">
<p>&nbsp;</p>
</body>
</html>

OneNewbieOneNewbie

Not sure what your getRecords function looks like but here is my take on getting the results.

    var sql = "Select Id FROM myEntity Where fkId__c = '" + fkId + "'";
   
    var qr1 = sforce.connection.query(sql);

 var records = result.getArray("records");

OneNewbieOneNewbie

Not sure what your getRecords function looks like but here is my take on getting the results.

    var sql = "Select Id FROM myEntity Where fkId__c = '" + fkId + "'";
   
    var qr1 = sforce.connection.query(sql);

  var records = result.getArray("records");

OneNewbieOneNewbie

Not sure what your getRecords function looks like but here is my take on getting the results.

    var sql = "Select Id FROM myEntity Where fkId__c = '" + fkId + "'";
   
    var qr1 = sforce.connection.query(sql);

    var records = qr1.getArray("records");

The var records now contain the records.

muthuswimuthuswi

Hi

I got it...its not a problem in Array..but in sforce.delete(...)..

it should be like sforce.connection.deleteIds([idsarray])

Thanks guys

Muthu.

cheenathcheenath
Correct, delete is javascript keyword. So the API is called deleteIds().



Jereriah ManningJereriah Manning
{!REQUIRESCRIPT("/soap/ajax/30.0/connection.js")}

var aIds = sforce.connection.query("SELECT Id FROM Attachment WHERE ParentId = '{!Contact.Id}' LIMIT 200");
var idsArray = aIds.getArray("records");
var p_ids = new Array(idsArray.length);

for (var i = 0; i < idsArray.length; i++)
{
   var record1 = idsArray[i];
   p_ids[i] = record1.Id;
   var deletees = sforce.connection.deleteIds([p_ids]);       
}

alert("Number of files deleted: " + idsArray.length);

window.location.reload();