• LoganUT
  • NEWBIE
  • 20 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 5
    Questions
  • 12
    Replies
Hello everyone! 

I had this trigger and test class working well with 100% test coverage, then I added the Account__c field and now my test class is failing. The error I recieve is: System.QueryException: List has no rows for assignment to SObject. 

I have tried writing my query as a list on the Location_Master__c section, but it still did not work. I have tried just about everythign I can think of..

Below I have included a section of my trigger and test class:
 
trigger locStatusOpp on Opportunity (after update, after insert) { 
    
    List<Location_Detail__c> 	loctoInsert  	 = new List<Location_Detail__c>();
    List<Location_Wait_List__c> loctoWaitInsert  = new List<Location_Wait_List__c>();    
    List<Location_Master__c>  	locMaster 		 = new List<Location_Master__c>();
    
        for (Opportunity opp : Trigger.new) {
         if (opp.StageName == 'Closed Won' && opp.Location__c == 'Auburn Hills MI' && opp.Category__c != null && opp.Type_of_Charge__c == 'Subscription'){
            Location_Master__c locAuburnHillsMI = [SELECT Id FROM Location_Master__c WHERE Name = 'Auburn Hills MI' LIMIT 1];
            	   Location_Detail__c locNewAuburnHillsMI =  new Location_Detail__c(
           											     Name =  opp.Name,
           									   Account__c =  opp.AccountId,
           									  Location__c =  opp.Location__c,
          									   On_List__c =  1,
                       Location_Master__c =  locAuburnHillsMI.Id,
                       					Active__c =  True,
          								 Vendor_Type__c =  opp.Category__c);
                if(opp.Location__c == 'Auburn Hills MI'){
                loctoInsert.add(locNewAuburnHillsMI);
                    }
         }
 
@istest  
public class locStatusOppTEST {
    
static testMethod void locStatusOppTEST1(){
        List<Location_Detail__c> loctoInsert  = new List<Location_Detail__c>();
    
        Account acc = new Account();
            acc.Name = 'Test';
            insert acc;    
        
        Location_Master__c locMaster = new Location_Master__c();
            locMaster.Name = 'Auburn Hills MI';
            insert locMaster;
        
        Opportunity opp = new Opportunity();
            opp.Name              = 'Test';
            opp.AccountId         =  acc.Id;
            opp.Type_of_Charge__c = 'Subscription';
            opp.Category__c       = 'Cake Decorator';
            opp.Location__c       = 'Auburn Hills MI';
            opp.StageName         = 'Closed Won';
            opp.CloseDate         = date.newInstance(2017, 2, 20);
            insert opp;

    }

 
Hello! 

I have built a Visualforce page and it has worked perfectly in a Developed enviornment and our Sandbox enviornment, but it was just deloyed to production and the tab set up for the VFP is completely blank.

Has anyone seen this issue before?

I have included the VFP code and a screen shot...
 
<apex:page standardController="Location_Master__c" recordSetVar="locMaster" sidebar="true" > 
        <apex:form >
        <apex:pageBlock title="Location Vendors" id="locationVendors">
        
            <!-- Vacancey List -->
       <apex:pageBlockTable value="{! locMaster }" var="locVac" >
                <apex:column >
                   <apex:facet name="header">URL</apex:facet>
                   <apex:outputLink value="/{!locVac.id}">{!locVac.Name}</apex:outputLink>
                </apex:column>
                <apex:column value="{! locVac.Current_Vendors__c}" />
                <apex:column value="{! locVac.Current_Value__c }" />
                <apex:column value="{! locVac.Available_Vendors__c }" />
                <apex:column value="{! locVac.Available_Value__c }" />

        </apex:pageBlockTable> 
             
<!-- Pagination -->
        <table style="widt: 100%"><tr>
            <td>
                Page: <apex:outputText value="{! PageNumber } of {! CEILING(ResultSize / PageSize) }"/>
            </td>
            <td align="center">
                <!-- Previous Page -->
                <!-- active -->
                <apex:commandLink action="{! Previous }" value=" Previous" rendered="{! HasPrevious }" />
                <!-- inactive (no earlier pages) -->
                <apex:outputText style="color: #ccc;" value=" Previous" rendered="{! NOT(HasPrevious) }" />
                
                &nbsp;&nbsp;
                
                <!-- Next Page -->
                <!-- active -->
                <apex:commandLink action="{! Next }" value="Next" rendered="{! HasNext }" />
                <!-- inactive (no more pages) -->
                <apex:outputText style="color: #ccc;" value="Next" rendered="{! NOT(HasNext) }" />
            </td>
            <td align="right">
                Records per page:
                <apex:selectList value="{! PageSize }" size="1">
                    <apex:selectOption itemValue="5" itemLabel="5" />
                    <apex:selectOption itemValue="20" itemLabel="20" />
                    <apex:selectOption itemValue="50" itemLabel="50" />
                    <apex:actionSupport event="onchange" reRender="locationVendors" />
                </apex:selectList>
            </td>
        </tr></table>            
            
        </apex:pageBlock>    
</apex:form>        
</apex:page>

User-added image
I have built an extensive Opportunity trigger that creates a new Location_Detail__c record, which is the child to Locaiton Master.
I am having a difficult time building a test class to deploy it. I can only achive 10% coverage, and only seem to able to cover the if statement.
Does anyone have any ideas how to test the remainder? I have attahced a section of the trigger and my test class.

Thanks, you guys are the best! 
 
trigger locStatusOpp on Opportunity (after update, after insert) { 
    
    List<Location_Detail__c> loctoInsert  = new List<Location_Detail__c>();
    
        for (Opportunity opp : Trigger.new) {
         if (opp.StageName == 'Closed Won' && opp.Location__c == 'Auburn Hills MI' && opp.Category__c != null && opp.Type_of_Charge__c == 'Subscription '){
            Location_Master__c locAuburnHillsMI = [SELECT Id FROM Location_Master__c
                                            WHERE Name = 'Auburn Hills MI' LIMIT 1];
            Location_Detail__c locNewAuburnHillsMI     =  new Location_Detail__c(
            Name                          =  opp.Name,
            Location__c                   =  opp.Location__c,
            On_List__c					  =  1,
            Location_Master__c			  =  locAuburnHillsMI.Id,
            Vendor_Type__c                =  opp.Category__c);  
                if(opp.Location__c == 'Auburn Hills MI'){
                loctoInsert.add(locNewAuburnHillsMI);
                    }
         }
 
@istest
private class locStatusOppTEST {
    
    @isTest static void locStatusOppTEST(){
        
       	List<Location_Detail__c> loctoInsert  = new List<Location_Detail__c>();
        
        Opportunity opp = new Opportunity();
            opp.Name 			  = 'Test';
            opp.AccountId   	  =  opp.Id;
            opp.Type_of_Charge__c = 'Subscription';
            opp.Category__c       = 'Bartender';
            opp.Location__c	      = 'Des Moines IA';
            opp.StageName		  = 'Closed Won';
            opp.CloseDate		  = date.newInstance(2017, 2, 20);
            insert opp;
    
    }
}

 
When an opportunituy is changed to 'Closed Won' we would like to have a new custom object, Location_Status__c, created. I have included my trigger so far. When I save it I dont have any errors and am able to update/create Opportunities without any errors, but the custom object is not created. This code is specific for an Opportunity that is located in Albuquerque NM and hase the StageName of 'Closed Won'.

Thanks! 
 
trigger locStatusOpp on Opportunity (after update) {

    for (Opportunity opp : Trigger.new) {
        
        List<Location_Status__c> loc = [SELECT Id,
                                        On_List__c,
                                        Location__c,
                                        Vendor_Type__c,
                                        OpportunityR__c
                                 FROM   Location_Status__c];
        for (Location_Status__c locLoop : loc)
        if (opp.StageName == 'Closed Won' || opp.Vendors__c == 'Bartender' || opp.Location__c == 'Albuquerque NM'){
            Location_Status__c locNew     =  new Location_Status__c(
            Name                   		  =  opp.Name,
            Location__c           		  = 'Albuquerque NM',
            Vendor_Type__c       		  = 'Bartender',
            OpportunityR__c       		  =  opp.Id);      
        }
        insert loc;
    }
}

 
We have changed our buisness process and have reassigned this trigger to a new Object. I have included the section of code that is causing the issue. The error is occuring in the last line of code.
Hello everyone! 

I had this trigger and test class working well with 100% test coverage, then I added the Account__c field and now my test class is failing. The error I recieve is: System.QueryException: List has no rows for assignment to SObject. 

I have tried writing my query as a list on the Location_Master__c section, but it still did not work. I have tried just about everythign I can think of..

Below I have included a section of my trigger and test class:
 
trigger locStatusOpp on Opportunity (after update, after insert) { 
    
    List<Location_Detail__c> 	loctoInsert  	 = new List<Location_Detail__c>();
    List<Location_Wait_List__c> loctoWaitInsert  = new List<Location_Wait_List__c>();    
    List<Location_Master__c>  	locMaster 		 = new List<Location_Master__c>();
    
        for (Opportunity opp : Trigger.new) {
         if (opp.StageName == 'Closed Won' && opp.Location__c == 'Auburn Hills MI' && opp.Category__c != null && opp.Type_of_Charge__c == 'Subscription'){
            Location_Master__c locAuburnHillsMI = [SELECT Id FROM Location_Master__c WHERE Name = 'Auburn Hills MI' LIMIT 1];
            	   Location_Detail__c locNewAuburnHillsMI =  new Location_Detail__c(
           											     Name =  opp.Name,
           									   Account__c =  opp.AccountId,
           									  Location__c =  opp.Location__c,
          									   On_List__c =  1,
                       Location_Master__c =  locAuburnHillsMI.Id,
                       					Active__c =  True,
          								 Vendor_Type__c =  opp.Category__c);
                if(opp.Location__c == 'Auburn Hills MI'){
                loctoInsert.add(locNewAuburnHillsMI);
                    }
         }
 
@istest  
public class locStatusOppTEST {
    
static testMethod void locStatusOppTEST1(){
        List<Location_Detail__c> loctoInsert  = new List<Location_Detail__c>();
    
        Account acc = new Account();
            acc.Name = 'Test';
            insert acc;    
        
        Location_Master__c locMaster = new Location_Master__c();
            locMaster.Name = 'Auburn Hills MI';
            insert locMaster;
        
        Opportunity opp = new Opportunity();
            opp.Name              = 'Test';
            opp.AccountId         =  acc.Id;
            opp.Type_of_Charge__c = 'Subscription';
            opp.Category__c       = 'Cake Decorator';
            opp.Location__c       = 'Auburn Hills MI';
            opp.StageName         = 'Closed Won';
            opp.CloseDate         = date.newInstance(2017, 2, 20);
            insert opp;

    }

 
Hello! 

I have built a Visualforce page and it has worked perfectly in a Developed enviornment and our Sandbox enviornment, but it was just deloyed to production and the tab set up for the VFP is completely blank.

Has anyone seen this issue before?

I have included the VFP code and a screen shot...
 
<apex:page standardController="Location_Master__c" recordSetVar="locMaster" sidebar="true" > 
        <apex:form >
        <apex:pageBlock title="Location Vendors" id="locationVendors">
        
            <!-- Vacancey List -->
       <apex:pageBlockTable value="{! locMaster }" var="locVac" >
                <apex:column >
                   <apex:facet name="header">URL</apex:facet>
                   <apex:outputLink value="/{!locVac.id}">{!locVac.Name}</apex:outputLink>
                </apex:column>
                <apex:column value="{! locVac.Current_Vendors__c}" />
                <apex:column value="{! locVac.Current_Value__c }" />
                <apex:column value="{! locVac.Available_Vendors__c }" />
                <apex:column value="{! locVac.Available_Value__c }" />

        </apex:pageBlockTable> 
             
<!-- Pagination -->
        <table style="widt: 100%"><tr>
            <td>
                Page: <apex:outputText value="{! PageNumber } of {! CEILING(ResultSize / PageSize) }"/>
            </td>
            <td align="center">
                <!-- Previous Page -->
                <!-- active -->
                <apex:commandLink action="{! Previous }" value=" Previous" rendered="{! HasPrevious }" />
                <!-- inactive (no earlier pages) -->
                <apex:outputText style="color: #ccc;" value=" Previous" rendered="{! NOT(HasPrevious) }" />
                
                &nbsp;&nbsp;
                
                <!-- Next Page -->
                <!-- active -->
                <apex:commandLink action="{! Next }" value="Next" rendered="{! HasNext }" />
                <!-- inactive (no more pages) -->
                <apex:outputText style="color: #ccc;" value="Next" rendered="{! NOT(HasNext) }" />
            </td>
            <td align="right">
                Records per page:
                <apex:selectList value="{! PageSize }" size="1">
                    <apex:selectOption itemValue="5" itemLabel="5" />
                    <apex:selectOption itemValue="20" itemLabel="20" />
                    <apex:selectOption itemValue="50" itemLabel="50" />
                    <apex:actionSupport event="onchange" reRender="locationVendors" />
                </apex:selectList>
            </td>
        </tr></table>            
            
        </apex:pageBlock>    
</apex:form>        
</apex:page>

User-added image
I have built an extensive Opportunity trigger that creates a new Location_Detail__c record, which is the child to Locaiton Master.
I am having a difficult time building a test class to deploy it. I can only achive 10% coverage, and only seem to able to cover the if statement.
Does anyone have any ideas how to test the remainder? I have attahced a section of the trigger and my test class.

Thanks, you guys are the best! 
 
trigger locStatusOpp on Opportunity (after update, after insert) { 
    
    List<Location_Detail__c> loctoInsert  = new List<Location_Detail__c>();
    
        for (Opportunity opp : Trigger.new) {
         if (opp.StageName == 'Closed Won' && opp.Location__c == 'Auburn Hills MI' && opp.Category__c != null && opp.Type_of_Charge__c == 'Subscription '){
            Location_Master__c locAuburnHillsMI = [SELECT Id FROM Location_Master__c
                                            WHERE Name = 'Auburn Hills MI' LIMIT 1];
            Location_Detail__c locNewAuburnHillsMI     =  new Location_Detail__c(
            Name                          =  opp.Name,
            Location__c                   =  opp.Location__c,
            On_List__c					  =  1,
            Location_Master__c			  =  locAuburnHillsMI.Id,
            Vendor_Type__c                =  opp.Category__c);  
                if(opp.Location__c == 'Auburn Hills MI'){
                loctoInsert.add(locNewAuburnHillsMI);
                    }
         }
 
@istest
private class locStatusOppTEST {
    
    @isTest static void locStatusOppTEST(){
        
       	List<Location_Detail__c> loctoInsert  = new List<Location_Detail__c>();
        
        Opportunity opp = new Opportunity();
            opp.Name 			  = 'Test';
            opp.AccountId   	  =  opp.Id;
            opp.Type_of_Charge__c = 'Subscription';
            opp.Category__c       = 'Bartender';
            opp.Location__c	      = 'Des Moines IA';
            opp.StageName		  = 'Closed Won';
            opp.CloseDate		  = date.newInstance(2017, 2, 20);
            insert opp;
    
    }
}

 
Hi,

I'm running into an issue where I have a custom object called Agent_Project__c.  What I'm hoping to do with this is allow various leadership groups and management users to create their own projects and assign however many users to the project.  I can't do set groups because I want the user to have the flexibility to add and remove users from the project whenever they need and there to be a related list to show all users assigned to the project.  The rest of the functions I can make but this one part I'm stuck with. 

Any ideas or help?  Anyone out there that has done something similar?
When I signed up for Trailhead, I used my work email. I am a contract worker and just realized that in a few months when my assignment here is done, I will no longer have access to that email. Is there a way to change my email address, or will have I have to start all over and re-earn the badges I already have?
When an opportunituy is changed to 'Closed Won' we would like to have a new custom object, Location_Status__c, created. I have included my trigger so far. When I save it I dont have any errors and am able to update/create Opportunities without any errors, but the custom object is not created. This code is specific for an Opportunity that is located in Albuquerque NM and hase the StageName of 'Closed Won'.

Thanks! 
 
trigger locStatusOpp on Opportunity (after update) {

    for (Opportunity opp : Trigger.new) {
        
        List<Location_Status__c> loc = [SELECT Id,
                                        On_List__c,
                                        Location__c,
                                        Vendor_Type__c,
                                        OpportunityR__c
                                 FROM   Location_Status__c];
        for (Location_Status__c locLoop : loc)
        if (opp.StageName == 'Closed Won' || opp.Vendors__c == 'Bartender' || opp.Location__c == 'Albuquerque NM'){
            Location_Status__c locNew     =  new Location_Status__c(
            Name                   		  =  opp.Name,
            Location__c           		  = 'Albuquerque NM',
            Vendor_Type__c       		  = 'Bartender',
            OpportunityR__c       		  =  opp.Id);      
        }
        insert loc;
    }
}

 
We have changed our buisness process and have reassigned this trigger to a new Object. I have included the section of code that is causing the issue. The error is occuring in the last line of code.