• matthew.w.hampton.ax1837
  • NEWBIE
  • 10 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 6
    Replies
Good Morning:

Please see the attached VF page and image. I am having trouble figuring out how to space out my field labels and fields so they are all symemtrical and easy to look at. Any help would be appreciated.

<apex:page standardController="Fioptics_Notify_Me__c" extensions="fiopticsNotifyMeExtension" sidebar="FALSE" showHeader="FALSE" standardStylesheets="False">
<style>
    .activeTab {background-color:white; color:black; background-image:none; font-weight: bold}
    .inactiveTab {background-color:lightgrey; color:black; background-image:none; font-weight:bold}
    .pageBlockStyle {text-align:left; width:30%}
    .bPageBlock .pbBody {background:white;}
</style>   
        <apex:form styleClass="pageBlockStyle">      
            <apex:tabPanel switchType="client" selectedTab="fioptics2" id="theTabPanel" tabClass="activeTab" inactiveTabClass="inactiveTab">
                <apex:tab label="Fioptics" name="fioptics1" id="tabOne" labelWidth="50px">
                    <apex:pageBlock >
                        <apex:pageBlockSection title="Customer Information" columns="1">
                            <apex:inputField label="Name" value="{!Fioptics_Notify_Me__c.Name}" required="TRUE" style="width: 200px; height: 20px nowrap;"/>
                            <apex:inputField label="Contact Number" value="{!Fioptics_Notify_Me__c.Contact_Number__c}" required="TRUE" style="width: 200px; height: 20px nowrap"/>
                            <apex:inputField label="Address" value="{!Fioptics_Notify_Me__c.Address__c}" required="TRUE" style="width: 200px; height: 20px nowrap"/>  
                            <apex:inputField label="Customer Email" value="{!Fioptics_Notify_Me__c.Customer_E_mail__c}" style="width: 200px; height: 20px nowrap"/>
                        </apex:PageBlockSection>
                        <apex:pageBlockSection title="Consultant Information" columns="1">  
                            <apex:inputField label="Store" value="{!Fioptics_Notify_Me__c.Store__c}" required="TRUE" style="width: 300px; height: 20px nowrap"/> 
                            <apex:inputField label="Consultant Email" value="{!Fioptics_Notify_Me__c.Consultant_Email__c}" required="TRUE" style="width: 300px; height: 20px nowrap"/>      
                            <apex:inputField label="Consultant" value="{!Fioptics_Notify_Me__c.Consultant_Name__c}" required="TRUE" style="width: 300px; height: 20px nowrap"/>     
                        </apex:PageBlockSection>
                        <apex:pageBlockSection title="Products Information" columns="1">      
                            <apex:inputField label="Video" value="{!Fioptics_Notify_Me__c.Video__c}" style="width: 300px; height: 20px nowrap"/>  
                            <apex:inputField label="Internet" value="{!Fioptics_Notify_Me__c.Internet__c}" style="width: 300px; height: 20px nowrap"/>      
                            <apex:inputField label="Phone" value="{!Fioptics_Notify_Me__c.Phone__c}" style="width: 300px; height: 20px nowrap"/>    
                            <apex:inputField label="Notes" value="{!Fioptics_Notify_Me__c.Notes__c}" style="width: 300px; height: 50px nowrap"/>   
                            <apex:commandButton value="Submit" action="{!saveLead}" style="float:left"/>   
                        </apex:pageBlockSection>
                    </apex:pageBlock>
                </apex:tab>
                <apex:tab label="CBW" name="fioptics2" id="tabTwo" labelWidth="50px">
                    <apex:pageBlock mode="mainDetail">
                        <apex:pageBlockSection title="Customer Information" columns="1">
                            <apex:inputField label="Name" value="{!Fioptics_Notify_Me__c.Name}" required="TRUE" style="width: 300px; height: 20px nowrap"/>
                            <apex:inputField label="Contact Number" value="{!Fioptics_Notify_Me__c.Contact_Number__c}" required="TRUE" style="width: 300px; height: 20px nowrap"/>
                            <apex:inputField label="Address" value="{!Fioptics_Notify_Me__c.Address_Free__c}" required="TRUE" style="width: 300px; height: 20px nowrap"/>  
                            <apex:inputField label="Customer Email" value="{!Fioptics_Notify_Me__c.Customer_E_mail__c}" style="width: 300px; height: 20px nowrap" />                              
                        </apex:pageBlockSection>
                        <apex:pageBlockSection title="Consultant Information" columns="1">  
                            <apex:inputField label="Store" value="{!Fioptics_Notify_Me__c.Store__c}" required="TRUE" style="width: 300px; height: 20px nowrap"/> 
                            <apex:inputField label="Consultant" value="{!Fioptics_Notify_Me__c.Consultant_Name__c}" required="TRUE" style="width: 300px; height: 20px nowrap"/>  
                        </apex:PageBlockSection>
                        <apex:pageBlockSection title="CBW Information" columns="1">      
                            <apex:inputField label="#of Lines" value="{!Fioptics_Notify_Me__c.of_Lines__c}" required="TRUE" style="width: 300px; height: 20px nowrap"/>  
                            <apex:inputField label="Current Plan" value="{!Fioptics_Notify_Me__c.Current_Plan__c}" style="width: 300px; height: 20px nowrap"/>         
                            <apex:inputField label="Notes" value="{!Fioptics_Notify_Me__c.Notes__c}" style="width: 300px; height: 50px nowrap"/>  
                            <apex:commandButton value="Submit" action="{!saveLead}" style="float:left"/>   
                        </apex:pageBlockSection>
                    </apex:pageBlock>                                                      
                </apex:tab>                         
            </apex:tabPanel>                                  
        </apex:form>          
</apex:page>




VF Page Screenshot
Thanks,

Matt
Good Morning:

I have the following piece of code that I am having some issues with.

What I am trying to do is to pull all Billing_Account__c records where Billing_Account__c.Zip_Code__c = MTU_Location__c.Zip_Code__c and Billing_Account__c.Address_1__c CONTAINS MTU_Location__c.Street_Address__c. After doing so, I want to update Billing_Account__c.MTU_Location__c with MTU_Location__c.ID.

The query should return multiple records to update, which it does, but that is causing my trigger to erorr out - I am getting the SOQL returned multiple rows for assignment error.

How to I re-write this so that it pulls multiple records but allows me to update multiple records?

Thanks,

Matt

for(MTU_Location__c mtuRecord : addMTUList){
            Billing_Account__c mtuUpdate = [Select ID, Address_1__c, Zip_Code__c, MTU_Location__c from Billing_Account__c where Zip_Code__c = :mtuRecord.Zip_Code__c];
                if(mtuUpdate.Address_1__c.CONTAINS(mtuRecord.Street_Address__c)){
                    mtuUpdate.MTU_Location__c = mtuRecord.ID;}


           
            updateBillingAccountList.add(mtuUpdate);
           
        }
        update updateBillingAccountList;
Good Morning:

I have a VF page that is hosted on a public site that allows users to create a record (a custom W2L page that goes to a custom lead object).

When the user submits the record, a second VF page, a thank you page pops up alerting the user that their record has been created. I want to put a custom button on the thank you page that the user can hit to return them back to the original page.

I have got this to work using window.open with the primary URL but this opens in a new window and i just want it to open in the same window (ie same function as hitting the back button).

Any help on this is appreciated.

Thanks,

Matt
Good Afternoon:

I  have the following Apex Trigger and Test Class written. The Test Class passes with 100% code coverage but when I insert or update the records, the trigger is not firing. Here are both the trigger and the test class. If anyone can help explain what I've done wrong here, please let me know.

Thanks,

Matt

trigger FiopticsNotifyMeUpdate on Fioptics_Notify_Me__c (before insert, before update) {

Set<String> street = new Set<String>();
for (Fioptics_Notify_Me__c fioptics : Trigger.new) {
        street.add(fioptics.Street_Name__c);
}

Map<String, Address__c> addressMap3 = new Map<String, Address__c>();
for(Address__c address3:[Select ID, Name, House_Number__c, Parsed_Street_Name__c, Zip_Code__c, Special_Location_Value__c, Fiber_Qualified__c, IPTV_Qualified__c from Address__c where Parsed_Street_Name__c in : street])
     addressMap3.put(address3.Parsed_Street_Name__c, address3);

List<Fioptics_Notify_Me__c> notificationsToUpdate = new List <Fioptics_Notify_Me__c>();
     for(Fioptics_Notify_Me__c a : trigger.new){
          if(addressMap3.containskey(a.Street_Name__c) && addressMap3.get(a.Street_Name__c).Special_Location_Value__c == a.Apt_Floor_Unit__c && addressMap3.get(a.Street_Name__c).Zip_Code__c == a.Zip_Code__c && addressMap3.get(a.Street_Name__c).House_Number__c == a.House_Number__c && addressMap3.get(a.Street_Name__c).Fiber_Qualified__c == 'N' && addressMap3.get(a.Street_Name__c).IPTV_Qualified__c == 'N'){
                     a.Address__c = addressMap3.get(a.Street_Name__c).ID;}
         else {
          if(addressMap3.containskey(a.Street_Name__c) && addressMap3.get(a.Street_Name__c).Special_Location_Value__c == a.Apt_Floor_Unit__c && addressMap3.get(a.Street_Name__c).Zip_Code__c == a.Zip_Code__c && addressMap3.get(a.Street_Name__c).House_Number__c == a.House_Number__c && (addressMap3.get(a.Street_Name__c).Fiber_Qualified__c == 'Y' || addressMap3.get(a.Street_Name__c).IPTV_Qualified__c == 'Y')){
                     a.Address__c = addressMap3.get(a.Street_Name__c).ID;
                     a.Fioptics_Qualified__c = TRUE;}
                     }
update notificationsToUpdate;
         }
         }

@IsTest
private class FiopticsNotifyMeUpdateTestClass {
    static testMethod void validateFiopticsNotifyMeUpdate() {

          Address__c a = new Address__c (Name = '123 Main Street 45202', House_Number__c='123', Parsed_Street_Name__c='Main St', Zip_Code__c='45202');
          insert a;

          Fioptics_Notify_Me__c b = new Fioptics_Notify_Me__c (Name = 'Matt Hampton', House_Number__c = '123', Street_Name__c='Main St', Zip_Code__c='45202');
          insert b;

          Fioptics_Notify_Me__c b2 = [Select Name, Address__c, Fioptics_Qualified__c from Fioptics_Notify_Me__c where Address__c = :a.ID];

          system.assertequals(b2.Address__c, a.ID);          
         
          Address__c c = new Address__c (Name = '456 Main Street 45202', House_Number__c='456', Parsed_Street_Name__c='Main St', Zip_Code__c='45202', HSIA_Qualification__c='G');
          insert c;

          Fioptics_Notify_Me__c d = new Fioptics_Notify_Me__c (Name = 'Matt Hampton', House_Number__c = '456', Street_Name__c='Main St', Zip_Code__c='45202');
          insert d;

          Fioptics_Notify_Me__c d2 = [Select Name, Address__c, Fioptics_Qualified__c from Fioptics_Notify_Me__c where Address__c = :c.ID];

          system.assertequals(d2.Fioptics_Qualified__c, TRUE); 
          system.assertequals(d2.Address__c, c.ID);                    
    }
}
Hello:

I have what I think is a fairly simple request but not really sure how to get started.

I have a VF page that is exposed internally to a group of sales folks to capture information that needs to result in the creation of a record on a custom object.

I have the VF page set up, I just need some guidance on how to write the logic in the submit button. The fields on the VF page would map to fields in custom object Notifications__c.

Here is the VF code:

<apex:page >
    <head>
        <style type="text/css">
            fieldset {
                font-weight:bold;
                width:500px;
                height:400px;
                }
            legend{
                font-size:150%
                }   
            label.field{
                width:200px;
                dispaly:block;
                float:left;             
                }
            button{
                float:right;
                }          
           
        </style>
    </head>
       
       <fieldset>
        <Legend>Fioptics</Legend>
        <Label class ="field" for="Contact Name">Contact Name</label><input type="text" name="contactname"></input>
        <Label class ="field" for="BTN">BTN</label><input type="tel" name="BTN"></input>
        <Label class ="field" for="Customer Email Address">Customer Email</label><input type="email" name="customeremail"></input>
        <Label class ="field" for="House Number">House Number</label><input type="text" name="housenumber"></input>
        <Label class ="field" for="Street Name">Street Name</label><input type="text" name="streetname"></input>
        <Label class ="field" for="Apt/Flr">Apt/Floor/Unit</label><input type="text" name="apt/flr"></input>       
        <Label class ="field" for="City">City</label><input type="text" name="city"></input>       
        <Label class ="field" for="State">State</label><input type="text" name="state"></input>       
        <Label class ="field" for="Zip_Code">Zip Code</label><input type="text" name="zip_code"></input>
        <Label class ="field" for="Consultant Name">Consultant Name</label>
            <Select>
                <Option Value="--">--</Option>
                <Option Value="Aaron Armbruster">Aaron Armbruster</Option>
                <Option Value="Alex Yankosky">Alex Yankosky</Option>
                <Option Value="Aliea Smith">Aliea Smith</Option>
                <Option Value="Andrew Clim">Andrew Clim</Option>
                <Option Value="Ashley Smith">Ashley Smith</Option>
                <Option Value="Austin Geiman">Austin Geiman</Option>
                <Option Value="Ben Thomas">Ben Thomas</Option>
                <Option Value="Bettina Torres">Bettina Torres</Option>
                <Option Value="Brad Wittrock">Brad Wittrock</Option>
                <Option Value="Brian Coogan">Brian Coogan</Option>
                <Option Value="Brian Henderson">Brian Henderson</Option>
                <Option Value="Bruce Farley">Bruce Farley</Option>
                <Option Value="Chad Smith">Chad Smith</Option>
                <Option Value="Chris Smith">Chris Smith</Option>
                <Option Value="Christie Fox">Christie Fox</Option>
                <Option Value="Christopher Brown">Christopher Brown</Option>
                <Option Value="Craig Conley">Craig Conley</Option>
                <Option Value="Craig Cornett">Craig Cornett</Option>
                <Option Value="Craig Foltz">Craig Foltz</Option>
                <Option Value="Danielle Duane">Danielle Duane</Option>
                <Option Value="David Delano">David Delano</Option>
                <Option Value="David Michaelson">David Michaelson</Option>
                <Option Value="David Sizemore">David Sizemore</Option>
                <Option Value="Donna Hawkins">Donna Hawkins</Option>
                <Option Value="Douglas DeTellem">Douglas DeTellem</Option>
                <Option Value="Drew Walker">Drew Walker</Option>
                <Option Value="Elbert Florence">Elbert Florence</Option>
                <Option Value="Eric Stock">Eric Stock</Option>
                <Option Value="Greg Gillum">Greg Gillum</Option>
                <Option Value="James Hester">James Hester</Option>
                <Option Value="Jason Lawrence">Jason Lawrence</Option>
                <Option Value="Jason Macintyre">Jason Macintyre</Option>
                <Option Value="Jason Pittinger">Jason Pittinger</Option>
                <Option Value="Jesse Patton">Jesse Patton</Option>
                <Option Value="Jocelyn McIntosh">Jocelyn McIntosh</Option>
                <Option Value="Joe Birchak">Joe Birchak</Option>
                <Option Value="Jon Greene">Jon Greene</Option>
                <Option Value="Jonathan Vehr">Jonathan Vehr</Option>
                <Option Value="Joseph Brunner">Joseph Brunner</Option>
                <Option Value="Josh Correll">Josh Correll</Option>
                <Option Value="Joshua Neal">Joshua Neal</Option>
                <Option Value="Justin Winstel">Justin Winstel</Option>
                <Option Value="Kayla Scott">Kayla Scott</Option>
                <Option Value="Kelsey Shoupe">Kelsey Shoupe</Option>
                <Option Value="Kerri McCann">Kerri McCann</Option>
                <Option Value="Kyle Leidy">Kyle Leidy</Option>
                <Option Value="Lauren Wilson">Lauren Wilson</Option>
                <Option Value="Lindsey Stock">Lindsey Stock</Option>
                <Option Value="Markus Richie">Markus Richie</Option>
                <Option Value="Matthew Miller">Matthew Miller</Option>
                <Option Value="Matthew Payne">Matthew Payne</Option>
                <Option Value="Megan Franklin">Megan Franklin</Option>
                <Option Value="Michael OBrien">Michael OBrien</Option>
                <Option Value="Mike Crump">Mike Crump</Option>
                <Option Value="Monica Hodapp">Monica Hodapp</Option>
                <Option Value="Myles Hornsby">Myles Hornsby</Option>
                <Option Value="Patrick Ebeling">Patrick Ebeling</Option>
                <Option Value="Phillip Trotta">Phillip Trotta</Option>
                <Option Value="Rebecca Bowman">Rebecca Bowman</Option>
                <Option Value="Rick Kurtzer">Rick Kurtzer</Option>
                <Option Value="Robert Hoffman">Robert Hoffman</Option>
                <Option Value="Robert Lucas">Robert Lucas</Option>
                <Option Value="Ryan Hartinger">Ryan Hartinger</Option>
                <Option Value="Samantha Ramey">Samantha Ramey</Option>
                <Option Value="Sarah Koehler">Sarah Koehler</Option>
                <Option Value="Shondra Valletti">Shondra Valletti</Option>
                <Option Value="Thomas Mroczka">Thomas Mroczka</Option>
                <Option Value="Tom Miller">Tom Miller</Option>
                <Option Value="Tyler Anderson">Tyler Anderson</Option>
                <Option Value="Tyler Stegemiller">Tyler Stegemiller</Option>
                <Option Value="Tyler Stolly">Tyler Stolly</Option>
                <Option Value="William Fahnestock">William Fahnestock</Option>
                <Option Value="William King">William King</Option>
                <Option Value="Zach Young">Zach Young</Option>
             </Select>
        <br/>
        <Label class ="field" for="Store">Store</label>
            <Select>
                <Option Value="--">--</Option>
                <Option Value="Crestview Hills">Crestview Hills</Option>
                <Option Value="Eastgate">Eastgate</Option>
                <Option Value="Florence">Florence</Option>
                <Option Value="Kenwood">Kenwood</Option>
                <Option Value="Northgate">Northgate</Option>
                <Option Value="Western Hills">Western Hills</Option>
                <Option Value="West Chester">West Chester</Option>
            </Select>
        <br />
        <Label class ="field" for="Internet Speed">Internet Speed</label>
            <Select>
                <Option Value="--">--</Option>
                <Option Value="10MB">10MB</Option>
                <Option Value="20MB">20MB</Option>
                <Option Value="30MB">30MB</Option>
                <Option Value="50MB">50MB</Option>
                <Option Value="100MB">100MB</Option>
            </Select>
        <br />
        <Label class="field" for="Fioptics TV">Fioptics TV</label>
            <Select>
                <Option Value="--">--</Option>
                <Option Value="Preferred">Preferred</Option>
                <Option Value="Elite">Elite</Option>
                <Option Value="Max">Max</Option>
            </Select>           
        <br/>
        <Label class="field" for="Home Phone">Home Phone</label>
            <Select>
                <Option Value="--">--</Option>
                <Option Value="Home Pak Lite">Home Pak Lite</Option>
                <Option Value="Home Pak Advantage">Home Pak Advantage</Option>
            </Select>
        <br/>
        <button type ="button">Submit</button>    
       
            
      </fieldset> 
</apex:page>
Good Evening:

I am in need of some help/suggestions here on how to make this query work. I am getting the dreded non-selective query error when I fire the trigger.

Summary

I have custom object MTU_Billing_Account__c that has a lookup field Account_Name__c that looks up to a custom object. Account_Name__c has a custom field called BTN__c. MTU_Billing_Account__c also has a lookup to the standard Accounts object called Account__c.

I have a second custom object called Billing_Account__c that has a field on it called Billing_Account_ID__c. This field is an External ID field. Billing_Account__c also has a lookup relationship to the standard Accounts object.

What I am looking to do is the following:

Take field Account_Name__r.BTN__c

Loop through Billing_Account__c records where Account_Name__r.BTN__c = Billing_Account__c.Billing_Account_ID__c (and a few other filters)

Updated Account__c on MTU_Billing_Account__c with Billing_Account__c.Account__r.ID.

Billing_Account__c has 770,815 records. Billing_Account_ID__c is an External ID and the key. I am out of filter options. 

Any suggestions would be greatly appreciated.

Thanks,

Matt

trigger MTUBillingAccountAccountUpdate on MTU_Billing_Account__c (before update, before insert)
{
    Map<String, MTU_Billing_Account__c> mtuAccount = new Map<String, MTU_Billing_Account__c>();
    for ( MTU_Billing_Account__c mtu2 : Trigger.new )
    {
        mtuAccount.put( mtu2.Account_Name__r.BTN__c, mtu2);
      
}

    Set<String> keys = mtuAccount.keyset();

    Map<String, Billing_Account__c> billingAccountMap = new Map<String, Billing_Account__c>();
    for(Billing_Account__c account1:[Select ID, Name, Account__r.ID, Billing_Account_ID__c from Billing_Account__c where Billing_Account_ID__c in : keys and Billing_Account_Status__c = 'Live' and Billing_System__c = 'CRIS'])
        billingAccountMap.put(account1.Billing_Account_ID__c, account1);
 
    List<MTU_Billing_Account__c> accountsToUpdate = new List <MTU_Billing_Account__c>();
        for(MTU_Billing_Account__c a : trigger.new) {
            if(billingAccountMap.containskey(a.Account_Name__r.BTN__c)) {
                    a.Account__c = billingAccountMap.get(a.Account_Name__r.BTN__c).Account__r.ID;
    }
update accountsToUpdate;
}
}


Good Afternoon:

 

I am in the need of a little guidance on the trigger below.

 

I have a custom object (MTU_Location__c) that is the parent in a master-detail to another custom object (MTU_Address__c).

 

I have a trigger bult to create child records based upon certain criteria on the parent object. But what I cannot figure out is how to create multiple child records upon the insertion of the parent.

 

There could be as few as 0 or as many as 15-20 child records that need created upon creation of the parent.

 

Below is the trigger. Any help is greatly appreciated.

 

Thanks,

 

Hampton

 

trigger MTUAddressCreation on MTU_Location__c (after insert, after update) {

    Set<String> mtuAddress = new Set<String>();
     for(MTU_Location__c mtu: trigger.new) {
     mtuAddress.add(mtu.Street_Address__c);
   }
    
    Map<String, Billing_Account__c> billingAccount = new Map<String, Billing_Account__c>();
    for(Billing_Account__c billingAccount1: [Select ID, Name, Account__c, Address_1__c, City__c, State__c, Zip_Code__c, Billing_Account_ID__c from Billing_Account__c where Billing_System__c='CRIS' AND Billing_Account_Status__c='Live' AND Address_1__c in: mtuAddress])
    billingAccount.put(billingAccount1.Address_1__c, billingAccount1); 
    
    List<MTU_Address__c> newAddresses = new List<MTU_Address__c>();
        for(MTU_Location__c location: [Select ID, Name, Street_Address__c, City__c, State__c, Zip_Code__c from MTU_Location__c where Street_Address__c in : billingAccount.keyset()]){
            newAddresses.add(new MTU_Address__c(
                Address__c = location.Street_Address__c,
                City__c = location.City__c,
                State__c = location.State__c,
                Zip_Code__c = location.Zip_Code__c,
                Account__c = billingAccount.get(location.Street_Address__c).Account__c,
                Billing_Account__c=billingAccount.get(location.Street_Address__c).ID,
                MTU_Location__c = location.ID));
  
    }
   insert newAddresses;
}

 

Hello:

 

I have to custom objects - Service_Orders__c and Rep_Sales_Summary__c that are unrelated but share a common key (Service_Order__c.Release__c = Rep_Summary__c.Turf__r.Name)

 

What I am looking to do is the following:

 

1. Group Service_Order__c records by Release__c

 

2. If Release__c = Rep_Summary__c.Turf__r.Name, then:

   a. Rep_Summary__c.Video__c = sum(Service_Order__c.Video__c)

   a. Rep_Summary__c.Internet__c = sum(Service_Order__c.Internet__c)

 

   a. Rep_Summary__c.Access_Line__c = sum(Service_Order__c.Access_Line__c)

   a. Rep_Summary__c.Completed__c = sum(Service_Order__c.Video__c) IF Service_Order__c.Status_Description__c = 'Completed'

 

   a. Rep_Summary__c.Video__c = sum(Service_Order__c.Video__c) IF Service_Order__c.Status_Description__c = 'Cancelled'

 

I'm an intermediate APEX writer but cannot figure this one out.

 

Any help you can provide is appreciated.

 

Thanks,

 

Matt

Good Morning:

I have the following piece of code that I am having some issues with.

What I am trying to do is to pull all Billing_Account__c records where Billing_Account__c.Zip_Code__c = MTU_Location__c.Zip_Code__c and Billing_Account__c.Address_1__c CONTAINS MTU_Location__c.Street_Address__c. After doing so, I want to update Billing_Account__c.MTU_Location__c with MTU_Location__c.ID.

The query should return multiple records to update, which it does, but that is causing my trigger to erorr out - I am getting the SOQL returned multiple rows for assignment error.

How to I re-write this so that it pulls multiple records but allows me to update multiple records?

Thanks,

Matt

for(MTU_Location__c mtuRecord : addMTUList){
            Billing_Account__c mtuUpdate = [Select ID, Address_1__c, Zip_Code__c, MTU_Location__c from Billing_Account__c where Zip_Code__c = :mtuRecord.Zip_Code__c];
                if(mtuUpdate.Address_1__c.CONTAINS(mtuRecord.Street_Address__c)){
                    mtuUpdate.MTU_Location__c = mtuRecord.ID;}


           
            updateBillingAccountList.add(mtuUpdate);
           
        }
        update updateBillingAccountList;

Good Afternoon:

 

I am in the need of a little guidance on the trigger below.

 

I have a custom object (MTU_Location__c) that is the parent in a master-detail to another custom object (MTU_Address__c).

 

I have a trigger bult to create child records based upon certain criteria on the parent object. But what I cannot figure out is how to create multiple child records upon the insertion of the parent.

 

There could be as few as 0 or as many as 15-20 child records that need created upon creation of the parent.

 

Below is the trigger. Any help is greatly appreciated.

 

Thanks,

 

Hampton

 

trigger MTUAddressCreation on MTU_Location__c (after insert, after update) {

    Set<String> mtuAddress = new Set<String>();
     for(MTU_Location__c mtu: trigger.new) {
     mtuAddress.add(mtu.Street_Address__c);
   }
    
    Map<String, Billing_Account__c> billingAccount = new Map<String, Billing_Account__c>();
    for(Billing_Account__c billingAccount1: [Select ID, Name, Account__c, Address_1__c, City__c, State__c, Zip_Code__c, Billing_Account_ID__c from Billing_Account__c where Billing_System__c='CRIS' AND Billing_Account_Status__c='Live' AND Address_1__c in: mtuAddress])
    billingAccount.put(billingAccount1.Address_1__c, billingAccount1); 
    
    List<MTU_Address__c> newAddresses = new List<MTU_Address__c>();
        for(MTU_Location__c location: [Select ID, Name, Street_Address__c, City__c, State__c, Zip_Code__c from MTU_Location__c where Street_Address__c in : billingAccount.keyset()]){
            newAddresses.add(new MTU_Address__c(
                Address__c = location.Street_Address__c,
                City__c = location.City__c,
                State__c = location.State__c,
                Zip_Code__c = location.Zip_Code__c,
                Account__c = billingAccount.get(location.Street_Address__c).Account__c,
                Billing_Account__c=billingAccount.get(location.Street_Address__c).ID,
                MTU_Location__c = location.ID));
  
    }
   insert newAddresses;
}