function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Lakshmi SLakshmi S 

what type of errors or difficulties we are facing in apex code development?

Hi Team,

Q). What are the issues or errors we are facing at the time of writing  visualforce pages and apex classes?
Kindly reply to this post .......

Regards
Lakshmi
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Lakshmi, hope it will be helpful.

Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.

Thanks
Rahul Kumar
 
Lakshmi SLakshmi S
Hi Rahul,

Thanks for your reply.
Lakshmi SLakshmi S
Hi Rahul,

How to write test class for after or before delete trigger?
 
Rahul KumarRahul Kumar (Salesforce Developers) 
Hi Lakshmi,

Please check the sample Example 
@IsTest
private class Account_Trigger_Test 
{
	private static testMethod void testDelete()
	{
           Account acc=new Account(Name='Test Account;);
           insert acc;
 
           // should succeed
           delete acc.id;
        }

	private static testMethod void testDeleteFail()
	{
           Account acc=new Account(Name='Test Account',
                                   Client_ID__c='Should fail');
           insert acc;
 
           try
           {
              delete acc.id;
              // should throw an exception - the following assertion will cause an error if the code carries on
              System.assert(false);
           }
           catch (DMLException e)
           {
               // expected - could assert the message here
           }
        }
}

Please refer the below link for reference. hope it helps.

Please mark it as best answer if the information is informative.so that question is removed from an unanswered question and appear as a proper solution.

Thanks
Rahul Kumar
Lakshmi SLakshmi S
Hi Rahul,

Rollup Summary Trigger
trigger RolllupSummaryOppAmt on Opportunity (After insert, After update,After delete, After undelete) {
    if(checkRecursive.runOnce()){
    Set<Id> accid = new Set<Id>();
    Decimal avgamt;
    Decimal sumamt;
        Integer noopp;
    if(Trigger.isInsert || Trigger.isUpdate || Trigger.isUndelete){
        for(Opportunity opp : Trigger.New){
            if(opp.AccountId != null){
                accid.add(opp.AccountId);
            }
            
        }
    }
    
    if(Trigger.isDelete || Trigger.isUpdate){
        for(Opportunity op : Trigger.Old){
            if(op.AccountId != null){
                accid.add(op.AccountId);
            }
            
        }
    }
        
    List<Account> aclist = [select id,OppAvgAmount__c,SumOfOppAmt__c,NoOfOpp__c,(select id,amount from opportunities) from account where id In :accid];
    List<Account> upacc = new List<Account>();
    if(aclist.size()>0){
        for(Account ac : aclist){
           
            List<AggregateResult> aglist = [select count(id)t,avg(amount)agg,min(amount)sumamt from opportunity where accountid = :ac.id];
            for(AggregateResult ag : aglist){
                avgamt = (Decimal)ag.get('agg');
                sumamt = (Decimal)ag.get('sumamt');
                noopp = (Integer)ag.get('t');
                system.debug('---average---:'+avgamt);
            }
            ac.OppAvgAmount__c = avgamt;
            ac.SumOfOppAmt__c = sumamt;
            ac.NoOfOpp__c = noopp;
            upacc.add(ac);
        }
        
            update upacc;
       
    }

    }
}

Test Class 
@isTest
public class TestRollupSummaryOppAmt {
    public static testMethod void method1(){
        Account acc = new Account(name='abc');
        insert acc;
        Opportunity opp = new Opportunity(name='abcopp',accountid=acc.Id,amount=120,stagename='prospecting',closedate=date.newInstance(2017, 06, 30));
        insert opp;
        opp.amount=100;
        update opp;
        Opportunity opp2 = new Opportunity(name='abcopp2',accountid=acc.Id,amount=120,stagename='prospecting',closedate=date.newInstance(2017, 06, 30));
        insert opp2;
       
        
        Test.startTest();
        List<Opportunity> o = [select id from opportunity where accountid = :acc.Id limit 1];
        delete o;
        //delete opp;
        Test.stopTest();
    }
}

My test class covered only 88% code coverage.
How to cover 100% code coverage.


Thanks
Lakshmi​