trigger updatepipelineamountField on Opportunity (after update) {
Map<Id,Decimal> budgetIDTotalMap = new MAp<Id,Decimal>();
set<id> setbudgetId = new set<Id>();
for (Opportunity opp : Trigger.new)
{
if( opp.budget__c != null){
setbudgetId.add(opp.budget__c);
}
}
for(AggregateResult objArg : [SELECT budget__c, SUM(Amount) total FROM Opportunity WHERE budget__c IN: setbudgetId AND (stageName = 'Prospecting' OR stageName = 'Value Proposition') GROUP BY budget__c])
{
budgetIDTotalMap.put((Id)objArg.get('budget__c'), (Decimal)objArg.get('total'));
}
List<Budget__c> blist = [select id,Pipeline_Amount__c from budget__c where id in :setbudgetId];
for(Budget__c c: blist)
{
c.Pipeline_Amount__c = budgetIDTotalMap.containskey(c.id) ? budgetIDTotalMap.get(c.id) : 0;
}
update blist;
}
and I wrote a test class for this but I am getting error:
@isTest
private class TestupdatepipelineamountField {
@isTest static void TestupdatepipelineamountField() {
// Test data setup
// Create an account with an opportunity, and then try to delete it
Account acct = new Account(Name='Test Account');
insert acct;
acct=[SELECT Name FROM Account WHERE Id=:acct.Id];
System.assertEquals(acct.Name,'TestOpp');
Budget__c bud = new Budget__c(Name ='Jan', Budget_Amount__c = 10000, Won_Amount__c = 5000,
Commit_Amount__c = 2000, Best_Case_Amount__c = 1000,
Pipeline_Amount__c = 1000)
insert bud;
bud=[SELECT Name FROM Budget__c WHERE Id=:bud.Id];
System.assertEquals(bud.Name,'Jan');
Opportunity opp = new Opportunity(Name=acct.Name + ' Opportunity',
StageName='Prospecting',budget__c = bud.Name
CloseDate=System.today().addMonths(1),
AccountId=acct.Id);
insert opp;
opp=[SELECT Name FROM Opportunity WHERE Id=:opp.Id];
System.assertEquals(opp.Name,'TestOpp');
}
}
Error: unexpected token: 'insert' at line 14 column 8
can any one help me to figure out the error and let me know where I am wrong.
@Ratan
budget__c = bud.Name CloseDate=System.today().addMonths(1),
you forgot one,
here it should be likebudget__c = bud.Name, CloseDate=System.today().addMonths(1),