• Juan Pablo Escobar
  • NEWBIE
  • 15 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 2
    Replies
Hi,
I created a trigger on Note and its not firing when adding a Note to any type of record (Accounts or Contacts)
A few considerations:
  1. Trigger is Active ans it's very simple(see below)
  2. The New Note feature is active on my Org
  3. I was not able to create a trigger from the UI initially so I followed this process and it worked (i didn't get an error when saving it):  https://ck-developer-salesforce-com.360casb.com/forums/ForumsMain?id=906F0000000AUhEIAW
I added debug before and after calling the trigger handler class and I see no entry on the debug lof for the NoteTriggerHandler Trigger. Suggestions ??

Thanks!!

Pablo
.........

trigger NoteTriggerHandler on Note (after insert,after update, before insert, before update) {
    NoteTriggerHandler handler = new NoteTriggerHandler();
    handler.onAfterInsertUpdate(trigger.new);
}
I'm new to Visualforce and I want to create a unit test to test my page but I'm getting an error. Help will be really apreciated! 

Thanks

Pablo
.....

Apex Class:
public with sharing class UnqulifiedLeads
{
    public ApexPages.StandardSetController setCon;

    public UnqulifiedLeads(ApexPages.StandardSetController Ld){
        this.setCon= Ld;
    }

    public String selectedValue { get; set; }
    public Boolean UseCustomReasons { get; set; }
    
    public List<SelectOption> getMyOptions(){
      List<SelectOption> options = new List<SelectOption>();      

      // Reading picklist values and labels
      Schema.DescribeFieldResult fieldResult = Lead.Unqualified_Reason__c.getDescribe();
      List<Schema.PicklistEntry> picklistEntries = fieldResult.getPicklistValues();
  
       // Adding apicklist values to the select list
       options.add(new SelectOption('N/A','N/A')); 
       options.add(new SelectOption('Custom','Custom for each Lead')); 
       for(Schema.PicklistEntry entry : picklistEntries){
           options.add(new SelectOption(entry.getValue(), entry.getLabel())); 
       }
     return options;
    }

    public PageReference bumpLeads(){       
        List<Lead> selectedLeads = (List<Lead>) setCon.getSelected();
        if(test.isrunningTest()){
            selectedLeads = [    
                                SELECT 
                                    Id, Status, Firstname, Lastname,Unqualified_Reason__c 
                                FROM 
                                    Lead 
                                ORDER BY 
                                    createddate DESC 
                                LIMIT 1
                            ];
            selectedValue = 'N/A';
        }

        // Update records       
        for(Lead selectedlead : selectedLeads)
        {
            selectedlead.Status = 'Unqualified';
            system.debug('selectedValue' + selectedValue);
            if(selectedValue == 'N/A' || selectedValue == '' )
                selectedlead.Unqualified_Reason__c = 'Budget';
            else
                if(selectedValue != 'Custom')
                    selectedlead.Unqualified_Reason__c = selectedValue;   
        }       

        updateLeads();
        
        return null;        
    }

    public PageReference updateLeads()
    {       
        // Call StandardSetController 'save' method to update
        return setCon.save();   
    }
}

................................................

Visualforce page

<apex:page standardController="Lead" extensions="UnqulifiedLeads" recordSetVar="leads" >
   <apex:form >
       <apex:pageBlock title="Bump Selected Leads">
                <apex:outputLabel>Set Unqualify Reason for Leads   &nbsp; </apex:outputLabel>
                <apex:selectList label="hola" value="{!selectedValue}" size="1" multiselect="false">
                    <apex:selectOptions value="{!MyOptions}"/>
                </apex:selectList>
          
            <apex:pageBlockButtons >
                <apex:commandButton action="{!bumpLeads}" value="Confirm" id="Confirm"/>
            </apex:pageBlockButtons><br/><br/>
            <apex:pageBlockTable value="{!selected}" var="lead">
                <apex:column value="{!lead.FirstName}"/>
                <apex:column value="{!lead.LastName}"/>
                <apex:column value="{!lead.status}"/> 
                <apex:column headerValue="Reason">
                    <apex:actionRegion >
                        <apex:outputField value="{!lead.Unqualified_Reason__c}">
                            <apex:inlineEditSupport event="ondblClick" showOnEdit="Confirm" />
                        </apex:outputField>
                    </apex:actionRegion>
                </apex:column>

            </apex:pageBlockTable> 
        </apex:pageBlock>
    </apex:form>    
</apex:page>

......
Unit Test

@isTest
public class UnqulifiedLeadsTest{

    public static testMethod void testUnqulifiedLeads() {
    
    //Create Test leads
    List<Lead> leadList= new List<Lead>();
    Lead leadTest1 = new Lead();
    leadTest1.FirstName = 'Fisrtname1';
    leadTest1.LastName = 'Lastname1';
    leadTest1.Lead_Source_custom_field__c= 'Unknown';
    leadTest1.Status= '1 - Open Lead';
    Lead leadTest2 = new Lead();
    leadTest2.FirstName = 'Fisrtname2';
    leadTest2.LastName = 'Lastname2';
    leadTest2.Lead_Source_custom_field__c= 'Unknown';
    leadTest2.Status= '1 - Open Lead';
    leadList.add(leadTest1);
    leadList.add(leadTest2);
    insert leadList;
    
     Test.startTest();
     // load the page       
    PageReference pageRef = Page.MassUnqulifyLeads;
    Test.setCurrentPageReference(pageRef);
    ApexPages.StandardController sc = new ApexPages.StandardController(leadTest1);    
    UnqulifiedLeads leadsTest = new UnqulifiedLeads(sc); 

    Test.stopTest();
    
    }
    
}

Error Message: Error: Compile Error: Constructor not defined: [UnqulifiedLeads].<Constructor>(ApexPages.StandardController) at line 28 column 33


 
Hi,
I created a trigger on Note and its not firing when adding a Note to any type of record (Accounts or Contacts)
A few considerations:
  1. Trigger is Active ans it's very simple(see below)
  2. The New Note feature is active on my Org
  3. I was not able to create a trigger from the UI initially so I followed this process and it worked (i didn't get an error when saving it):  https://ck-developer-salesforce-com.360casb.com/forums/ForumsMain?id=906F0000000AUhEIAW
I added debug before and after calling the trigger handler class and I see no entry on the debug lof for the NoteTriggerHandler Trigger. Suggestions ??

Thanks!!

Pablo
.........

trigger NoteTriggerHandler on Note (after insert,after update, before insert, before update) {
    NoteTriggerHandler handler = new NoteTriggerHandler();
    handler.onAfterInsertUpdate(trigger.new);
}
I'm new to Visualforce and I want to create a unit test to test my page but I'm getting an error. Help will be really apreciated! 

Thanks

Pablo
.....

Apex Class:
public with sharing class UnqulifiedLeads
{
    public ApexPages.StandardSetController setCon;

    public UnqulifiedLeads(ApexPages.StandardSetController Ld){
        this.setCon= Ld;
    }

    public String selectedValue { get; set; }
    public Boolean UseCustomReasons { get; set; }
    
    public List<SelectOption> getMyOptions(){
      List<SelectOption> options = new List<SelectOption>();      

      // Reading picklist values and labels
      Schema.DescribeFieldResult fieldResult = Lead.Unqualified_Reason__c.getDescribe();
      List<Schema.PicklistEntry> picklistEntries = fieldResult.getPicklistValues();
  
       // Adding apicklist values to the select list
       options.add(new SelectOption('N/A','N/A')); 
       options.add(new SelectOption('Custom','Custom for each Lead')); 
       for(Schema.PicklistEntry entry : picklistEntries){
           options.add(new SelectOption(entry.getValue(), entry.getLabel())); 
       }
     return options;
    }

    public PageReference bumpLeads(){       
        List<Lead> selectedLeads = (List<Lead>) setCon.getSelected();
        if(test.isrunningTest()){
            selectedLeads = [    
                                SELECT 
                                    Id, Status, Firstname, Lastname,Unqualified_Reason__c 
                                FROM 
                                    Lead 
                                ORDER BY 
                                    createddate DESC 
                                LIMIT 1
                            ];
            selectedValue = 'N/A';
        }

        // Update records       
        for(Lead selectedlead : selectedLeads)
        {
            selectedlead.Status = 'Unqualified';
            system.debug('selectedValue' + selectedValue);
            if(selectedValue == 'N/A' || selectedValue == '' )
                selectedlead.Unqualified_Reason__c = 'Budget';
            else
                if(selectedValue != 'Custom')
                    selectedlead.Unqualified_Reason__c = selectedValue;   
        }       

        updateLeads();
        
        return null;        
    }

    public PageReference updateLeads()
    {       
        // Call StandardSetController 'save' method to update
        return setCon.save();   
    }
}

................................................

Visualforce page

<apex:page standardController="Lead" extensions="UnqulifiedLeads" recordSetVar="leads" >
   <apex:form >
       <apex:pageBlock title="Bump Selected Leads">
                <apex:outputLabel>Set Unqualify Reason for Leads   &nbsp; </apex:outputLabel>
                <apex:selectList label="hola" value="{!selectedValue}" size="1" multiselect="false">
                    <apex:selectOptions value="{!MyOptions}"/>
                </apex:selectList>
          
            <apex:pageBlockButtons >
                <apex:commandButton action="{!bumpLeads}" value="Confirm" id="Confirm"/>
            </apex:pageBlockButtons><br/><br/>
            <apex:pageBlockTable value="{!selected}" var="lead">
                <apex:column value="{!lead.FirstName}"/>
                <apex:column value="{!lead.LastName}"/>
                <apex:column value="{!lead.status}"/> 
                <apex:column headerValue="Reason">
                    <apex:actionRegion >
                        <apex:outputField value="{!lead.Unqualified_Reason__c}">
                            <apex:inlineEditSupport event="ondblClick" showOnEdit="Confirm" />
                        </apex:outputField>
                    </apex:actionRegion>
                </apex:column>

            </apex:pageBlockTable> 
        </apex:pageBlock>
    </apex:form>    
</apex:page>

......
Unit Test

@isTest
public class UnqulifiedLeadsTest{

    public static testMethod void testUnqulifiedLeads() {
    
    //Create Test leads
    List<Lead> leadList= new List<Lead>();
    Lead leadTest1 = new Lead();
    leadTest1.FirstName = 'Fisrtname1';
    leadTest1.LastName = 'Lastname1';
    leadTest1.Lead_Source_custom_field__c= 'Unknown';
    leadTest1.Status= '1 - Open Lead';
    Lead leadTest2 = new Lead();
    leadTest2.FirstName = 'Fisrtname2';
    leadTest2.LastName = 'Lastname2';
    leadTest2.Lead_Source_custom_field__c= 'Unknown';
    leadTest2.Status= '1 - Open Lead';
    leadList.add(leadTest1);
    leadList.add(leadTest2);
    insert leadList;
    
     Test.startTest();
     // load the page       
    PageReference pageRef = Page.MassUnqulifyLeads;
    Test.setCurrentPageReference(pageRef);
    ApexPages.StandardController sc = new ApexPages.StandardController(leadTest1);    
    UnqulifiedLeads leadsTest = new UnqulifiedLeads(sc); 

    Test.stopTest();
    
    }
    
}

Error Message: Error: Compile Error: Constructor not defined: [UnqulifiedLeads].<Constructor>(ApexPages.StandardController) at line 28 column 33