You need to sign in to do that
Don't have an account?
azar khasim
Need help in writing a Test class for a Trigger.
Hello Guys,
I need help in writing a test class for the below trigger.
trigger AccountNameUpdate on Booking_Link__c (before insert, before update) {
List<Account> accountList = new List<Account>();
String CustomNumber;
for(Booking_Link__c bl : Trigger.new)
{
CustomNumber = bl.Customer_Number__c;
}
accountList = [Select Id, OwnerId, Customer_Number__pc from Account where Customer_Number__pc =:CustomNumber ];
for(Booking_Link__c bl : Trigger.new)
{
for(Account a : accountList)
{
if(bl.Customer_Number__c == a.Customer_Number__pc && bl.T2G__c==True)
{
bl.Account__c = a.Id;
bl.OwnerId = a.OwnerId;
}
}
}
}
*********************************************************************
My test Class which got 0% code coverage.
***********************************************************************
@isTest
public class AccountNameUpdate {
@isTest static void updateAccount(){
Account a = new Account();
a.Name = 'Abhishek Gupta';
insert a;
Booking_Link__c bl= new Booking_Link__c();
bl.Customer_Number__c = a.Customer_Number__pc;
bl.T2G__c =True;
bl.Account__c = a.Id;
bl.OwnerId = a.OwnerId;
update bl;
}
}
*************************************************
Help me out from this...
Azar Khasim.
I need help in writing a test class for the below trigger.
trigger AccountNameUpdate on Booking_Link__c (before insert, before update) {
List<Account> accountList = new List<Account>();
String CustomNumber;
for(Booking_Link__c bl : Trigger.new)
{
CustomNumber = bl.Customer_Number__c;
}
accountList = [Select Id, OwnerId, Customer_Number__pc from Account where Customer_Number__pc =:CustomNumber ];
for(Booking_Link__c bl : Trigger.new)
{
for(Account a : accountList)
{
if(bl.Customer_Number__c == a.Customer_Number__pc && bl.T2G__c==True)
{
bl.Account__c = a.Id;
bl.OwnerId = a.OwnerId;
}
}
}
}
*********************************************************************
My test Class which got 0% code coverage.
***********************************************************************
@isTest
public class AccountNameUpdate {
@isTest static void updateAccount(){
Account a = new Account();
a.Name = 'Abhishek Gupta';
insert a;
Booking_Link__c bl= new Booking_Link__c();
bl.Customer_Number__c = a.Customer_Number__pc;
bl.T2G__c =True;
bl.Account__c = a.Id;
bl.OwnerId = a.OwnerId;
update bl;
}
}
*************************************************
Help me out from this...
Azar Khasim.
Please find below the test class and the coverage is 100% with all test methods passing.
@isTest
public class AccountNameUpdate {
@isTest static void updateAccount(){
Account a = new Account();
a.Name = 'Abhishek Gupta';
insert a;
Booking_Link__c bl= new Booking_Link__c();
bl.Customer_Number__c = a.Customer_Number__c;
bl.T2G__c =True;
bl.Account__c = a.Id;
//bl.OwnerId = a.OwnerId;
insert bl;
}
}
Kindly mark this as solved if it's resolved so that it gets removed from the unanswered queue.
Thanks,
Sangeetha A
All Answers
Please find below the test class and the coverage is 100% with all test methods passing.
@isTest
public class AccountNameUpdate {
@isTest static void updateAccount(){
Account a = new Account();
a.Name = 'Abhishek Gupta';
insert a;
Booking_Link__c bl= new Booking_Link__c();
bl.Customer_Number__c = a.Customer_Number__c;
bl.T2G__c =True;
bl.Account__c = a.Id;
//bl.OwnerId = a.OwnerId;
insert bl;
}
}
Kindly mark this as solved if it's resolved so that it gets removed from the unanswered queue.
Thanks,
Sangeetha A
First, you have inserted the Booking_Link__c object after that you can update Booking_Link__c object fields.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks and Regards,
Ajay Dubedi
www.ajaydubedi.com