You need to sign in to do that
Don't have an account?
conpas
How to build testmethod apex class for this apex trigger?
Helle, i want to build the testmethod apex class for a apex class trigger, but i dont obtain any result.
trigger t on Account (after update) {
for (Account a : Trigger.new) {
List<Contact> contactdata = [Select Id, AccountId, Name From Contact where AccountId = :a.Id];
if(contactdata.size()>0) {
List<User> userdata = [Select Id, ContactId From User where ContactId = :contactdata.get(0).Id];
if(userdata.size()>0) {
userdata.get(0).accspot__c = a.Spot_lead_time__c;
userdata.get(0).accstory__c = a.Storyboard_lead_time__c;
update userdata.get(0);
}
}
}
}
Thanks!!!
Hello,
Well use the below mention testmethod for that.Be sure to put the desired value for mendetory fields.
@isTestprivate class AccountTest
{public ststic testMethod void testAccount()
{
Profile p = [select id from profile where name='System Administrator'];
User u1 = new User(alias = 'standt2', email='standarduser@test12.com',emailencodingkey='UTF-8', lastname='Testing1', languagelocalekey='en_US',localesidkey='en_US', profileid = p.Id,firstname='Heather',timezonesidkey='America/Los_Angeles', username='standarduser@test12.com');
insert u1;
account a=new account(name='test',Spot_lead_time__c=Some value,Storyboard_lead_time__c=Some value);
insert a;
contact con=new contact(firstname='testing',lastname='contact1',accountid=a.id,ownerId=u1.id);
insert con;
a.name='test1';
update a;
}
}
Think this will help you.
All Answers
Hello,
Well use the below mention testmethod for that.Be sure to put the desired value for mendetory fields.
@isTestprivate class AccountTest
{public ststic testMethod void testAccount()
{
Profile p = [select id from profile where name='System Administrator'];
User u1 = new User(alias = 'standt2', email='standarduser@test12.com',emailencodingkey='UTF-8', lastname='Testing1', languagelocalekey='en_US',localesidkey='en_US', profileid = p.Id,firstname='Heather',timezonesidkey='America/Los_Angeles', username='standarduser@test12.com');
insert u1;
account a=new account(name='test',Spot_lead_time__c=Some value,Storyboard_lead_time__c=Some value);
insert a;
contact con=new contact(firstname='testing',lastname='contact1',accountid=a.id,ownerId=u1.id);
insert con;
a.name='test1';
update a;
}
}
Think this will help you.
is your code for portal user??
Thank you very much
Is for standard enterprise users.