• bookeraward
  • NEWBIE
  • 40 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 6
    Questions
  • 11
    Replies
I am trying to write a trigger that fires when my custom object "Vehicles" is either updated or new record is inserted.

If any of its two particular fields (In_service__c, Manufacturer__c)have been updated or new record has been inserted, then I want to compare these values to the fields Name__c and Subscriber__c of my custom object "Company".

If the values of the two fields in “Vehicles” match with the fields in “Company”, then assign the value in the field
Channel__c.Vehicles = Group__c.Company
This is what I have so far:
trigger VehicleUpdate on Vehicle_custom_object__c (before insert, before update){
    map<id, string, string> vehicleIDs = new map<id, string,string>();
      for(Vehicle_custom_object__c v: trigger.new){
        // ?? vehicleIDs.add(v.Vehicle_ID__c);(it should now have a collection of all ID's and also the values od the two fields which I am trying to compare with
       }
      Map<Id, Company__c> mapOfCompanies = new Map<Id,Company__c>();
      for (Company__c comp: [select  Name, Subscriber__c from Company__c where ??
       //this is where I am stuck at
       //if the values of Name__c.Company and Subscriber__c.Company match with the values of In_service__c.Vehicle and Vehicle.Manufacturer__c
      //then Vehicle.Channel__c = Company.Group__c

Thanks for your help.
I am trying to write a trigger that fires when my custom object ‘Vehicles' is either updated or new recored is inserted.
If any of its 2 particular fields (In_service__c, Vehicle_designation__c) have been updated ,i want those records to be saved in a list.
And  i want to assign the value of  field (Group__c ) equal to the field (Vehicle_designation__c)
 My Code:  
Trigger TUpdate on Vehicle__c (before insert, before update) {
   set<String>  vehicleID = new Set<String>() ;
  for(Vehicle__c v: trigger.new){
    // if the fields are updated:
     Vehicle__c oldv = trigger.oldMap.get(v.Vehicle_ID__c);
      if ((v.In_service__c != oldv.In_service__c) || (v.Vehicle_designation__c != oldv.Vehicle_designation__c) )
      {  
       // field was updated,do something!
           v.Group__c = v.Channel_designation__c;
        }    
     // if new records are inserted:
      vehicleID.add(v.Vehicle_ID__c);
      v.Group__c = v.Channel_designation__c;
  }
There seems to be some problem with Line 6
if ((v.In_service__c != oldv.In_service__c) || (v.Vehicle_designation__c != oldv.Vehicle_designation__c) )
 when i run my test case it fails and if i insert a new record I get the error message
(Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger TruUpdate caused an unexpected exception, contact your administrator: TUpdate: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.TUpdate: line 6, column 1.)

My Unit test:
@IsTest
public with sharing class TFieldUpdate {
static testMethod void testupdates(){

// Create our records from scratch!
 Vehicle__c vc = newVehicle__v()
 vc.Serial_Number__c='1233333';
 vc.In_service__c ='yes';
 insert vc;
//update Vehicle Record:
 vc.In_service__c ='no';
 update vc;  
 }
}


 
I am trying to display the custom field trackingnumber present in opportunity on my Quotes pagelayout.
I understand there is a formula which i need to use to link the fields from opportunity in Quotes,but i cant get it to work.
Can anybody help me with my problem.
Thankyou.
Hello Everyone,

I am trying to write a test class for my trigger which updates the Contacts Mailing to Accounts Biliing Address whenever the  Accounts Billing Address is updated.
This is my Trigger

trigger UpdateContactBillingAddress on Account (after update) {

    Set<Id> accountId = new Set<Id>();
    List<Contact> contactsToUpdate = new List<Contact>();
    
    for(Account acc: Trigger.new){

        // Please perform a check to see if address was updated

        accountId.add(acc.Id); //accounts that were updated.
    }
    
    for(Contact c : [Select Id, MailingCity, MailingStreet, MailingCountry, 
                            Account.BillingCity, Account.BillingStreet, Account.BillingCountry 
                      from Contact where Account.Id in: accountId]){

                 c.MailingCity = c.Account.BillingCity;
                 ///same for rest of the fields
                 
                 contactsToUpdate.add(c);
    }

    update contactsToUpdate;
    
}

I am having a hard time writing its test Class,This is what I have done so far:
@isTest 
public class UpdateContactBillingAddress_Test{
    static testMethod void testupdates() {

     // Let's create our records from scratch!
       Account a= new Account();
       a.Name='TestAccount';
       a.BillingStreet='hjasadhj';
       insert a;
        Contact c = [SELECT Id, MailingStreet,MailingCity FROM Contact WHERE AccountId = :a.Id];
        System.assertEquals('hjasadhj', c.MailingStreet);
        System.assertEquals('High', c.MailingStreet);
       }
      }

Why am i getting error while running the code?
Any help will be appreciated.
Thanks.
Hello all,
I am new to Salesforce.Can anyone please help with this problem.
 I am trying to Build a trigger.The trigger should fire whenever an Account object is modified.The trigger should detect if the billing address on the Account has changed.If the Account billing address has changed, the new billing address should be copied to all Contact records related to that account