You need to sign in to do that
Don't have an account?
DaNae Peterson
System.Assert Exception Error
Hi all,
I am trying to get my quotes to autosync to the opportunity upon creation. I have the following controller, trigger, and test class:
controller:
public class QuoteAutoSyncUtil
{
@future
public static void syncQuote(Map<Id, Id> quoteMap)
{
List<Opportunity> oppList = new List<Opportunity>();
for(Id currentQuote : quoteMap.keyset())
{
Opportunity opp = new Opportunity();
opp.Id = quoteMap.get(currentQuote);
opp.SyncedQuoteId = currentQuote;
oppList.add(opp);
}
update oppList;
}
}
Trigger:
trigger QuoteAutoSync on Quote (after insert)
{
Map<Id, Id> quoteMap = new Map<Id, Id>();
for(Quote currentQuote : Trigger.New)
{
quoteMap.put(currentQuote.Id, currentQuote.OpportunityId);
}
QuoteAutoSyncUtil.syncQuote(quoteMap);
}
Test Class:
@isTest
private class TestQuoteAutoSync
{
static testMethod void insertQuote()
{
Opportunity opp = new Opportunity();
opp.Name = 'Test Opportunity';
opp.StageName = 'Prospecting';
opp.CloseDate = system.today();
insert opp;
Quote quo = new Quote();
quo.Name = 'Test Quote';
quo.OpportunityId = opp.Id;
Test.startTest();
insert quo;
Test.stopTest();
Opportunity o = [select SyncedQuoteId from opportunity where id=:opp.Id];
system.assert(o.SyncedQuoteId != null);
}
}
It is functioning properly in Sandbox and clears tests with 100% coverage but when I try to push to Production I get the following error with the test class:
System.AssertException: Assertion Failed
Stack Trace: Class.TestQuoteAutoSync.insertQuote: line 21, column 1
*Line 21 = system.assert(o.SyncedQuoteId != null);
Any ideas what I am missing?
Thanks!
I am trying to get my quotes to autosync to the opportunity upon creation. I have the following controller, trigger, and test class:
controller:
public class QuoteAutoSyncUtil
{
@future
public static void syncQuote(Map<Id, Id> quoteMap)
{
List<Opportunity> oppList = new List<Opportunity>();
for(Id currentQuote : quoteMap.keyset())
{
Opportunity opp = new Opportunity();
opp.Id = quoteMap.get(currentQuote);
opp.SyncedQuoteId = currentQuote;
oppList.add(opp);
}
update oppList;
}
}
Trigger:
trigger QuoteAutoSync on Quote (after insert)
{
Map<Id, Id> quoteMap = new Map<Id, Id>();
for(Quote currentQuote : Trigger.New)
{
quoteMap.put(currentQuote.Id, currentQuote.OpportunityId);
}
QuoteAutoSyncUtil.syncQuote(quoteMap);
}
Test Class:
@isTest
private class TestQuoteAutoSync
{
static testMethod void insertQuote()
{
Opportunity opp = new Opportunity();
opp.Name = 'Test Opportunity';
opp.StageName = 'Prospecting';
opp.CloseDate = system.today();
insert opp;
Quote quo = new Quote();
quo.Name = 'Test Quote';
quo.OpportunityId = opp.Id;
Test.startTest();
insert quo;
Test.stopTest();
Opportunity o = [select SyncedQuoteId from opportunity where id=:opp.Id];
system.assert(o.SyncedQuoteId != null);
}
}
It is functioning properly in Sandbox and clears tests with 100% coverage but when I try to push to Production I get the following error with the test class:
System.AssertException: Assertion Failed
Stack Trace: Class.TestQuoteAutoSync.insertQuote: line 21, column 1
*Line 21 = system.assert(o.SyncedQuoteId != null);
Any ideas what I am missing?
Thanks!
As this functionality has been accomplished by future method which runs asynchronously, so there is no guarantee for the time when this will be executed.
So, to make the assertion successful, you will have to give a dummy value to trigger handler like:
opp.SyncedQuoteId = Test.isRunningTest() ? currentQuote : '79978';//any value.
All Answers
As this functionality has been accomplished by future method which runs asynchronously, so there is no guarantee for the time when this will be executed.
So, to make the assertion successful, you will have to give a dummy value to trigger handler like:
opp.SyncedQuoteId = Test.isRunningTest() ? currentQuote : '79978';//any value.
You are missing SyncedQuoteId field on opportunity to set synced quote on opportunity.
@isTest
private class TestQuoteAutoSync
{
static testMethod void insertQuote()
{
Opportunity opp = new Opportunity();
opp.Name = 'Test Opportunity';
opp.StageName = 'Prospecting';
opp.CloseDate = system.today();
insert opp;
Quote quo = new Quote();
quo.Name = 'Test Quote';
quo.OpportunityId = opp.Id;
******************************
Opportunity o = [select SyncedQuoteId from opportunity where id=:opp.Id];
o.SyncedQuoteId = quo.Id;
******************************
Test.startTest();
insert quo;
Test.stopTest();
Opportunity o = [select SyncedQuoteId from opportunity where id=:opp.Id];
system.assert(o.SyncedQuoteId != null);
}
}
@isTest
private class TestQuoteAutoSync
{
static testMethod void insertQuote()
{
Opportunity opp = new Opportunity();
opp.Name = 'Test Opportunity';
opp.StageName = 'Prospecting';
opp.CloseDate = system.today();
insert opp;
Quote quo = new Quote();
quo.Name = 'Test Quote';
quo.OpportunityId = opp.Id;
Opportunity o = [select SyncedQuoteId from opportunity where id=:opp.Id];
o.SyncedQuoteId = Test.isRunningTest() ? quo.Id : '79978';
update o;
Test.startTest();
insert quo;
Test.stopTest();
Opportunity op = [select SyncedQuoteId from opportunity where id=:opp.Id];
system.assert(op.SyncedQuoteId != null);
}
}
Please use 15 or 18 digit quote Id at this line and then try:
o.SyncedQuoteId = Test.isRunningTest() ? quo.Id : '15 or 18 digit Id';