salesforce - Amount change on Opportunity Apex Trigger [Resolved] -
trigger change quantity in negative number opportunitylineitems final opportunity amount in negative number if record type of opportunity 'revenue risk'
trigger risk_negativequantity on opportunitylineitem (before insert) { if(trigger.isinsert) { set<id> oppid = new set<id>(); (opportunitylineitem oli : trigger.new) { oppid.add(oli.opportunityid); } id revenuerisk= schema.sobjecttype.opportunity.getrecordtypeinfosbyname().get('revenue risk').getrecordtypeid(); list<opportunity> opplist = [select id, recordtype.name,recordtypeid opportunity id in : oppid ]; (opportunitylineitem oli : trigger.new) { (opportunity opp: opplist) { if (oli.opportunityid == opp.id) { if(opp.recordtype.name == 'revenue risk') { if(oli.quantity > 0) { oli.quantity = oli.quantity * -1; } } } } } } }
the error clear:
if(opplist.amount >= '0'){ // line throw error: 'comparison arguments must compatible types: integer (or double), string opplist.amount = opplist.amount * '-1'; // 1 too: 'arithmetic expressions must use numeric arguments' }
your second code snippet wrong (same first one).
if(opplist.amount >= 0){ opplist.amount = opplist.amount*-1; // must each.amount = each.amount * - 1; please try not use reserved words variable names }
you may want take @ previous post describing typed programming languages: strongly typed
Comments
Post a Comment