Simple AJAX in Salesforce


The relationship between Member and Interests is Master Detail. One member can have multiple interests.

Check Valid Interests button will say whether any interest under the Member is active using AJAX.

Custom Detail page Button:

Button Javascript code:


var soql = "SELECT InfallibleTech__Active__c FROM  InfallibleTech__Interest__c WHERE InfallibleTech__Member__c = '{!InfallibleTech__Member__c.Id}'";

result = sforce.connection.query(soql);
records = result.getArray("records");
var check = "false";

if(records.length > 0){
    for (var i=0; i < records.length; i++) {
        var record = records[i];
        if(record.InfallibleTech__Active__c == "false"){
            check = "true";
        } else{
            check = "false";
} else {
    check = "true"

if(check == "true"){
    alert("No active interests");
} else {
    alert("Active interests are present");


With Active interests:

With No Active interests:

No comments:

Post a Comment