-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
6Questions
-
11Replies
trigger doesn't work?
I am trying to fire a trigger on object ‘Router_custom_object__c' when either ‘In_service__c’ || ‘Channel_designation_del__c' || ‘Router_designation' have been updated or new object is created.
IF the fields are updated or new object is created, then I compare the 3 fields of 'Router_custom_object__c '(concatenated together) with field ‘all_fields' of custom object ‘TRU_Groups__c'
and if they match then
Router_custom_object__c. TRU_c = TRU_Groups__c .Name
This is how my values of field ‘all_fields__c' looks like:
No, Aftermarket, Subscriber
My code:
IF the fields are updated or new object is created, then I compare the 3 fields of 'Router_custom_object__c '(concatenated together) with field ‘all_fields' of custom object ‘TRU_Groups__c'
and if they match then
Router_custom_object__c. TRU_c = TRU_Groups__c .Name
This is how my values of field ‘all_fields__c' looks like:
No, Aftermarket, Subscriber
My code:
Trigger TruFieldUpdate on Router_custom_object__c (before insert, before update) { Map<Id, Router_custom_object__c> changedRouters = new Map<Id, Router_custom_object__c>(); Map<Id, String> afTargets = new Map<Id, String>(); // Map of Router->All_field__c // Build a list of routers whose groups MAY have changed if(trigger.isInsert) { // All new routers for(Router_custom_object__c newR: trigger.new) { changedRouters.put(newR.Id, newR); } } else { // Some updated routers, if the relevant fields have been updated for(Router_custom_object__c oldR: trigger.old) { Router_custom_object__c newR = trigger.newMap.get(oldR.Id); if( (oldR.In_service__c != newR.In_service__c) || (oldR.Channel_designation_del__c != newR.Channel_designation_del__c) || (oldR.Router_designation__c != newR.Router_designation__c) ) { changedRouters.put(newR.Id, newR); } } } // The string we're building here matches the computation done for TRU_Groups__c.all_fields__c // Map this computer field to router Id. for(Router_custom_object__c oneR: changedRouters.values()) { afTargets.put(oneR.Id, oneR.In_service__c+','+oneR.Channel_designation_del__c+','+oneR.Router_designation__c); } // Get all the group records matching our afTargets values. List<TRU_Groups__c> foundGroups = [select Name, all_fields__c from TRU_Groups__c where all_fields__c in :afTargets.values()]; // For each router in afTargets, find the new Group value for(Id rId: afTargets.keySet()) { String routerFields = afTargets.get(rId); for(TRU_Groups__c oneG: foundGroups) { if(oneG.all_fields__c == routerFields) { // finally, change the router record. Router_custom_object__c r = changedRouters.get(rId); r.TRU__c = oneG.Name; break; } } } }
-
- bookeraward
- August 25, 2015
- Like
- 0
- Continue reading or reply
How to write a trigger one object with value in another object when two objects have no relation?
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
Thanks for your help.
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.CompanyThis 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.
-
- bookeraward
- August 21, 2015
- Like
- 0
- Continue reading or reply
Error Message while testing my Trigger
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:
(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:
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; } }
-
- bookeraward
- July 29, 2015
- Like
- 0
- Continue reading or reply
Displaying customfields of Oppurtunity in Quotes pagelayout
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.
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.
-
- bookeraward
- June 24, 2015
- Like
- 0
- Continue reading or reply
Test Class for Updating a Trigger
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.
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.
-
- bookeraward
- March 03, 2015
- Like
- 0
- Continue reading or reply
Fire a Trigger
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
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
-
- bookeraward
- March 02, 2015
- Like
- 0
- Continue reading or reply
How to write a trigger one object with value in another object when two objects have no relation?
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
Thanks for your help.
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.CompanyThis 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.
- bookeraward
- August 21, 2015
- Like
- 0
- Continue reading or reply
Error Message while testing my Trigger
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:
(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:
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; } }
- bookeraward
- July 29, 2015
- Like
- 0
- Continue reading or reply
Displaying customfields of Oppurtunity in Quotes pagelayout
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.
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.
- bookeraward
- June 24, 2015
- Like
- 0
- Continue reading or reply
Test Class for Updating a Trigger
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.
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.
- bookeraward
- March 03, 2015
- Like
- 0
- Continue reading or reply
Fire a Trigger
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
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
- bookeraward
- March 02, 2015
- Like
- 0
- Continue reading or reply