You need to sign in to do that
Don't have an account?
System.TypeException: Invalid integer: 319
Hi,
i am new to Apex coding
i want to generate reference like while creating an opportunity based on some cobination of fileds
Opp Number
DE_HP_1
DE_HP_2
DE_HP_3
RD_HP_1
RD_HP_2
RD_HP_3
RD_SR_1
so to generate ref like above i am writing apex trigger like before insert
String test1 ;
String test2 ;
String test3 ;
Integer test4 ;
for(Opportunity ct: Trigger.new)
{
test1 = ct.RECORDTYPEID;
test2 = ct.LEADINGUNIT__C;
test3 = ct.DIVISION__C;
}
AggregateResult[] groupedResults = [select MaxRefNumCount__c) refnum from Opportunity where RefNumCount__c != null
and RECORDTYPEID = :test1 and LEADINGUNIT__C :test2 and DIVISION__C :test3];
for (AggregateResult ar : groupedResults)
{
test4 = Integer.valueOf(ar.get('refnum'));
}
for(Opportunity ct1: Trigger.new)
{
ct1.RefNumCount__c = test4 + 1; //RefNumCount__c is Number filed (18,0)
ct1.OpprefNUm__C= test2 + '_' + test3 + '_' ct1.RefNumCount__c ;
}
but while saving opportunity i am getting error like
System.TypeException: Invalid integer: 319: Trigger.OpportunityBeforeInsert
i am getting error in test4 = Integer.valueOf(ar.get('refnum'));
any body please help me
What's the field type of refnum?
btw-looks like there's a typo in your SOQL:
Yours:
[select MaxRefNumCount__c) refnum from
My guess:
[select MaxRefNumCount__c, refnum__c from
HI
i got the solution like below .
RefNumCount__c is a Number datatype .
please check my apex coding style is this ok ? because i am new to Apex
String OppRecordType;
String OppLeadingUnit;
String OppDivision;
Integer refCountValue = 0 ;
for(Opportunity ct: Trigger.new)
{
OppRecordType = ct.RECORDTYPEID;
OppLeadingUnit = ct.LEADINGCONVERTEAMUNIT__C;
OppDivision = ct.DIVISION__C;
}
AggregateResult[] groupedResults = [select Max(RefNumCount__c) refnum from Opportunity where RECORDTYPEID = :OppRecordType and LEADINGCONVERTEAMUNIT__C = :OppLeadingUnit and DIVISION__C = :OppDivision ];
for (AggregateResult ar : groupedResults)
{
if (String.valueOf(ar.get('refnum')) == null)
{
refCountValue = 0;
}
else
{
refCountValue = Integer.valueOf(String.valueOf(ar.get('refnum')));
}
}
for(Opportunity ct1: Trigger.new)
{
ct1.RefNumCount__c = refCountValue + 1;
ct1.OLDNICENBR__C = OppLeadingUnit + '-' + OppDivision + '-000' + ct1.RefNumCount__c ;
}
RecordTypeID variable should be of type ID. Might need to change the type for OppLeadingUnit as well.
Id OppRecordType; String OppLeadingUnit; //is this just a text value? String OppDivision; Integer refCountValue = 0 ; for(Opportunity ct: Trigger.new) { OppRecordType = ct.RECORDTYPEID; OppLeadingUnit = ct.LEADINGCONVERTEAMUNIT__C; OppDivision = ct.DIVISION__C; } AggregateResult[] groupedResults = [select Max(RefNumCount__c) refnum from Opportunity where RECORDTYPEID = :oppRecordType and LEADINGCONVERTEAMUNIT__C = :oppLeadingUnit and DIVISION__C = :oppDivision ]; for (AggregateResult ar : groupedResults) { if (String.valueOf(ar.get('refnum')) == null) { refCountValue = 0; } else { refCountValue = Integer.valueOf(String.valueOf(ar.get('refnum'))); } } for(Opportunity ct1: Trigger.new) { ct1.RefNumCount__c = refCountValue + 1; ct1.OLDNICENBR__C = OppLeadingUnit + '-' + OppDivision + '-000' + ct1.RefNumCount__c ; }