You need to sign in to do that
Don't have an account?
Sam Ward
How do I write a test class for updating a record
I'm new to apex code and I've got everything working its just the test class i'm struggling on.
Here is my Apex Class
My test class is:
Can anyone give me some advice to where i might be going wrong?
Thanks
Here is my Apex Class
public class ramassistAPI { @future (callout=true) public static void updateopp() { DVLA_Lookup_Opportunity__c DVLA = [SELECT id FROM DVLA_Lookup_Opportunity__c WHERE Stage__c = 'Closed Won' AND SentToAPI__c = 'Pending']; DVLA.SentToAPI__c = 'Sent'; update DVLA; } }
My test class is:
@isTest private class RamassistApiTest { static testMethod void TestOppUpdating() { Account acct = new Account(Name='Test'); insert acct; Contact con = new Contact(LastName = 'Bloggs',FirstName = 'Joe',Phone = '01234567890',Email = 'test@test.com',AccountId = acct.Id); insert con; DVLA_Lookup_Opportunity__c dvlaOpp = new DVLA_Lookup_Opportunity__c(Account__c = acct.Id, Stage__c = 'Closed Won',Close_Date__c = System.today(),SentToAPI__c = 'Pending',Contact__c = con.Id); insert dvlaOpp; dvlaOpp = [SELECT Id, SentToAPI__c FROM DVLA_Lookup_Opportunity__c WHERE Stage__c = 'Closed Won' AND SentToAPI__c = 'Sent' AND Id =: dvlaopp.Id]; dvlaOpp.SentToAPI__c = 'Sent'; update dvlaOpp; // Do the test test.startTest(); System.assertEquals('Sent', dvlaOpp.SentToAPI__c); test.stopTest(); } }
Can anyone give me some advice to where i might be going wrong?
Thanks
Try Below Code Please Mark It As Best Answer If It Helps
Thank You!
Apex Class
Apex Trigger
Apex TestClass
I get the below coverage
ramassistAPI 64%
RAMassistHTTP 83%
Any advice again would be good thank you.