You need to sign in to do that
Don't have an account?
Jeff Bomar
Problem with Apex trigger
Can someone tell me what I am doing wrong?
I want to create a trigger that when the Custom type = Tape Drop and Total hours are updated so does not = Null or > 0 the trigger will get the cost of the Custom Development from the price book (189.00) and the cost of the Tape Drop from the price book (750.00) and put the
(Tape Drop (750) + Total Hours * Custom Development) in Testing_Balance__c here is what I have so far.
trigger UpdateBalanceTapeDrop on Custom_Programming__c (before insert, before update) {
for (Custom_Programming__c custom : Trigger.new)
{
//SQL statement to lookup price
List<PricebookEntry> sqlResult = [SELECT UnitPrice FROM PricebookEntry WHERE Product2.Name = 'Custom Development'AND PriceBook2.Name='DAKCS'];
List<PricebookEntry> sqlResult2 = [SELECT UnitPrice FROM PricebookEntry WHERE Product2.Name = 'Tape Drop'AND PriceBook2.Name='DAKCS'];
if (custom.Custom_Type__c == 'Tape Drop' && custom.Total_Hours__c != null)
{
custom.Testing_Balance__c = sqlResult2[0].UnitPrice + (Total_Hours__c*sqlResult[0].UnitPrice);
}
}
}
Any help would be much appreciated.
I want to create a trigger that when the Custom type = Tape Drop and Total hours are updated so does not = Null or > 0 the trigger will get the cost of the Custom Development from the price book (189.00) and the cost of the Tape Drop from the price book (750.00) and put the
(Tape Drop (750) + Total Hours * Custom Development) in Testing_Balance__c here is what I have so far.
trigger UpdateBalanceTapeDrop on Custom_Programming__c (before insert, before update) {
for (Custom_Programming__c custom : Trigger.new)
{
//SQL statement to lookup price
List<PricebookEntry> sqlResult = [SELECT UnitPrice FROM PricebookEntry WHERE Product2.Name = 'Custom Development'AND PriceBook2.Name='DAKCS'];
List<PricebookEntry> sqlResult2 = [SELECT UnitPrice FROM PricebookEntry WHERE Product2.Name = 'Tape Drop'AND PriceBook2.Name='DAKCS'];
if (custom.Custom_Type__c == 'Tape Drop' && custom.Total_Hours__c != null)
{
custom.Testing_Balance__c = sqlResult2[0].UnitPrice + (Total_Hours__c*sqlResult[0].UnitPrice);
}
}
}
Any help would be much appreciated.
trigger UpdateBalanceTapeDrop on Custom_Programming__c (before insert, before update) {
for (Custom_Programming__c custom : Trigger.new)
{
//SQL statement to lookup price
List<PricebookEntry> sqlResult = [SELECT UnitPrice FROM PricebookEntry WHERE Product2.Name IN('Custom Development','Tape Drop')AND PriceBook2.Name='DAKCS'];
if (custom.Custom_Type__c == 'Tape Drop' && custom.Total_Hours__c != null)
{
// Tapedrop + (Custom Programing * Total Hours)
custom.Testing_Balance__c = sqlResult[1].UnitPrice + (sqlResult[0].UnitPrice * custom.Total_Hours__c);
}
}
}
All Answers
Greetings!
I would suggest you to try by adding the System.debug() statements in the code to make sure that the data is available.
Also,Capture the debug logs to see the complete code execution which makes easy to troubleshoot further on this.
https://help.salesforce.com/apex/HTViewHelpDoc?id=code_add_users_debug_log.htm&language=en_us
Kindly mark it as best answer if it helps so that it can help others in the future.
Warm Regards,
Shirisha Pathuri
trigger UpdateBalanceTapeDrop on Custom_Programming__c (before insert, before update) {
for (Custom_Programming__c custom : Trigger.new)
{
//SQL statement to lookup price
List<PricebookEntry> sqlResult = [SELECT UnitPrice FROM PricebookEntry WHERE Product2.Name IN('Custom Development','Tape Drop')AND PriceBook2.Name='DAKCS'];
if (custom.Custom_Type__c == 'Tape Drop' && custom.Total_Hours__c != null)
{
// Tapedrop + (Custom Programing * Total Hours)
custom.Testing_Balance__c = sqlResult[1].UnitPrice + (sqlResult[0].UnitPrice * custom.Total_Hours__c);
}
}
}