0
{!REQUIRESCRIPT("/soap/ajax/16.0/connection.js")} 
var records = {!GETRECORDIDS($ObjectType.Lead)};
var url = parent.location.href;
var newRecords = [];
if(records[0] ==null) 
alert('Please select a record');
if(records.length>0) {
for(i=0;i<records.length;i++) {
    var leadObj = new sforce.SObject("Lead");
    leadObj.Id = records[i];
    if(leadObj.TypeOfInterest__c =='VO'&& leadObj.Country__c =='France') {

            leadObj.OwnerId = '00G7E000000rZIs';
    }
    else if(leadObj.TypeOfInterest__c =='VN'&& leadObj.Country__c =='France') {
            leadObj.OwnerId = '00G7E000000rZIr';
    }
    newRecords.push(leadObj);
}
result = sforce.connection.update(newRecords);
parent.location.href = url;
}

Using the above code , mass transfer is not happening. PLease tell me what is missing here? It is not entering into the if loop. it is directly going to sforce update.

1

Using {!GETRECORDIDS($ObjectType.Lead)} only the Lead Ids is returned as Array.You need to query Lead object using the collected ids, to get the respective leads fields: Country__c,TypeOfInterest__c.

Doc to the sforce examples can be found here.

{!REQUIRESCRIPT("/soap/ajax/16.0/connection.js")} 
var leadIds = {!GETRECORDIDS($ObjectType.Lead)},
    url = parent.location.href,
    newRecords = [],leadIdStr,result;

if(typeof leadIds[0] == 'undefined'){
    alert('Please select a record');
} 

for(var i = 0;i < leadIds.length;i++) {
    if(leadIdStr){
        leadIdStr += ','+'\''+leadIds[i]+'\'';
    }
    else{
        leadIdStr = '\''+leadIds[i]+'\'';
    }
}


if(leadIdStr){
    var leads = sforce.connection.query("Select Id,TypeOfInterest__c,Country__c FROM Lead WHERE Id IN ("+leadIdStr+")"),
        leaseRecords = leads.getArray("records");

    for (var i = 0; i < leaseRecords.length; i++) {

        var leadObj = new sforce.SObject("Lead");
        leadObj.Id = leaseRecords[i].Id;

        leadObj.OwnerId = '00G280000029OrK'; // Queue Id 


        newRecords.push(leadObj);
    }

    result = sforce.connection.update(newRecords);
    parent.location.href = url;
}
  • thanx a lot praveen . It worked :) – uma451 Jul 12 '16 at 9:57

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.