+ Start a Discussion
Dhilip DussaDhilip Dussa 

Avoid additional Record

This code is working fine but if i changed -91 to -90 r -92 then also one opportunity is creating can any one please fix this
    public static void insertOpportunity(list<OrderApi__Subscription__c> sub){
        set<id> ids = new set<id>();
        for(OrderApi__Subscription__c o : sub){
        list<Opportunity> op = new list<Opportunity>();

        for(OrderApi__Subscription__c o : [select id,OrderApi__Subscription_Plan__c,OrderApi__Days_To_Lapse__c,OrderApi__Contact__c,OrderApi__Contact__r.name,OrderApi__Item__c,OrderApi__Account__c from OrderApi__Subscription__c where id in : ids and (OrderApi__Item_Class__r.name='Silver Leader Membership' or OrderApi__Item_Class__r.name='Council Membership')]){
                Opportunity opp = new Opportunity(Name=o.OrderApi__Contact__r.name,AccountId=o.OrderApi__Account__c,ContactId=o.OrderApi__Contact__c,StageName='Qualified',Type='Existing Business',CloseDate=system.today()+365,Probability=10);
            insert op;
if -91 hits i need to insert opportunity this one is working fine, if i updated -91 to any other number then also opportunity is creating please help me on this bug.
About MeAbout Me
To start with minor debugging I would try below:
if(o.OrderApi__Days_To_Lapse__c==-91 && (o.OrderApi__Days_To_Lapse__c !=-92  || o.OrderApi__Days_To_Lapse__c !=-90){