• Mark Gallagher
  • NEWBIE
  • 10 Points
  • Member since 2018
  • Salesforce.com Director
  • The Heyl Group


  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 9
    Replies
I want to know if I can open an lightning component through a button on a visualforce page.
Each button corresponds to a different component that I want to pop up I was wondering if I could write javascript to do this. If so what would that look like? I've never written javascript before.

<--- Visual Force Page --->
<apex:page standardController="Leverage__c">
    <apex:form >
        <h1>
            Support Services
        </h1>
        <apex:pageBlock>
            <apex:pageBlockButtons>
                <apex:commandButton value="Batman" onclick=""/>
                <apex:commandButton value="Superman" onclick=""/>
                <apex:commandButton value="Wonder Woman" onclick=""/>
                <apex:commandButton value="Flash" onclick=""/>
            </apex:pageBlockButtons>
        </apex:pageBlock>
        
    </apex:form>
</apex:page>
Built a trigger that limits the number of a certain type of Lead a User can have trying to Test it. I have four methods that test four different Users that have four differnt caps 100, 200, 300, and 400. The 200 and the 400 Methods work, but the 100 and 300 don't work. They are all the exact same method and user. I have tried switching the users and that doesn't work, but if I change the caps then it works. The error I'm getting is Assertion Failed

<--- Trigger Code --->
trigger LimitLeads on Lead (after update)
{
    List<Lead> trueLeads = new List<Lead>();
    Set<Id> LeadOwner = new Set<Id>();
    List<User> capName = new List<User>();
    
    for(Integer i = 0; i < Trigger.New.size(); i++)
    {
        if(Trigger.New[i].OwnerId != Trigger.old[i].OwnerId && Trigger.New[i].OwnerId != Null)
        {
            LeadOwner.add(Trigger.New[i].OwnerId);
        }
    }
    
    if(LeadOwner.size() > 0)
    {
        trueLeads = [SELECT Id FROM Lead WHERE (Status = '01-New' OR Status = '20-Nurture') AND
                                               RecordTypeId = '01250000000Mvl2AAC' AND
                                               Lead_Source_Type__c = 'Team Lead' AND
                                               OwnerId in: LeadOwner];
        capName = [SELECT Pipeline_Cap__c, Full_Name__c FROM User WHERE Id in: LeadOwner];
        
        for(Lead ld: Trigger.New)
        {   
            if((ld.Status == '01-New' || ld.Status == '20-Nurture') && ld.RecordTypeId == '01250000000Mvl2AAC' && ld.Lead_Source_Type__c == 'Team Lead')
            {
                Integer pipelineCap = (Integer) capName[0].Pipeline_Cap__c;
                String name = capName[0].Full_Name__c;
                Integer numLeads = trueLeads.size();
                Integer remove = numLeads - pipelineCap;
                if(numLeads > pipelineCap)
                {
                    ld.OwnerId.addError( name + ' too many team leads remove some to add more team leads');
                } 
            } 
        }
    }
}

<--- Method Code --->
   @isTest static void TestCap100True()
    {
        User[] cap100Id =  [SELECT Pipeline_Cap__c FROM User WHERE Full_Name__c = 'Test User']; 
        Id cap100 = cap100Id[0].Id;
        Integer cap = (Integer)cap100Id[0].Pipeline_Cap__c;
        
       
        List<Lead> trueLead = TestLimitLeadsDataFactory.trueLeads();
        
        for(Lead ld: trueLead)
        {
            ld.OwnerId = cap100;
        }
        
        Test.startTest();
        Database.SaveResult[] results = Database.update(trueLead,false);
        Test.stopTest();
        
        for(Integer i = 0; i < results.size(); i++)
        {
            if(i < cap)
            {
                System.assert(results[i].isSuccess());
            }
            else
            {
                System.assert(!results[i].isSuccess());
                System.debug('result ' + i + 'failed');
            }
        }
    }
This trigger working the way I want it to, but I'm getting the too many SOQL queries error in my test class I've tried moving the queries out of the for loop because I know that can cause govenor limit hits, but I haven't done it properly help please.

<---Trigger Code--->
trigger LimitLeads on Lead (after update)
{
    List<Lead> ownerChange = new List<Lead>();
    for(Integer i = 0; i < Trigger.New.size(); i++)
    {
        if(Trigger.New[i].OwnerId != Trigger.old[i].OwnerId)
        {
            ownerChange.add(Trigger.New[i]);
        }
    }
    for(Lead ld: ownerChange)
    {
        if((ld.Status == '01-New' || ld.Status == '20-Nurture') && ld.RecordTypeId == '01250000000Mvl2AAC' && ld.Lead_Source_Type__c == 'Team Lead') 
        {
                Id LeadOwner = ld.OwnerId;
                List<Lead> trueLeads = [SELECT Id FROM Lead WHERE OwnerId =: LeadOwner AND 
                                       (Status = '01-New' OR Status = '20-Nurture') AND
                                       RecordTypeId = '01250000000Mvl2AAC' AND
                                       Lead_Source_Type__c = 'Team Lead'];
                List<User> capName = [SELECT Pipeline_Cap__c, Full_Name__c FROM User WHERE Id =: LeadOwner];
                Integer pipelineCap = (Integer) capName[0].Pipeline_Cap__c;
                String name = capName[0].Full_Name__c;
                Integer numLeads = trueLeads.size();
                Integer remove = numLeads - pipelineCap;
                if(numLeads > pipelineCap)
                {
                    ld.OwnerId.addError( name + ' too many team leads remove some to add more team leads');
                }
        }      
    }
}
This trigger isn't firing and I can't figure out why help please

<--Trigger Code--->

trigger LimitLeads on Lead (before update) 
{
    for(Lead ld: Trigger.New)
    {  
        String LeadOwner = ld.OwnerId;
        if(ld.Lead_Source_Type__c == 'Team Lead' &&  (ld.Status == '01-New' && ld.Status == '20-Nurture') && ld.RecordTypeId == '01250000000Mvl2AAC')
        {
            List<Lead> leads = [SELECT Id FROM Lead WHERE OwnerId =: LeadOwner AND Lead_Source_Type__c =: 'Team Lead' AND (Status = '01-New' OR Status = '20-Nurture') AND RecordTypeId = '01250000000Mvl2AAC'];
            List<User> caps  = [SELECT Pipeline_Cap__c FROM User WHERE Id =: LeadOwner];
            Integer numLeads = leads.size();
            Integer cap = (Integer)caps[0].Pipeline_Cap__c;
            Integer remove = leads.size() - cap + 1;
                                              
            If(numLeads > cap) 
            {
                ld.OwnerId.addError('You already have too many Team Leads. Please remove leads before adding a new one.');
            }  
        
        }
    }    
}
Wrote a trigger that caps how many of a certain type of lead that a user can have need help writing the test class

TestFullCapStatus and TestFullCapType are woriking properly, but the rest aren't and I don't understand why?
TestFullCapTrue shouldn't allow any of the leads to update and the others should allow all the leads under their respective caps to change and reject the rest. Each List<Lead> has 500 so for example TestCap100True should allow the first 100 to change leadOwner, but not the next 400.

<--- Trigger--->
trigger Limit100Leads on Lead (before update)  
{
       for(Lead ld: Trigger.New)
    {  
        Id LeadOwner = ld.OwnerId;
        if(ld.Lead_Source_Type__c == 'Team Lead' &&  (ld.Status == '01-New' && ld.Status == '20-Nurture') && ld.RecordTypeId == '01250000000Mvl2AAC')
        {
            List<Lead> leads = [SELECT OwnerId FROM Lead WHERE OwnerId =: LeadOwner AND Lead_Source_Type__c =: 'Team Lead'];
            List<User> caps  = [SELECT Pipeline_Cap__c FROM User WHERE Id =: LeadOwner];
            Integer numLeads = leads.size();
               Integer cap = (Integer)caps[0].Pipeline_Cap__c;
            Integer remove = leads.size() - cap + 1;
            
                                              
            If(numLeads > cap) 
            {
                ld.OwnerId.addError('You already have too many Team Leads. Please remove leads before adding a new one.');
            }  
        }
    }
}

<---Test Class--->

@isTest
private class TestLimitData

    @isTest static void TestFullCap()
    {
        User[] MarkId =  [SELECT Id FROM User WHERE Full_Name__c = 'Mark Gallagher']; 
        Id Mark = MarkId[0].Id;
       
        List<Lead> trueLead = TestLimitDataFactory.trueLeads();
        
        for(Lead ld: trueLead)
        {
            ld.OwnerId = Mark;
        }
        
        Test.startTest();
        Database.SaveResult[] results = Database.update(trueLead, true);
        Test.stopTest();
        
        for(Database.SaveResult res : results)
        {
            System.assert(!res.isSuccess());
        }
    }
    
    @isTest static void TestFullCapStatus()
    {
        User[] MarkId =  [SELECT Id FROM User WHERE Full_Name__c = 'Mark Gallagher']; 
        Id Mark = MarkId[0].Id;
       
        List<Lead> statusLead = TestLimitDataFactory.statusLeads();
        
        for(Lead ld: statusLead)
        {
            ld.OwnerId = Mark;
        }
        
        Test.startTest();
        Database.SaveResult[] results = Database.update(statusLead,false);
        Test.stopTest();
        
        for(Database.SaveResult res : results)
        {
            System.assert(res.isSuccess());
        }
    }
    
    @isTest static void TestFullCapType()
    {
        User[] MarkId =  [SELECT Id FROM User WHERE Full_Name__c = 'Mark Gallagher']; 
        Id Mark = MarkId[0].Id;
       
        List<Lead> typeLead = TestLimitDataFactory.typeLeads();
        
        for(Lead ld: typeLead)
        {
            ld.OwnerId = Mark;
        }
        
        Test.startTest();
        Database.SaveResult[] results = Database.update(typeLead,false);
        Test.stopTest();
        
        for(Database.SaveResult res : results)
        {
            System.assert(res.isSuccess());
        }
    }
    
    @isTest static void TestCap100True()
    {
        User[] cap100Id =  [SELECT Pipeline_Cap__c FROM User WHERE Full_Name__c = 'Jayte Acree']; 
        Id cap100 = cap100Id[0].Id;
        Double cap = cap100Id[0].Pipeline_Cap__c;
        
       
        List<Lead> trueLead = TestLimitDataFactory.trueLeads();
        
        for(Lead ld: trueLead)
        {
            ld.OwnerId = cap100;
        }
        
        Test.startTest();
        Database.SaveResult[] results = Database.update(trueLead,false);
        Test.stopTest();
        
        for(Integer i = 0; i < results.size(); i++)
        {
            if(i < cap)
            {
                System.assert(results[i].isSuccess());
            }
            else
            {
                System.assert(!results[i].isSuccess());
            }
        }
    }
    
    @isTest static void TestCap200True()
    {
        User[] cap200Id =  [SELECT Pipeline_Cap__c FROM User WHERE Full_Name__c = 'Sandra Alvidrez']; 
        Id cap200 = cap200Id[0].Id;
        Double cap = cap200Id[0].Pipeline_Cap__c;
        
       
        List<Lead> trueLead = TestLimitDataFactory.trueLeads();
        
        for(Lead ld: trueLead)
        {
            ld.OwnerId = cap200;
        }
        
        Test.startTest();
        Database.SaveResult[] results = Database.update(trueLead,false);
        Test.stopTest();
        
        for(Integer i = 0; i < results.size(); i++)
        {
            if(i < cap)
            {
                System.assert(results[i].isSuccess());
            }
            else
            {
                System.assert(!results[i].isSuccess());
            }
        }
    }
    
    @isTest static void TestCap300True()
    {
        User[] cap300Id =  [SELECT Pipeline_Cap__c FROM User WHERE Full_Name__c = 'Johnny App']; 
        Id cap300 = cap300Id[0].Id;
        Double cap = cap300Id[0].Pipeline_Cap__c;
        
       
        List<Lead> trueLead = TestLimitDataFactory.trueLeads();
        
        for(Lead ld: trueLead)
        {
            ld.OwnerId = cap300;
        }
        
        Test.startTest();
        Database.SaveResult[] results = Database.update(trueLead,false);
        Test.stopTest();
        
        for(Integer i = 0; i < results.size(); i++)
        {
            if(i < cap)
            {
                System.assert(results[i].isSuccess());
            }
            else
            {
                System.assert(!results[i].isSuccess());
            }
        }
    }
    
    @isTest static void TestCap400True()
    {
        User[] cap400Id =  [SELECT Pipeline_Cap__c FROM User WHERE Full_Name__c = 'Allison Arevalo']; 
        Id cap400 = cap400Id[0].Id;
        Double cap = cap400Id[0].Pipeline_Cap__c;
        
       
        List<Lead> trueLead = TestLimitDataFactory.trueLeads();
        
        for(Lead ld: trueLead)
        {
            ld.OwnerId = cap400;
        }
        
        Test.startTest();
        Database.SaveResult[] results = Database.update(trueLead,false);
        Test.stopTest();
        
        for(Integer i = 0; i < results.size(); i++)
        {
            if(i < cap)
            {
                System.assert(results[i].isSuccess());
            }
            else
            {
                System.assert(!results[i].isSuccess());
            }
        }
    }
}
Wrote a trigger to limit the amount of leads a specific owner can have. Trying to write the test class for the trigger and am getting this error:
System.DmlException: Insert failed. First exception on row 0 with id a0O17000001aWCWEA2; first error: INVALID_FIELD_FOR_INSERT_UPDATE
<--- Trigger Code --->
trigger Limit100Leads on Lead (before insert, before update)  
{
       for(Lead ld: Trigger.New)
    {  
        String LeadOwner = ld.OwnerId;
        if(ld.Lead_Source_Type__c == 'Team Lead' &&  (ld.Status == '01-New' && ld.Status == '20-Nurture' ) && ld.RecordTypeId == '01250000000Mvl2AAC')
        {
            List<Lead> leads = [SELECT OwnerId FROM Lead WHERE OwnerId =: LeadOwner AND Lead_Source_Type__c = 'Team Lead'];
            List<User> caps  = [SELECT Pipeline_Cap__c FROM User WHERE Id =: LeadOwner];
            Integer numLeads = leads.size();
               Integer cap = (Integer)caps[0].Pipeline_Cap__c;
            Integer remove = leads.size() - cap + 2;
            
                                              
            If(numLeads > cap) 
            {
                ld.OwnerId.addError('You already have '+ leads.size() + ' Team Leads. Please remove ' + remove + ' before adding a new one.');
            }  
        }
    }
}

<--- Test Class Code --->
@isTest
private class TestLimitData

    @isTest static void TestFullCap()
    {
        User[] MarkId =  [SELECT Id FROM User WHERE Full_Name__c = 'Mark Gallagher']; 
        Id Mark = MarkId[0].Id;
       
        List<Lead> trueLead = TestLimitDataFactory.trueLeads(Mark);
        
        Test.startTest();
        Database.SaveResult[] results = Database.insert(trueLead, false);
        Test.stopTest();
        
        for(Database.SaveResult res : results)
        {
            System.assert(!res.isSuccess());
        }
    }
    
    @isTest static void TestFullCapStatus()
    {
        User[] MarkId =  [SELECT Id FROM User WHERE Full_Name__c = 'Mark Gallagher']; 
        Id Mark = MarkId[0].Id;
       
        List<Lead> statusLead = TestLimitDataFactory.statusLeads(Mark);
        
        Test.startTest();
        Database.SaveResult[] results = Database.insert(statusLead, true);
        Test.stopTest();
        
        for(Database.SaveResult res : results)
        {
            System.assert(res.isSuccess());
        }
    }
}
<aura:component  implements="flexipage:availableForAllPageTypes" access="global" >
    <aura:if isTrue="{!$Lead.Sys_Household__c == 'Wally West Jesse Quick'}">
        <img src="{!$Resource.Flash}"/>
    <aura:set attribute="else"> 
        <p>False </p>
    </aura:set>
    </aura:if>
</aura:component>

I am trying to get a picture to show up based on a condition the problem is that I know this condition to be true, but it is giving the False output. 
<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
    <aura:attribute name="Lead" type="Lead"/>
    <aura:if isTrue="{!and(v.Lead.pi__score__c != 0, v.Lead.Email = "darkknight@theherogothamneeds.com")}">
        <p>    one step closer</p>
    <aura:set attribute="else">
        <p> still one step closer</p>
       </aura:set>
    </aura:if>
</aura:component>
Built a trigger that limits the number of a certain type of Lead a User can have trying to Test it. I have four methods that test four different Users that have four differnt caps 100, 200, 300, and 400. The 200 and the 400 Methods work, but the 100 and 300 don't work. They are all the exact same method and user. I have tried switching the users and that doesn't work, but if I change the caps then it works. The error I'm getting is Assertion Failed

<--- Trigger Code --->
trigger LimitLeads on Lead (after update)
{
    List<Lead> trueLeads = new List<Lead>();
    Set<Id> LeadOwner = new Set<Id>();
    List<User> capName = new List<User>();
    
    for(Integer i = 0; i < Trigger.New.size(); i++)
    {
        if(Trigger.New[i].OwnerId != Trigger.old[i].OwnerId && Trigger.New[i].OwnerId != Null)
        {
            LeadOwner.add(Trigger.New[i].OwnerId);
        }
    }
    
    if(LeadOwner.size() > 0)
    {
        trueLeads = [SELECT Id FROM Lead WHERE (Status = '01-New' OR Status = '20-Nurture') AND
                                               RecordTypeId = '01250000000Mvl2AAC' AND
                                               Lead_Source_Type__c = 'Team Lead' AND
                                               OwnerId in: LeadOwner];
        capName = [SELECT Pipeline_Cap__c, Full_Name__c FROM User WHERE Id in: LeadOwner];
        
        for(Lead ld: Trigger.New)
        {   
            if((ld.Status == '01-New' || ld.Status == '20-Nurture') && ld.RecordTypeId == '01250000000Mvl2AAC' && ld.Lead_Source_Type__c == 'Team Lead')
            {
                Integer pipelineCap = (Integer) capName[0].Pipeline_Cap__c;
                String name = capName[0].Full_Name__c;
                Integer numLeads = trueLeads.size();
                Integer remove = numLeads - pipelineCap;
                if(numLeads > pipelineCap)
                {
                    ld.OwnerId.addError( name + ' too many team leads remove some to add more team leads');
                } 
            } 
        }
    }
}

<--- Method Code --->
   @isTest static void TestCap100True()
    {
        User[] cap100Id =  [SELECT Pipeline_Cap__c FROM User WHERE Full_Name__c = 'Test User']; 
        Id cap100 = cap100Id[0].Id;
        Integer cap = (Integer)cap100Id[0].Pipeline_Cap__c;
        
       
        List<Lead> trueLead = TestLimitLeadsDataFactory.trueLeads();
        
        for(Lead ld: trueLead)
        {
            ld.OwnerId = cap100;
        }
        
        Test.startTest();
        Database.SaveResult[] results = Database.update(trueLead,false);
        Test.stopTest();
        
        for(Integer i = 0; i < results.size(); i++)
        {
            if(i < cap)
            {
                System.assert(results[i].isSuccess());
            }
            else
            {
                System.assert(!results[i].isSuccess());
                System.debug('result ' + i + 'failed');
            }
        }
    }
This trigger isn't firing and I can't figure out why help please

<--Trigger Code--->

trigger LimitLeads on Lead (before update) 
{
    for(Lead ld: Trigger.New)
    {  
        String LeadOwner = ld.OwnerId;
        if(ld.Lead_Source_Type__c == 'Team Lead' &&  (ld.Status == '01-New' && ld.Status == '20-Nurture') && ld.RecordTypeId == '01250000000Mvl2AAC')
        {
            List<Lead> leads = [SELECT Id FROM Lead WHERE OwnerId =: LeadOwner AND Lead_Source_Type__c =: 'Team Lead' AND (Status = '01-New' OR Status = '20-Nurture') AND RecordTypeId = '01250000000Mvl2AAC'];
            List<User> caps  = [SELECT Pipeline_Cap__c FROM User WHERE Id =: LeadOwner];
            Integer numLeads = leads.size();
            Integer cap = (Integer)caps[0].Pipeline_Cap__c;
            Integer remove = leads.size() - cap + 1;
                                              
            If(numLeads > cap) 
            {
                ld.OwnerId.addError('You already have too many Team Leads. Please remove leads before adding a new one.');
            }  
        
        }
    }    
}
Wrote a trigger to limit the amount of leads a specific owner can have. Trying to write the test class for the trigger and am getting this error:
System.DmlException: Insert failed. First exception on row 0 with id a0O17000001aWCWEA2; first error: INVALID_FIELD_FOR_INSERT_UPDATE
<--- Trigger Code --->
trigger Limit100Leads on Lead (before insert, before update)  
{
       for(Lead ld: Trigger.New)
    {  
        String LeadOwner = ld.OwnerId;
        if(ld.Lead_Source_Type__c == 'Team Lead' &&  (ld.Status == '01-New' && ld.Status == '20-Nurture' ) && ld.RecordTypeId == '01250000000Mvl2AAC')
        {
            List<Lead> leads = [SELECT OwnerId FROM Lead WHERE OwnerId =: LeadOwner AND Lead_Source_Type__c = 'Team Lead'];
            List<User> caps  = [SELECT Pipeline_Cap__c FROM User WHERE Id =: LeadOwner];
            Integer numLeads = leads.size();
               Integer cap = (Integer)caps[0].Pipeline_Cap__c;
            Integer remove = leads.size() - cap + 2;
            
                                              
            If(numLeads > cap) 
            {
                ld.OwnerId.addError('You already have '+ leads.size() + ' Team Leads. Please remove ' + remove + ' before adding a new one.');
            }  
        }
    }
}

<--- Test Class Code --->
@isTest
private class TestLimitData

    @isTest static void TestFullCap()
    {
        User[] MarkId =  [SELECT Id FROM User WHERE Full_Name__c = 'Mark Gallagher']; 
        Id Mark = MarkId[0].Id;
       
        List<Lead> trueLead = TestLimitDataFactory.trueLeads(Mark);
        
        Test.startTest();
        Database.SaveResult[] results = Database.insert(trueLead, false);
        Test.stopTest();
        
        for(Database.SaveResult res : results)
        {
            System.assert(!res.isSuccess());
        }
    }
    
    @isTest static void TestFullCapStatus()
    {
        User[] MarkId =  [SELECT Id FROM User WHERE Full_Name__c = 'Mark Gallagher']; 
        Id Mark = MarkId[0].Id;
       
        List<Lead> statusLead = TestLimitDataFactory.statusLeads(Mark);
        
        Test.startTest();
        Database.SaveResult[] results = Database.insert(statusLead, true);
        Test.stopTest();
        
        for(Database.SaveResult res : results)
        {
            System.assert(res.isSuccess());
        }
    }
}
<aura:component  implements="flexipage:availableForAllPageTypes" access="global" >
    <aura:if isTrue="{!$Lead.Sys_Household__c == 'Wally West Jesse Quick'}">
        <img src="{!$Resource.Flash}"/>
    <aura:set attribute="else"> 
        <p>False </p>
    </aura:set>
    </aura:if>
</aura:component>

I am trying to get a picture to show up based on a condition the problem is that I know this condition to be true, but it is giving the False output. 
<aura:component implements="flexipage:availableForAllPageTypes" access="global" >
    <aura:attribute name="Lead" type="Lead"/>
    <aura:if isTrue="{!and(v.Lead.pi__score__c != 0, v.Lead.Email = "darkknight@theherogothamneeds.com")}">
        <p>    one step closer</p>
    <aura:set attribute="else">
        <p> still one step closer</p>
       </aura:set>
    </aura:if>
</aura:component>