• pavan kumar 1864
  • NEWBIE
  • 50 Points
  • Member since 2021

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 8
    Questions
  • 10
    Replies
HI,I HAVE A REQUIREMENT WHICH STATES THAT IF Account.Agreement_type__c AND Opportunity.Agreement_type__c IS NOT BLANK AND IF BOTH THE VALUES ARE THE SAME THEN RETURN 1 OR ELSE 0.

IF(NOT(ISBLANK(Account.Agreement_type__c)) AND NOT(ISBLANK(Opportunity.Agreement_type__c)) 
AND (TEXT(Account.Agreement_type__c) == TEXT(Opportunity.Agreement_type__c)),1,0)


I'M GETTING A ERROR AS MISSING ) AND DON'T KNOW WHETHER THIS CODES WORKS AS PER MY REQUIREMENT OR NOT.
CAN ANYONE GUIDE ME
Everything is  fine but at the last im not getting to updtae,i'm missing out in Brackets ,can anyone please guide me.

global class corporatearrbatch implements Database.Batchable<sObject>{
    
    public string a;
    
    public  corporatearrbatch()
    {
        a= 'select id,name,Corporate_Arr__c,createddate from account where type =\'Customer - Direct\' and id = \'0015g00000Gba22AAB\'';
    }
    
    public Database.querylocator start(Database.BatchableContext bc)
    {
        return Database.getquerylocator(a);
    }
    public void execute(Database.BatchableContext bc,list<account>accountrecords)
    {
        system.debug(accountrecords);
        
        
        
        list<account> accountupdated = new list<account>();
        map<id,account> mapname =new map<id,account>();
        
        map<id,list<opportunity>> opportunitylistwithid = new map<id,list<opportunity>>();
        
        map<id,Datetime> opportunityidwithmaxdate = new map<id,Datetime>();
        
        list<opportunity>opportunityrecords = [select id,name,accountid,StageName,CloseDate,Incremental_ARR__c,Corporate_Incremental_ARR__c,Corporate_effective_date__c,Contract_end_date__c from opportunity where (stagename = 'Closed Won' or stagename ='Closed: won - S' or stagename ='Closed: won - Renewal') and accountid in : accountrecords];
        
        system.debug(opportunityrecords.size());
        system.debug(opportunityrecords);
        
        Datetime maxdatefromopportunity;
        
        for(opportunity opportunityrecord : opportunityrecords)
        {
            
            maxdatefromopportunity = Null ;
            
            list<opportunity>opportunitylist = opportunitylistwithid.get(opportunityrecord.accountid);
            
            if(opportunitylist == Null)
            {
                opportunitylist = new list<opportunity>();
            }
            
            opportunitylist.add(opportunityrecord);
            
            opportunitylistwithid.put(opportunityrecord.accountid,opportunitylist);
            system.debug(opportunitylistwithid.size());
            
            if(opportunityrecord.Corporate_effective_date__c == Null)
            {
                maxdatefromopportunity = opportunityrecord.CloseDate;
                system.debug(maxdatefromopportunity);
            }
            
            else if(opportunityrecord.CloseDate >= opportunityrecord.Corporate_effective_date__c)
            {
                maxdatefromopportunity = opportunityrecord.CloseDate;
                system.debug(maxdatefromopportunity);
            }
            
            else
            {
                maxdatefromopportunity = opportunityrecord.Corporate_effective_date__c;
                system.debug(maxdatefromopportunity);
            }
            
            opportunityidwithmaxdate.put(opportunityrecord.id,maxdatefromopportunity);
            system.debug(opportunityidwithmaxdate);
        }
        
        Decimal maxamount = 0.00;
        
        account acc = new account ();
        
        for(id accountids : opportunitylistwithid.keyset())
        {
            system.debug('accountids'+ accountids);
            
            list<opportunity> opportunitylist = opportunitylistwithid.get(accountids);
            
            system.debug('opportunitylistwith correspondentaccountid'+ opportunitylist);
            
            for(opportunity opportunitysinglerecord : opportunitylist)
            {
                system.debug('opportunitylist----------'+ opportunitysinglerecord);
                
                
                if(opportunitylist.size()>1 && opportunitysinglerecord.Incremental_ARR__c != null)
                {
                    system.debug(1);
                    system.debug(opportunitylist.size());
                    
                    if(date.today() >= opportunityidwithmaxdate.get(opportunitysinglerecord.id))
                    {
                        system.debug(2);
                        if(opportunitysinglerecord.Corporate_Incremental_ARR__c == Null)
                        {
                            system.debug(3);
                            
                            maxamount = maxamount + opportunitysinglerecord.Incremental_ARR__c;
                            acc.id = opportunitysinglerecord.accountid;
                            
                            system.debug('maxamount--------------'+ maxamount);
                            system.debug('accid-------------'+ opportunitysinglerecord);
                            
                            
                        }
                        else
                        {
                            system.debug(4);
                            maxamount= maxamount + opportunitysinglerecord.Corporate_Incremental_ARR__c;
                            acc.id = opportunitysinglerecord.accountid;
                            system.debug('maxamount--------------'+ maxamount);
                            system.debug('accid-------------'+ opportunitysinglerecord);
                        }
                    } 
                }
                
                else {
                    if(opportunitylist.size() == 1 && opportunitylist.size() != null )
                    {
                        system.debug(5);
                        if(opportunitysinglerecord.Incremental_ARR__c != null)
                        {
                            system.debug(6);
                            maxamount = opportunitysinglerecord.Incremental_ARR__c;
                            system.debug('maxamount--------------'+ maxamount);
                            
                        }
                        else
                        {
                            system.debug(7);
                            maxamount = 0;
                            system.debug('maxamount--------------'+ maxamount);
                        }
                    }}
                acc.id = opportunitysinglerecord.AccountId;
                system.debug(acc.id = opportunitysinglerecord.AccountId);
                
                if(maxamount != null)
                {
                    acc.Corporate_Arr__c = maxamount;
                    system.debug( acc.Corporate_Arr__c);
                    accountupdated.add(acc);
                     system.debug(acc);
                }
            }
            
            
        }
        
        
        if(accountupdated != null)
        {    mapname.putall(accountupdated);
         if(mapname!=null)
         {
             update mapname.values();
         }
         
        }
        
        system.debug(acc);
        system.debug(mapname);
    }
    public void finish(Database.BatchableContext bc)
    {
        
    }
}
 
I have a formula field name Partner_involved__c on opportunity object, it should be marked 'true' when amount field in opportunity object is not blank, so i have written a formula-

IF(ISBLANK(Amount),"True","False")

but here irrespective of the amount field whether it is blank or not ,
The Formula field named Partner_involved__c is marking as 'False'.


Can anyone please explain how i can overcome this.
Hi all this is my class
Global class UPDATINGFROMOPPORTUNITYTOACCOUNT implements database.batchable<sObject>{
    
     string ferchingaccountrecords;
   
   
    public UPDATINGFROMOPPORTUNITYTOACCOUNT()
    {
        
        ferchingaccountrecords = 'select id,name,Agreement_type__c,    Partner_involved__c,Self_servied__c,Edition_type__c from account where type = \'Customer - Direct\'';
    }
    
    
    Global database.querylocator start (database.BatchableContext bc)
    {
        
        return database.getquerylocator(ferchingaccountrecords);
    }
    
    
    Global void execute(database.BatchableContext bc,list<account>accountfetched)
    {
        
        list<account> newupdatedaccount = new list <account>();
    map<id,opportunity> mapofaccountopportunity = new map<id,opportunity>();
        
        for(opportunity opportunityrecords : [select id,Agreement_type__c,type,accountid,Partner_involved__c,Edition_type__c from opportunity 
                                              where accountid in :accountfetched 
                                              and StageName ='Closed Won' and 
                                              (type != 'Services Only' or type !='Paid POC' or type !='Change-Order' or type != 'Amendment')
                                              order by CloseDate desc limit 1]) 
        {
            mapofaccountopportunity.put(opportunityrecords.accountid,opportunityrecords);                         
            
        }
        
        account newaccount = new account();
        
        
        for(id accountid : mapofaccountopportunity.keyset()){
            
            
            opportunity opportunityrecord = mapofaccountopportunity.get(accountid);
            
            if(opportunityrecord.Type=='New Logo' || opportunityrecord.Type=='Upgrade' || opportunityrecord.Type=='Renewal' || opportunityrecord.Type=='Cross-Sell')
            {
                if(opportunityrecord.Partner_involved__c=='True')
                {
                    newaccount.Partner_involved__c =  true;
                    
                }
                else
                {
                    newaccount.Partner_involved__c = false;
                }
            }
            if(opportunityrecord.Edition_type__c!= null)
            {
                newaccount.Edition_type__c = opportunityrecord.Edition_type__c;
            }
            else
            {
                newaccount.Edition_type__c = '';
            }
            
            if(opportunityrecord.Agreement_type__c!= null)
            {
                 newaccount.Agreement_type__c = opportunityrecord.Agreement_type__c;
                
                if(opportunityrecord.Agreement_type__c == 'Self-Service')
                {
                    newaccount.Self_servied__c = true;
                    
                }
                else
                {
                    newaccount.Self_servied__c = false; 
                   
                }
                
                
            }
            
            else
            {
                newaccount.Self_servied__c = false; 
                newaccount.Agreement_type__c = '';
            }
            
            newaccount.Id = opportunityrecord.AccountId;
            
        }
        
        if(newaccount!=null)
        {
            newupdatedaccount.add(newaccount);
            update newupdatedaccount;
        }
        
    }
    
    Global void finish(database.BatchableContext bc)
    {
        
    }
    
}

this is my test class

@istest
public class updateaaccountfromopportunity {
    
    
    @testsetup
    public static void method()
    {       
        account acountrecord = new account();
        acountrecord.name= 'pavabn';       
        acountrecord.type= 'Customer - Direct';
        insert acountrecord;
        
        opportunity opportunityrecord = new opportunity();
        opportunityrecord.name= 'pavan';
        opportunityrecord.Agreement_type__c='Order Form';
        opportunityrecord.Amount=30;
        opportunityrecord.Edition_type__c='';
        opportunityrecord.type='Customer - Direct';
        opportunityrecord.accountid= acountrecord.id;
        opportunityrecord.type= 'New Logo';
        opportunityrecord.StageName ='Closed Won';
        opportunityrecord.CloseDate= system.today()+5;
        opportunityrecord.Stage__c='Stage 3';
        insert opportunityrecord;
        
        
        opportunity opportunityrecord1 = new opportunity();
        opportunityrecord1.name= 'pava';
        opportunityrecord1.Agreement_type__c='Self-Service';
        // aaa.Partner_involved__c =True;
        opportunityrecord1.Edition_type__c='Essentials';
        opportunityrecord1.type='Customer - Direct';
        opportunityrecord1.accountid= acountrecord.id;
        opportunityrecord1.type= 'New Customer';
        opportunityrecord1.StageName='Qualification';
        opportunityrecord1.CloseDate= system.today()+4;
        opportunityrecord1.Stage__c='Stage 3';
        insert opportunityrecord1; 
        
        
        UPDATINGFROMOPPORTUNITYTOACCOUNT updatingaccount = new UPDATINGFROMOPPORTUNITYTOACCOUNT();
        
        Test.startTest();
        id updatingaccountid = database.executebatch(updatingaccount,10);
        Test.stopTest(); 
        
        
        
        
        system.assertEquals(false, acountrecord.Partner_involved__c);
        system.assertEquals(null,acountrecord.Edition_type__c);
        system.assertEquals(false,acountrecord.Self_servied__c);
        system.assertEquals(null,acountrecord.Agreement_type__c);
        
    }
    
    
    public static testmethod void method2()
    {
        account acountrecord8 = new account();
        acountrecord8.name= 'paaavabn';  
        acountrecord8.type= 'Customer - Direct';
        insert acountrecord8;
        
        opportunity opportunityrecord4 = new opportunity();
        opportunityrecord4.name= 'pavaaaaan';
         opportunityrecord4.Agreement_type__c='Self-Service';
        // aaa.Partner_involved__c =True;
        opportunityrecord4.Edition_type__c='';
        opportunityrecord4.type='';
        opportunityrecord4.accountid= acountrecord8.id;
        opportunityrecord4.type= ' ';
        opportunityrecord4.StageName='Qualification';
        opportunityrecord4.CloseDate= system.today()+5;
        opportunityrecord4.Stage__c='Stage 4';
        insert opportunityrecord4;
        
        opportunity opportunityrecord2 = new opportunity();
        opportunityrecord2.name= 'pavaaaa';
        opportunityrecord2.Agreement_type__c=' ';
        // aaa.Partner_involved__c =True;
        opportunityrecord2.Edition_type__c='';
        opportunityrecord2.type='';
        opportunityrecord2.accountid= acountrecord8.id;
        opportunityrecord2.type= ' ';
        opportunityrecord2.StageName='Qualification';
        opportunityrecord2.CloseDate= system.today()+4;
        opportunityrecord2.Stage__c='Stage 4';
        insert opportunityrecord2; 
        
        
        UPDATINGFROMOPPORTUNITYTOACCOUNT updatingaccount1 = new UPDATINGFROMOPPORTUNITYTOACCOUNT();
        
        Test.startTest();
        id updatingaccountid = database.executebatch(updatingaccount1,10);
        Test.stopTest(); 
        
        system.assertEquals(true,acountrecord8.Self_servied__c);
    }}


Can any one  please explain how to achieve 100% coverage and how it can be achieved?
Hi, i have put up a condition in class using Formula Field and now in the test class i want to use it For unit Testing,If i give the value to Formula Filed  the Error is popping up as this is NON- WRITTEABLE...what is the workaroud for this
public class triggerclassss {
    public set<id> aa= new set<id>();
    
    public  void accountss(list<contact>aaas){
        
        system.debug('contacts----'+aaas);
        
        for(contact c : aaas)
        {
            aa.add(c.accountid);
            
            system.debug('account ids----'+ c);
        }
        
        
        
        map<id,account> hg =  new map<id,account>([select id,name,phone from account where id in : aa]);
        
        system.debug('account with id and records'+hg);
        for(contact c : aaas)
        {
            
            if(c.accountid == hg.get(c.accountid).id)
            {
                
                system.debug('matching id with accuont and contact'+hg);
                c.phone = hg.get(c.accountid).phone;
            }
            system.debug('assigning contact phone'+c.phone);
        }
    }
}

can anyone please tell me why null pointer exception displaying at line 23
This is the batch class..
Global class UPDATINGFROMOPPORTUNITYTOACCOUNT implements database.batchable<sObject>{
    
    public string ferchingaccountrecords;
    public list<Account> listofaccount = new list<Account>();
   
    public UPDATINGFROMOPPORTUNITYTOACCOUNT(list<Account> IdAccount)
    {
        listofaccount = IdAccount;
        ferchingaccountrecords = 'select id,name,Agreement_type__c,    Partner_involved__c,Self_servied__c,Edition_type__c from account where type = \'Customer - Direct\' and id in : listofaccount';
    }
    
    
    Global database.querylocator start (database.BatchableContext bc)
    {
        
        return database.getquerylocator(ferchingaccountrecords);
    }
    
    
    Global void execute(database.BatchableContext bc,list<account>accountfetched)
    {
        
        list<account> newupdatedaccount = new list <account>();
        map<id,opportunity> mapofaccountopportunity = new map<id,opportunity>();
        
        for(opportunity opportunityrecords : [select id,Agreement_type__c,type,accountid,Partner_involved__c,Edition_type__c from opportunity 
                                              where accountid in :accountfetched 
                                              and
                                              (type != 'Services Only' or type !='Paid POC' or type !='Change-Order' or type != 'Amendment')
                                              order by CloseDate desc limit 1]) 
        {
            mapofaccountopportunity.put(opportunityrecords.accountid,opportunityrecords);                         
            
        }
        
        account newaccount = new account();
        
        
        for(id accountid : mapofaccountopportunity.keyset()){
            
            
            opportunity opportunityrecord = mapofaccountopportunity.get(accountid);
            
            if(opportunityrecord.Type=='New Logo' || opportunityrecord.Type=='Upgrade' || opportunityrecord.Type=='Renewal' || opportunityrecord.Type=='Cross-Sell')
            {
                if(opportunityrecord.Partner_involved__c=='True')
                {
                    newaccount.Partner_involved__c =  true;
                    
                }
                else
                {
                    newaccount.Partner_involved__c = false;
                }
            }
            if(opportunityrecord.Edition_type__c!= null)
            {
                newaccount.Edition_type__c = opportunityrecord.Edition_type__c;
            }
            else
            {
                newaccount.Edition_type__c = '';
            }
            
            if(opportunityrecord.Agreement_type__c!= null)
            {
                if(opportunityrecord.Agreement_type__c == 'Self-Service')
                {
                    newaccount.Self_servied__c = true;
                    
                }
                else
                {
                    newaccount.Self_servied__c = false; 
                    newaccount.Agreement_type__c = opportunityrecord.Agreement_type__c;
                }
            }
            else
            {
                newaccount.Self_servied__c = false; 
                newaccount.Agreement_type__c = '';
            }
            
            newaccount.Id = opportunityrecord.AccountId;
            
        }
        
        if(newaccount!=null)
        {
            newupdatedaccount.add(newaccount);
            update newupdatedaccount;
        }
        
    }
    
    Global void finish(database.BatchableContext bc)
    {
        
    }
    
-------------------------------------------------
this is the trigger which is invoking batch class

trigger updateaccountfromopportunity on Account (before update) {
    if(trigger.isexecuting && trigger.isbefore && trigger.isupdate)
    {
        if(!system.isbatch()){    
    list<Account> IdAccount = new list<Account>();
    for(Account acc:trigger.new){
                    IdAccount.add(acc);
            }
    if(IdAccount.size() > 0){
        
        database.executeBatch(new UPDATINGFROMOPPORTUNITYTOACCOUNT(IdAccount)); // Calling batch class.
    }

        }}
}

---------------------------------------------------------
this is the test class

@istest
public class updateaaccountfromopportunity {
    
    static list<account>acountrecordlist = new list<account>();
    @testsetup
    public static void method()
    {
        
        
        account acountrecord = new account();
        acountrecord.name= 'pavabn';
        acountrecord.Agreement_type__c='Order Form';
        acountrecord.Partner_involved__c =True;
        acountrecord.Self_servied__c=True;
        acountrecord.Edition_type__c='Enterprise';
        acountrecord.type='Customer - Direct';
        
        insert acountrecord;
        acountrecordlist.add(acountrecord);
        
        
        opportunity opportunityrecord = new opportunity();
        
        opportunityrecord.name= 'pavabn';
        opportunityrecord.Agreement_type__c='Order Form';
        // aaa.Partner_involved__c =True;
        opportunityrecord.Edition_type__c='Enterprise';
        opportunityrecord.type='Customer - Direct';
        opportunityrecord.accountid= acountrecord.id;
        opportunityrecord.type= 'New Customer';
        opportunityrecord.StageName='Qualification';
        opportunityrecord.CloseDate= system.today()+5;
        opportunityrecord.Stage__c='Stage 3';
        insert opportunityrecord;
        
        account accountquery = [select Agreement_type__c,Self_servied__c,Edition_type__c,Partner_involved__c from account where id = :acountrecord.id];
        
        accountquery.Edition_type__c='professional';
        update accountquery;
        
        opportunity opportunityquery = [select Agreement_type__c,Edition_type__c,type,Partner_involved__c from opportunity where accountid = : accountquery.id];       
        
        account lea = [select Agreement_type__c,Self_servied__c,Edition_type__c,Partner_involved__c from account where id = : accountquery.id];
        
        system.assertEquals('Order Form',lea.Agreement_type__c);
        system.assertEquals(true,lea.Self_servied__c);
        system.assertEquals('professional',lea.Edition_type__c);
        system.assertEquals(true,lea.Partner_involved__c);
        
        
        
        UPDATINGFROMOPPORTUNITYTOACCOUNT ada = new UPDATINGFROMOPPORTUNITYTOACCOUNT(acountrecordlist);
        //   insert aaa;
        
        Test.startTest();
        id aakak = database.executebatch(ada,10);
        
        Test.stopTest(); 
    }
    
    public static testmethod void method2()
    {
        account leads = [select Agreement_type__c,Self_servied__c,Edition_type__c,Partner_involved__c from account];
        
        leads.Edition_type__c='professional';
        update leads;
        
        opportunity opp = [select Agreement_type__c,Edition_type__c,type,Partner_involved__c from opportunity where accountid = : leads.id];
        
        account lea = [select Agreement_type__c,Self_servied__c,Edition_type__c,Partner_involved__c from account where id = : opp.accountid];
        
        system.assertEquals('Order Form',lea.Agreement_type__c);
        system.assertEquals(true,lea.Self_servied__c);
        system.assertEquals('professional',lea.Edition_type__c);
        system.assertEquals(true,lea.Partner_involved__c);
        
        
        
        UPDATINGFROMOPPORTUNITYTOACCOUNT ada = new UPDATINGFROMOPPORTUNITYTOACCOUNT(acountrecordlist);
        //   insert aaa;
        
        Test.startTest();
        id aakak = database.executebatch(ada,10);
        
        Test.stopTest(); 
    }} 
-------------------------------------------------------------------

im not getting to write test class can anyone help me out?
public class batchjobassignment implements Database.batchable<sObject>
{
    
    public  Database.querylocator start(Database.batchablecontext bc)
    {
        string s= 'select id from opportunity where StageName = \'Closed Won\'';
        return (Database.getquerylocator(s));
        // system.debug(s);
    }
    public  void execute(Database.batchablecontext bc,list<opportunity>opp)
    {    set<id>oppid = new set<id>();
     for(opportunity op : opp)
     {
         oppid.add(op.accountid);            
     }
     list<account> acc = [select id, name, Latest_owner__c,(select id, OwnerId from Opportunities) from account where id in :oppid];
     
     list<account>acountnew = new list<account>();
     
     for(account aa : acc)
     {
         for(opportunity oo : aa.Opportunities){
             
             aa.Latest_owner__c = oo.OwnerId;
             acountnew.add(aa);
         }
     }
     update acountnew;
    }
    public  void finish(Database.batchablecontext bc){
        
    }
}
Everything is  fine but at the last im not getting to updtae,i'm missing out in Brackets ,can anyone please guide me.

global class corporatearrbatch implements Database.Batchable<sObject>{
    
    public string a;
    
    public  corporatearrbatch()
    {
        a= 'select id,name,Corporate_Arr__c,createddate from account where type =\'Customer - Direct\' and id = \'0015g00000Gba22AAB\'';
    }
    
    public Database.querylocator start(Database.BatchableContext bc)
    {
        return Database.getquerylocator(a);
    }
    public void execute(Database.BatchableContext bc,list<account>accountrecords)
    {
        system.debug(accountrecords);
        
        
        
        list<account> accountupdated = new list<account>();
        map<id,account> mapname =new map<id,account>();
        
        map<id,list<opportunity>> opportunitylistwithid = new map<id,list<opportunity>>();
        
        map<id,Datetime> opportunityidwithmaxdate = new map<id,Datetime>();
        
        list<opportunity>opportunityrecords = [select id,name,accountid,StageName,CloseDate,Incremental_ARR__c,Corporate_Incremental_ARR__c,Corporate_effective_date__c,Contract_end_date__c from opportunity where (stagename = 'Closed Won' or stagename ='Closed: won - S' or stagename ='Closed: won - Renewal') and accountid in : accountrecords];
        
        system.debug(opportunityrecords.size());
        system.debug(opportunityrecords);
        
        Datetime maxdatefromopportunity;
        
        for(opportunity opportunityrecord : opportunityrecords)
        {
            
            maxdatefromopportunity = Null ;
            
            list<opportunity>opportunitylist = opportunitylistwithid.get(opportunityrecord.accountid);
            
            if(opportunitylist == Null)
            {
                opportunitylist = new list<opportunity>();
            }
            
            opportunitylist.add(opportunityrecord);
            
            opportunitylistwithid.put(opportunityrecord.accountid,opportunitylist);
            system.debug(opportunitylistwithid.size());
            
            if(opportunityrecord.Corporate_effective_date__c == Null)
            {
                maxdatefromopportunity = opportunityrecord.CloseDate;
                system.debug(maxdatefromopportunity);
            }
            
            else if(opportunityrecord.CloseDate >= opportunityrecord.Corporate_effective_date__c)
            {
                maxdatefromopportunity = opportunityrecord.CloseDate;
                system.debug(maxdatefromopportunity);
            }
            
            else
            {
                maxdatefromopportunity = opportunityrecord.Corporate_effective_date__c;
                system.debug(maxdatefromopportunity);
            }
            
            opportunityidwithmaxdate.put(opportunityrecord.id,maxdatefromopportunity);
            system.debug(opportunityidwithmaxdate);
        }
        
        Decimal maxamount = 0.00;
        
        account acc = new account ();
        
        for(id accountids : opportunitylistwithid.keyset())
        {
            system.debug('accountids'+ accountids);
            
            list<opportunity> opportunitylist = opportunitylistwithid.get(accountids);
            
            system.debug('opportunitylistwith correspondentaccountid'+ opportunitylist);
            
            for(opportunity opportunitysinglerecord : opportunitylist)
            {
                system.debug('opportunitylist----------'+ opportunitysinglerecord);
                
                
                if(opportunitylist.size()>1 && opportunitysinglerecord.Incremental_ARR__c != null)
                {
                    system.debug(1);
                    system.debug(opportunitylist.size());
                    
                    if(date.today() >= opportunityidwithmaxdate.get(opportunitysinglerecord.id))
                    {
                        system.debug(2);
                        if(opportunitysinglerecord.Corporate_Incremental_ARR__c == Null)
                        {
                            system.debug(3);
                            
                            maxamount = maxamount + opportunitysinglerecord.Incremental_ARR__c;
                            acc.id = opportunitysinglerecord.accountid;
                            
                            system.debug('maxamount--------------'+ maxamount);
                            system.debug('accid-------------'+ opportunitysinglerecord);
                            
                            
                        }
                        else
                        {
                            system.debug(4);
                            maxamount= maxamount + opportunitysinglerecord.Corporate_Incremental_ARR__c;
                            acc.id = opportunitysinglerecord.accountid;
                            system.debug('maxamount--------------'+ maxamount);
                            system.debug('accid-------------'+ opportunitysinglerecord);
                        }
                    } 
                }
                
                else {
                    if(opportunitylist.size() == 1 && opportunitylist.size() != null )
                    {
                        system.debug(5);
                        if(opportunitysinglerecord.Incremental_ARR__c != null)
                        {
                            system.debug(6);
                            maxamount = opportunitysinglerecord.Incremental_ARR__c;
                            system.debug('maxamount--------------'+ maxamount);
                            
                        }
                        else
                        {
                            system.debug(7);
                            maxamount = 0;
                            system.debug('maxamount--------------'+ maxamount);
                        }
                    }}
                acc.id = opportunitysinglerecord.AccountId;
                system.debug(acc.id = opportunitysinglerecord.AccountId);
                
                if(maxamount != null)
                {
                    acc.Corporate_Arr__c = maxamount;
                    system.debug( acc.Corporate_Arr__c);
                    accountupdated.add(acc);
                     system.debug(acc);
                }
            }
            
            
        }
        
        
        if(accountupdated != null)
        {    mapname.putall(accountupdated);
         if(mapname!=null)
         {
             update mapname.values();
         }
         
        }
        
        system.debug(acc);
        system.debug(mapname);
    }
    public void finish(Database.BatchableContext bc)
    {
        
    }
}
 
I have a formula field name Partner_involved__c on opportunity object, it should be marked 'true' when amount field in opportunity object is not blank, so i have written a formula-

IF(ISBLANK(Amount),"True","False")

but here irrespective of the amount field whether it is blank or not ,
The Formula field named Partner_involved__c is marking as 'False'.


Can anyone please explain how i can overcome this.
Hi all this is my class
Global class UPDATINGFROMOPPORTUNITYTOACCOUNT implements database.batchable<sObject>{
    
     string ferchingaccountrecords;
   
   
    public UPDATINGFROMOPPORTUNITYTOACCOUNT()
    {
        
        ferchingaccountrecords = 'select id,name,Agreement_type__c,    Partner_involved__c,Self_servied__c,Edition_type__c from account where type = \'Customer - Direct\'';
    }
    
    
    Global database.querylocator start (database.BatchableContext bc)
    {
        
        return database.getquerylocator(ferchingaccountrecords);
    }
    
    
    Global void execute(database.BatchableContext bc,list<account>accountfetched)
    {
        
        list<account> newupdatedaccount = new list <account>();
    map<id,opportunity> mapofaccountopportunity = new map<id,opportunity>();
        
        for(opportunity opportunityrecords : [select id,Agreement_type__c,type,accountid,Partner_involved__c,Edition_type__c from opportunity 
                                              where accountid in :accountfetched 
                                              and StageName ='Closed Won' and 
                                              (type != 'Services Only' or type !='Paid POC' or type !='Change-Order' or type != 'Amendment')
                                              order by CloseDate desc limit 1]) 
        {
            mapofaccountopportunity.put(opportunityrecords.accountid,opportunityrecords);                         
            
        }
        
        account newaccount = new account();
        
        
        for(id accountid : mapofaccountopportunity.keyset()){
            
            
            opportunity opportunityrecord = mapofaccountopportunity.get(accountid);
            
            if(opportunityrecord.Type=='New Logo' || opportunityrecord.Type=='Upgrade' || opportunityrecord.Type=='Renewal' || opportunityrecord.Type=='Cross-Sell')
            {
                if(opportunityrecord.Partner_involved__c=='True')
                {
                    newaccount.Partner_involved__c =  true;
                    
                }
                else
                {
                    newaccount.Partner_involved__c = false;
                }
            }
            if(opportunityrecord.Edition_type__c!= null)
            {
                newaccount.Edition_type__c = opportunityrecord.Edition_type__c;
            }
            else
            {
                newaccount.Edition_type__c = '';
            }
            
            if(opportunityrecord.Agreement_type__c!= null)
            {
                 newaccount.Agreement_type__c = opportunityrecord.Agreement_type__c;
                
                if(opportunityrecord.Agreement_type__c == 'Self-Service')
                {
                    newaccount.Self_servied__c = true;
                    
                }
                else
                {
                    newaccount.Self_servied__c = false; 
                   
                }
                
                
            }
            
            else
            {
                newaccount.Self_servied__c = false; 
                newaccount.Agreement_type__c = '';
            }
            
            newaccount.Id = opportunityrecord.AccountId;
            
        }
        
        if(newaccount!=null)
        {
            newupdatedaccount.add(newaccount);
            update newupdatedaccount;
        }
        
    }
    
    Global void finish(database.BatchableContext bc)
    {
        
    }
    
}

this is my test class

@istest
public class updateaaccountfromopportunity {
    
    
    @testsetup
    public static void method()
    {       
        account acountrecord = new account();
        acountrecord.name= 'pavabn';       
        acountrecord.type= 'Customer - Direct';
        insert acountrecord;
        
        opportunity opportunityrecord = new opportunity();
        opportunityrecord.name= 'pavan';
        opportunityrecord.Agreement_type__c='Order Form';
        opportunityrecord.Amount=30;
        opportunityrecord.Edition_type__c='';
        opportunityrecord.type='Customer - Direct';
        opportunityrecord.accountid= acountrecord.id;
        opportunityrecord.type= 'New Logo';
        opportunityrecord.StageName ='Closed Won';
        opportunityrecord.CloseDate= system.today()+5;
        opportunityrecord.Stage__c='Stage 3';
        insert opportunityrecord;
        
        
        opportunity opportunityrecord1 = new opportunity();
        opportunityrecord1.name= 'pava';
        opportunityrecord1.Agreement_type__c='Self-Service';
        // aaa.Partner_involved__c =True;
        opportunityrecord1.Edition_type__c='Essentials';
        opportunityrecord1.type='Customer - Direct';
        opportunityrecord1.accountid= acountrecord.id;
        opportunityrecord1.type= 'New Customer';
        opportunityrecord1.StageName='Qualification';
        opportunityrecord1.CloseDate= system.today()+4;
        opportunityrecord1.Stage__c='Stage 3';
        insert opportunityrecord1; 
        
        
        UPDATINGFROMOPPORTUNITYTOACCOUNT updatingaccount = new UPDATINGFROMOPPORTUNITYTOACCOUNT();
        
        Test.startTest();
        id updatingaccountid = database.executebatch(updatingaccount,10);
        Test.stopTest(); 
        
        
        
        
        system.assertEquals(false, acountrecord.Partner_involved__c);
        system.assertEquals(null,acountrecord.Edition_type__c);
        system.assertEquals(false,acountrecord.Self_servied__c);
        system.assertEquals(null,acountrecord.Agreement_type__c);
        
    }
    
    
    public static testmethod void method2()
    {
        account acountrecord8 = new account();
        acountrecord8.name= 'paaavabn';  
        acountrecord8.type= 'Customer - Direct';
        insert acountrecord8;
        
        opportunity opportunityrecord4 = new opportunity();
        opportunityrecord4.name= 'pavaaaaan';
         opportunityrecord4.Agreement_type__c='Self-Service';
        // aaa.Partner_involved__c =True;
        opportunityrecord4.Edition_type__c='';
        opportunityrecord4.type='';
        opportunityrecord4.accountid= acountrecord8.id;
        opportunityrecord4.type= ' ';
        opportunityrecord4.StageName='Qualification';
        opportunityrecord4.CloseDate= system.today()+5;
        opportunityrecord4.Stage__c='Stage 4';
        insert opportunityrecord4;
        
        opportunity opportunityrecord2 = new opportunity();
        opportunityrecord2.name= 'pavaaaa';
        opportunityrecord2.Agreement_type__c=' ';
        // aaa.Partner_involved__c =True;
        opportunityrecord2.Edition_type__c='';
        opportunityrecord2.type='';
        opportunityrecord2.accountid= acountrecord8.id;
        opportunityrecord2.type= ' ';
        opportunityrecord2.StageName='Qualification';
        opportunityrecord2.CloseDate= system.today()+4;
        opportunityrecord2.Stage__c='Stage 4';
        insert opportunityrecord2; 
        
        
        UPDATINGFROMOPPORTUNITYTOACCOUNT updatingaccount1 = new UPDATINGFROMOPPORTUNITYTOACCOUNT();
        
        Test.startTest();
        id updatingaccountid = database.executebatch(updatingaccount1,10);
        Test.stopTest(); 
        
        system.assertEquals(true,acountrecord8.Self_servied__c);
    }}


Can any one  please explain how to achieve 100% coverage and how it can be achieved?
public class triggerclassss {
    public set<id> aa= new set<id>();
    
    public  void accountss(list<contact>aaas){
        
        system.debug('contacts----'+aaas);
        
        for(contact c : aaas)
        {
            aa.add(c.accountid);
            
            system.debug('account ids----'+ c);
        }
        
        
        
        map<id,account> hg =  new map<id,account>([select id,name,phone from account where id in : aa]);
        
        system.debug('account with id and records'+hg);
        for(contact c : aaas)
        {
            
            if(c.accountid == hg.get(c.accountid).id)
            {
                
                system.debug('matching id with accuont and contact'+hg);
                c.phone = hg.get(c.accountid).phone;
            }
            system.debug('assigning contact phone'+c.phone);
        }
    }
}

can anyone please tell me why null pointer exception displaying at line 23
Hi All,

I have written a trigger on contact update. In this trigger, wrote some if conditions to check somme conditions as below.. Here am confused that how to cover this if contions in test class. Below is my if conditions.

If(con.Lead__r.Sector__c=='Developer'&& acc.Rating__c!=null){
                flag = true;       
                If(Condition){
                    con.Lead__r.Rate__c = x%;
                }else if(condition){
                    con.Lead__r.Rate__c =y%;
               and so on.......
                }
            }

Please give me some sample code to cover this if condition..