• Naomi Harmon
  • NEWBIE
  • 50 Points
  • Member since 2015
  • Salesforce Administrator
  • Volusion, Inc.

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 13
    Replies
I have a beautiful button created on my Contact object that shows a popup and uses sforce.connect.query to get an associated Opportunity. Everything is working perfectly, except for me trying to display the Opportunity's name in the popup. How can I access and display my javascript variable "name" from my box.setContentInnerHTML(...) ? Here is my code:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}

var records = sforce.connection.query("SELECT Id, Name FROM Opportunity Where Contact__r.Id = '{!Contact.Id}' AND App_Opp_For__c ='Manna' AND IsClosed=false ORDER BY CreatedDate");

var oppRec = records.getArray('records')[0];

 var oppId = oppRec.Id;
 url = `${oppId}`;

 var oppName = oppRec.Name;
 var name = `${oppName}`;

 var box = new SimpleDialog("hersh"+Math.random(), true); 
	parent.box = box; 
	box.setTitle("Manna Application"); 
	box.createDialog(); 
	box.setWidth(350); 
	box.setContentInnerHTML("<p align='center'><img src='https://c.cs21.content.force.com/servlet/servlet.ImageServer?id=015q00000007FVD&oid=00Dq0000000CSTt&lastMod=1521667670000' style='margin:0 5px;'/></p></br><p align='center'>{!Contact.FirstName} already has a Manna Opportunity open.</br></p><p align='center'><br /><button class='btn' onclick='window.parent.box.hide(); window.open(url);'>Go To Opp</button>&nbsp;<button class='btn' onclick='window.parent.box.hide(); window.open(url);'>New Manna App</button></p>"); 
	box.setupDefaultButtons(); 
	box.show();

Hey guys,

I found code for a cool pop-up window that looks and works beautifully. So I have a button on the Contact that executes the following Javascript:

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}

specialcare = "{!Contact.Special_Care_Comments__c}";
contact = "{!Contact.Id}";
dates = new Date();

function insertScript(script){ 
	var targetNode = document.createElement('div');	//	construct div for script injection 
	document.body.appendChild(targetNode); 
	try {
		var el = document.createElement('script');
			el.type="text/javascript";
			el.innerHTML = script;
		targetNode.appendChild(el); 
	} catch (e){ 
		var el = document.createElement('span'); 
		targetNode.appendChild(el); 
		el.innerHTML = "<br /><scr"+"ipt type='text/javascript' defer='defer'>"+script+"</script" + ">"; 
	} 

var box = new SimpleDialog("hersh"+Math.random(), true); 
	parent.box = box; 
	box.setTitle("Special Care Notice"); 
	box.createDialog(); 
	box.setWidth(350); 
	box.setContentInnerHTML("<p align='center'><img src='https://c.cs21.content.force.com/servlet/servlet.ImageServer?id=015q0000000BNcN&oid=00Dq0000000CSTt&lastMod=1519241870000' style='margin:0 5px;'/></p><p align='center'>Please note: {!Contact.Special_Care_Comments__c}</p><p align='center'><br /><button class='btn' onclick='window.parent.box.hide(); return false;'>Okay</button></p>"); 
	box.setupDefaultButtons(); 
	box.show(); 
} 

script = "Special Care Comments: specialcare;"; 

insertScript(script);

Now I would like to create a similar pop-up with two buttons. The second button, I would like it to open a new window (visualforce page). I just can't get it to work! Instead of the 'window.parent.box.hide();' onclick function, I've tried 'window.open('/apex/nameofpage');' as well as tried a specific url, but whenever I go to click the button then, absolutely nothing happens.

Can someone help?
IT recently built some Apex triggers on our Lead, Account, and Opportunity objects that make a web callout whenever a record is inserted and/or updated. Now I'm trying to deploy some new triggers, and I'm creating some new Opportunities in my test class. My trigger and test class don't contain any callouts, but because of these other triggers that are in place, I'm getting hit with this error message:
Methods defined as TestMethod do not support Web service callouts 
Stack Trace: null

How can I fix this?? I've tried changing the triggers that contain the callouts by inserting the if(!test.isrunningtest()) before the callout, but that causes its own test class to fail with a null pointer exception.
I am trying to create a batch Apex class that I can schedule to run weekly to automatically unqualify Leads that are 60 days old or older and haven't had activity on them in the past 10 days (and only for a single Record Type). Here is my Class and Test Class...I keep receiving a "Methods defined as TestMethod do not support Web service callouts." My test class doesn't include any callouts..but I know we have a trigger or two in our instance on Leads that does have a callout. How do I fix my test class then?

Batch Apex Class:
global class AutoUnqualifyLeads implements Database.Batchable<sObject> {
   
    global Database.QueryLocator start(Database.BatchableContext bc){
        String query = 'SELECT Id, Status, Reason_Not_Qualified__c, LastActivityDate '+
                         'FROM Lead '+
                        'WHERE CreatedDate < LAST_N_DAYS:60 '+
                          'AND Days_Since_Last_Activity__c > 10 '+
                          'AND IsConverted = false '+
                          'AND Status != '+' \'Unqualified\' '+
                          'AND RecordTypeId = '+' \'01270000000Q4tB\' ';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext bc, List<Lead> scope){
        List<Lead> leads = new List<Lead>();
        for (Lead l: scope){
                l.Status                  = 'Unqualified';
                l.Reason_Not_Qualified__c = 'No Response';
                system.debug(l);
                leads.add(l);
        }
   update leads;
   }

    global void finish(Database.BatchableContext bc){
        
    }
}

Test Class (my test load data information is listed below the code snippet):
@isTest
public class AutoUnqualifyLeadsTest{
        
    @testSetup
    static void setupTest(){
        List<Lead> leadLoad = Test.loadData(Lead.sObjectType,'testLeadsAutoUnqual');
        System.debug(leadLoad);
        
        Lead L1 = (Lead)leadLoad[0];
        
        List<Task> tasks = new List<Task>();
         Task t = new Task();
           t.Subject = 'Test';
           t.Status = 'Completed';
           t.ActivityDate = Date.newInstance(2017, 10, 09);
           t.WhoId = L1.Id;
           System.debug('WhoId = '+t.WhoId);
         tasks.add(t);
         insert tasks;
        
        L1.Status = 'Contacted';
        Update L1;
             
        List<Lead> days = [Select Days_Since_Last_Activity__c, Status, FirstName 
                             From Lead
                            Where Id = :leadLoad];
        System.debug(days);
        
        
    }

    @isTest
    static void testLeads(){
        
        Test.startTest();
        AutoUnqualifyLeads aul = new AutoUnqualifyLeads();
        Id batchId = Database.executeBatch(aul);
        Test.stopTest();
        
     //after the testing stops, assert records were updated properly
     System.assertEquals(1, [select count() from Lead where Reason_Not_Qualified__c='No Response']);
    }
 
}

Test data:

CreatedDate, RecordTypeID, Days_Since_Last_Activity__c, Status, Reason_Not_Qualified__c, LastName, Company
2017-10-07T01:40:39, 0121I000000QxE7, 12, Open, Bing, Friends Co.
2017-09-22T01:43:39, 0121I000000QxE7, 13, Contacted, Gellar, Friends Inc.
2014-05-02T02:43:39, 0121I000000QxE7, 4, Open, Green, Friends LLC

Can you please help me troubleshoot??
I am trying to create a batch Apex class that I can schedule to run weekly to automatically unqualify Leads that are 60 days old or older and haven't had activity on them in the past 10 days (and only for a single Record Type). Here is my Class and Test Class...My assertion keeps failing. It seems 0 of my leads are being updated correctly.

Batch Apex Class:
global class AutoUnqualifyLeads implements Database.Batchable<sObject> {
    
    global Database.QueryLocator start(Database.BatchableContext bc){
        String query = 'SELECT Id, Status, Reason_Not_Qualified__c, LastActivityDate '+
                         'FROM Lead '+
                        'WHERE CreatedDate < LAST_N_DAYS:60 '+
                          'AND Days_Since_Last_Activity__c > 10 '+
                          'AND IsConverted = false '+
                          'AND Status != '+' \'Unqualified\' '+
                          'AND RecordTypeId = '+' \'0121I000000QxE7QAK\' ';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext bc, List<Lead> scope){
        List<Lead> leads = new List<Lead>();
        for (Lead l: scope){
                l.Status                  = 'Unqualified';
                l.Reason_Not_Qualified__c = 'No Response';
                system.debug(l);
                leads.add(l);
        }
   update leads;
   }

    global void finish(Database.BatchableContext bc){
        
    }
}

Test Class (my test load data information is listed below the code snippet):
@isTest

private class AutoUnqualifyLeadsTest {
    @isTest
    static void setupTest(){
        List<Lead> leadLoad = Test.loadData(Lead.sObjectType,'testLeadsAutoUnqual');
        System.debug(leadLoad);
        
    }
    
    @isTest
    static void testLeads(){
        
        Test.startTest();
        AutoUnqualifyLeads aul = new AutoUnqualifyLeads();
        Id batchId = Database.executeBatch(aul);
        Test.stopTest();

     System.assertEquals(3, [select count() from Lead where Status='Unqualified']);
    }
 
}
Test data:

CreatedDate, RecordTypeID, Days_Since_Last_Activity__c, Status, Reason_Not_Qualified__c, LastName, Company
2017-10-07T01:40:39, 0121I000000QxE7, 12, Open, Bing, Friends Co.
2017-09-22T01:43:39, 0121I000000QxE7, 13, Contacted, Gellar, Friends Inc.
2014-05-02T02:43:39, 0121I000000QxE7, 4, Open, Green, Friends LLC

Can you please help me troubleshoot??
 
Hi there! I am extremely new to coding and need help fixing my Apex Trigger below. The Trigger is set up to populate a lookup field on the Lead object that points to my custom CampaignAdGroup__c object. I need help fixing it so that the lookup field ("Campaign_ad_group__c") is populated with a null value in the case that the "CampaignAdGroup_concatenate__c" on my lead record is populated but does not match any Name values in my CampaignAdGroup__c object. Any help is appreciated!

trigger campaignAdGroupLookup on Lead (before update, before insert) {     
        Set<String> campaignAdGroups = new Set<String>();
            for (Lead collectCampaignAdgroupFromLead : Trigger.new) {
            campaignAdGroups.add(collectCampaignAdgroupFromLead.CampaignAdGroup_concatenate__c);
             }           
        List<CampaignAdGroup__c> campaignadgroupList = [SELECT id, Name FROM CampaignAdGroup__c WHERE Name IN :campaignAdGroups];
        
        Map<String, CampaignAdGroup__c> campaignAdGroupNameToLeadMap = new Map<String, CampaignAdGroup__c>();
    
        for (CampaignAdGroup__c c : campaignadgroupList) {
            campaignAdGroupNameToLeadMap.put(c.Name, c);
        }
        for (Lead o : Trigger.new) {         
            if (o.CampaignAdGroup_concatenate__c != null) {
                o.Campaign_Ad_Group__c = campaignAdGroupNameToLeadMap.get(o.CampaignAdGroup_concatenate__c).id;
            }
            else {
                o.Campaign_Ad_Group__c = null;
            }
        }
        }
I have a beautiful button created on my Contact object that shows a popup and uses sforce.connect.query to get an associated Opportunity. Everything is working perfectly, except for me trying to display the Opportunity's name in the popup. How can I access and display my javascript variable "name" from my box.setContentInnerHTML(...) ? Here is my code:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}

var records = sforce.connection.query("SELECT Id, Name FROM Opportunity Where Contact__r.Id = '{!Contact.Id}' AND App_Opp_For__c ='Manna' AND IsClosed=false ORDER BY CreatedDate");

var oppRec = records.getArray('records')[0];

 var oppId = oppRec.Id;
 url = `${oppId}`;

 var oppName = oppRec.Name;
 var name = `${oppName}`;

 var box = new SimpleDialog("hersh"+Math.random(), true); 
	parent.box = box; 
	box.setTitle("Manna Application"); 
	box.createDialog(); 
	box.setWidth(350); 
	box.setContentInnerHTML("<p align='center'><img src='https://c.cs21.content.force.com/servlet/servlet.ImageServer?id=015q00000007FVD&oid=00Dq0000000CSTt&lastMod=1521667670000' style='margin:0 5px;'/></p></br><p align='center'>{!Contact.FirstName} already has a Manna Opportunity open.</br></p><p align='center'><br /><button class='btn' onclick='window.parent.box.hide(); window.open(url);'>Go To Opp</button>&nbsp;<button class='btn' onclick='window.parent.box.hide(); window.open(url);'>New Manna App</button></p>"); 
	box.setupDefaultButtons(); 
	box.show();

Hey guys,

I found code for a cool pop-up window that looks and works beautifully. So I have a button on the Contact that executes the following Javascript:

{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}

specialcare = "{!Contact.Special_Care_Comments__c}";
contact = "{!Contact.Id}";
dates = new Date();

function insertScript(script){ 
	var targetNode = document.createElement('div');	//	construct div for script injection 
	document.body.appendChild(targetNode); 
	try {
		var el = document.createElement('script');
			el.type="text/javascript";
			el.innerHTML = script;
		targetNode.appendChild(el); 
	} catch (e){ 
		var el = document.createElement('span'); 
		targetNode.appendChild(el); 
		el.innerHTML = "<br /><scr"+"ipt type='text/javascript' defer='defer'>"+script+"</script" + ">"; 
	} 

var box = new SimpleDialog("hersh"+Math.random(), true); 
	parent.box = box; 
	box.setTitle("Special Care Notice"); 
	box.createDialog(); 
	box.setWidth(350); 
	box.setContentInnerHTML("<p align='center'><img src='https://c.cs21.content.force.com/servlet/servlet.ImageServer?id=015q0000000BNcN&oid=00Dq0000000CSTt&lastMod=1519241870000' style='margin:0 5px;'/></p><p align='center'>Please note: {!Contact.Special_Care_Comments__c}</p><p align='center'><br /><button class='btn' onclick='window.parent.box.hide(); return false;'>Okay</button></p>"); 
	box.setupDefaultButtons(); 
	box.show(); 
} 

script = "Special Care Comments: specialcare;"; 

insertScript(script);

Now I would like to create a similar pop-up with two buttons. The second button, I would like it to open a new window (visualforce page). I just can't get it to work! Instead of the 'window.parent.box.hide();' onclick function, I've tried 'window.open('/apex/nameofpage');' as well as tried a specific url, but whenever I go to click the button then, absolutely nothing happens.

Can someone help?
IT recently built some Apex triggers on our Lead, Account, and Opportunity objects that make a web callout whenever a record is inserted and/or updated. Now I'm trying to deploy some new triggers, and I'm creating some new Opportunities in my test class. My trigger and test class don't contain any callouts, but because of these other triggers that are in place, I'm getting hit with this error message:
Methods defined as TestMethod do not support Web service callouts 
Stack Trace: null

How can I fix this?? I've tried changing the triggers that contain the callouts by inserting the if(!test.isrunningtest()) before the callout, but that causes its own test class to fail with a null pointer exception.
I am trying to create a batch Apex class that I can schedule to run weekly to automatically unqualify Leads that are 60 days old or older and haven't had activity on them in the past 10 days (and only for a single Record Type). Here is my Class and Test Class...I keep receiving a "Methods defined as TestMethod do not support Web service callouts." My test class doesn't include any callouts..but I know we have a trigger or two in our instance on Leads that does have a callout. How do I fix my test class then?

Batch Apex Class:
global class AutoUnqualifyLeads implements Database.Batchable<sObject> {
   
    global Database.QueryLocator start(Database.BatchableContext bc){
        String query = 'SELECT Id, Status, Reason_Not_Qualified__c, LastActivityDate '+
                         'FROM Lead '+
                        'WHERE CreatedDate < LAST_N_DAYS:60 '+
                          'AND Days_Since_Last_Activity__c > 10 '+
                          'AND IsConverted = false '+
                          'AND Status != '+' \'Unqualified\' '+
                          'AND RecordTypeId = '+' \'01270000000Q4tB\' ';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext bc, List<Lead> scope){
        List<Lead> leads = new List<Lead>();
        for (Lead l: scope){
                l.Status                  = 'Unqualified';
                l.Reason_Not_Qualified__c = 'No Response';
                system.debug(l);
                leads.add(l);
        }
   update leads;
   }

    global void finish(Database.BatchableContext bc){
        
    }
}

Test Class (my test load data information is listed below the code snippet):
@isTest
public class AutoUnqualifyLeadsTest{
        
    @testSetup
    static void setupTest(){
        List<Lead> leadLoad = Test.loadData(Lead.sObjectType,'testLeadsAutoUnqual');
        System.debug(leadLoad);
        
        Lead L1 = (Lead)leadLoad[0];
        
        List<Task> tasks = new List<Task>();
         Task t = new Task();
           t.Subject = 'Test';
           t.Status = 'Completed';
           t.ActivityDate = Date.newInstance(2017, 10, 09);
           t.WhoId = L1.Id;
           System.debug('WhoId = '+t.WhoId);
         tasks.add(t);
         insert tasks;
        
        L1.Status = 'Contacted';
        Update L1;
             
        List<Lead> days = [Select Days_Since_Last_Activity__c, Status, FirstName 
                             From Lead
                            Where Id = :leadLoad];
        System.debug(days);
        
        
    }

    @isTest
    static void testLeads(){
        
        Test.startTest();
        AutoUnqualifyLeads aul = new AutoUnqualifyLeads();
        Id batchId = Database.executeBatch(aul);
        Test.stopTest();
        
     //after the testing stops, assert records were updated properly
     System.assertEquals(1, [select count() from Lead where Reason_Not_Qualified__c='No Response']);
    }
 
}

Test data:

CreatedDate, RecordTypeID, Days_Since_Last_Activity__c, Status, Reason_Not_Qualified__c, LastName, Company
2017-10-07T01:40:39, 0121I000000QxE7, 12, Open, Bing, Friends Co.
2017-09-22T01:43:39, 0121I000000QxE7, 13, Contacted, Gellar, Friends Inc.
2014-05-02T02:43:39, 0121I000000QxE7, 4, Open, Green, Friends LLC

Can you please help me troubleshoot??
I am trying to create a batch Apex class that I can schedule to run weekly to automatically unqualify Leads that are 60 days old or older and haven't had activity on them in the past 10 days (and only for a single Record Type). Here is my Class and Test Class...My assertion keeps failing. It seems 0 of my leads are being updated correctly.

Batch Apex Class:
global class AutoUnqualifyLeads implements Database.Batchable<sObject> {
    
    global Database.QueryLocator start(Database.BatchableContext bc){
        String query = 'SELECT Id, Status, Reason_Not_Qualified__c, LastActivityDate '+
                         'FROM Lead '+
                        'WHERE CreatedDate < LAST_N_DAYS:60 '+
                          'AND Days_Since_Last_Activity__c > 10 '+
                          'AND IsConverted = false '+
                          'AND Status != '+' \'Unqualified\' '+
                          'AND RecordTypeId = '+' \'0121I000000QxE7QAK\' ';
        return Database.getQueryLocator(query);
    }
    
    global void execute(Database.BatchableContext bc, List<Lead> scope){
        List<Lead> leads = new List<Lead>();
        for (Lead l: scope){
                l.Status                  = 'Unqualified';
                l.Reason_Not_Qualified__c = 'No Response';
                system.debug(l);
                leads.add(l);
        }
   update leads;
   }

    global void finish(Database.BatchableContext bc){
        
    }
}

Test Class (my test load data information is listed below the code snippet):
@isTest

private class AutoUnqualifyLeadsTest {
    @isTest
    static void setupTest(){
        List<Lead> leadLoad = Test.loadData(Lead.sObjectType,'testLeadsAutoUnqual');
        System.debug(leadLoad);
        
    }
    
    @isTest
    static void testLeads(){
        
        Test.startTest();
        AutoUnqualifyLeads aul = new AutoUnqualifyLeads();
        Id batchId = Database.executeBatch(aul);
        Test.stopTest();

     System.assertEquals(3, [select count() from Lead where Status='Unqualified']);
    }
 
}
Test data:

CreatedDate, RecordTypeID, Days_Since_Last_Activity__c, Status, Reason_Not_Qualified__c, LastName, Company
2017-10-07T01:40:39, 0121I000000QxE7, 12, Open, Bing, Friends Co.
2017-09-22T01:43:39, 0121I000000QxE7, 13, Contacted, Gellar, Friends Inc.
2014-05-02T02:43:39, 0121I000000QxE7, 4, Open, Green, Friends LLC

Can you please help me troubleshoot??
 
Hi there! I am extremely new to coding and need help fixing my Apex Trigger below. The Trigger is set up to populate a lookup field on the Lead object that points to my custom CampaignAdGroup__c object. I need help fixing it so that the lookup field ("Campaign_ad_group__c") is populated with a null value in the case that the "CampaignAdGroup_concatenate__c" on my lead record is populated but does not match any Name values in my CampaignAdGroup__c object. Any help is appreciated!

trigger campaignAdGroupLookup on Lead (before update, before insert) {     
        Set<String> campaignAdGroups = new Set<String>();
            for (Lead collectCampaignAdgroupFromLead : Trigger.new) {
            campaignAdGroups.add(collectCampaignAdgroupFromLead.CampaignAdGroup_concatenate__c);
             }           
        List<CampaignAdGroup__c> campaignadgroupList = [SELECT id, Name FROM CampaignAdGroup__c WHERE Name IN :campaignAdGroups];
        
        Map<String, CampaignAdGroup__c> campaignAdGroupNameToLeadMap = new Map<String, CampaignAdGroup__c>();
    
        for (CampaignAdGroup__c c : campaignadgroupList) {
            campaignAdGroupNameToLeadMap.put(c.Name, c);
        }
        for (Lead o : Trigger.new) {         
            if (o.CampaignAdGroup_concatenate__c != null) {
                o.Campaign_Ad_Group__c = campaignAdGroupNameToLeadMap.get(o.CampaignAdGroup_concatenate__c).id;
            }
            else {
                o.Campaign_Ad_Group__c = null;
            }
        }
        }
I installed both the Opp Alert Coponent and the ContactsToday Component from the Trailhead Module "Working with Custom Lightning Components". However, they are not available to add as components in the Lightning App Builder. I've tried uninstalling an reinstalling, with no luck. The "Custom Components" section in Lightning App Builder shows 0.

Any help would be appreciated - I've had nothing but technical difficulties with this module and I want to earn that darn badge already!
I don't see a Setup menu to run the Lightning App Builder for a challange.  I'm using the Summer `15 Developer Edition.  How is it enabled?