• Vikas Menon
  • NEWBIE
  • 10 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 10
    Replies
Hi All,
Need Help !!... i have written a trigger which updates payments on change of status on account. Pasting code here. Somehow my test class does not give any coverage at all. Its urgent !


trigger :-
trigger CancelAdmission on Account(after update) 
{   
    // if(system.isFuture()) return;

    if(checkRecursive.ischeckcanceltrigger==true)
    {
        checkRecursive.ischeckcanceltrigger=false;
    }
    else
    {
        return;
    }
    
    Set<Id> accountIds = new Set<Id>();
    Set<Id> oppsIds = new Set<Id>();
  
    List<Lead>  reverselead = new list<Lead>();
    List<nmRefund_Payment__c> refund = new List<nmRefund_Payment__c>();
    String strEmailid;
   
    for(Account ac : Trigger.new)
    {
    system.debug('<-----------------nm_StudentStatus__c------------>'+ac.nm_StudentStatus__c);
         if(ac.nm_StudentStatus__c=='Admission Cancelled' || ac.nm_StudentStatus__c=='Registration Cancelled') 
         {
              accountIds.add(ac.Id);
         }
      system.debug('<--------------------------accountIds-------------->'+accountIds);       
    }
    if(accountIds.size()>0)
    {
         //List<Deduction_Amount__c> daupdate = new List<Deduction_Amount__c>();
          List<Opportunity> lstAppOpportuniyties = new List<Opportunity>();
          list<Opportunity> lstUpdate=new list<Opportunity>();
          list<nmRefund_Payment__c> lstRefundpayment=new list<nmRefund_Payment__c>();
          map<String,Opportunity> mapsemWise=new map<String,Opportunity>();
          lstAppOpportuniyties=[select id,Account.Is_Lateral_c__c,nm_InformationCenters__c,Account.PersonEmail,nm_Program__r.nm_Type__c,Amount,StageName,nm_Session__c,nm_Semester__c,nm_StudentSession__c,AccountId,Name,(select id,nm_ModeOfPayment__c,nm_Amount__c,nm_PaymentType__c,nm_PaymentStatus__c from Opportunities__r where (nm_PaymentType__c='Admission' OR nm_PaymentType__c='Late Fees')) from Opportunity where AccountId in: accountIds order by nm_Semester__c Desc];
          list<Opportunity> lstToUpdate=new list<Opportunity>();
          if(lstAppOpportuniyties.size()>0)
          {
             for(Opportunity objOpp:lstAppOpportuniyties)
             {
                mapsemWise.put(objOpp.nm_Semester__c,objOpp);
             }
          }
         
          strEmailid=lstAppOpportuniyties[0].Account.PersonEmail;
          
      if(lstAppOpportuniyties.size()>0)
      {
            Opportunity objopp=lstAppOpportuniyties[0];
            String StrSemister=lstAppOpportuniyties[0].nm_Semester__c;
            list<nm_Payment__c> lstPayment=new list<nm_Payment__c>();
            
           //Sem 1
              if((lstAppOpportuniyties[0].StageName=='Closed Won' || lstAppOpportuniyties[0].StageName =='Closed'))
            {
                
                Integer intTotalMountTorefund=0;
                
                String ModeofPaymentSem1;
                lstToUpdate.add(lstAppOpportuniyties[0]);
                integer intLatefees=0;
                if(lstToUpdate.size()>0)
                {
                    for(opportunity objOppGetAmountsem1:lstToUpdate)
                    {
                        for(nm_Payment__c objPayment:objOppGetAmountsem1.Opportunities__r)
                        {
                            if(objPayment.nm_PaymentType__c=='Admission' && (objPayment.nm_PaymentStatus__c=='Payment Made' || objPayment.nm_PaymentStatus__c=='Payment Approved'))
                            {
                                 ModeofPaymentSem1=objPayment.nm_ModeOfPayment__c;
                                 intTotalMountTorefund+=Integer.valueof(objPayment.nm_Amount__c);
                            }
                            if(objPayment.nm_PaymentType__c=='Late Fees' && (objPayment.nm_PaymentStatus__c=='Payment Made' || objPayment.nm_PaymentStatus__c=='Payment Approved'))
                            {
                                intLatefees+=Integer.valueof(objPayment.nm_Amount__c);
                            } 
                             
                        }
                    }
                }
               if(lstAppOpportuniyties[0].StageName=='Closed Won'){
                    nmRefund_Payment__c objRefundPayment=new nmRefund_Payment__c();
                    objRefundPayment.Total_Refund_Amount__c=intTotalMountTorefund;
                    objRefundPayment.nm_Payment_Status__c='Payment made';
                     // RP.nm_Amount__c=opp.nm_AmountReceived__c;
                    objRefundPayment.Account__c=lstAppOpportuniyties[0].Accountid;
                    objRefundPayment.Mode_Of_Payment__c=ModeofPaymentSem1;
                    //objRefundPayment.Additional_Deduction__c=2000;
                    objRefundPayment.nm_Information_Center__c=lstAppOpportuniyties[0].nm_InformationCenters__c;
                    lstRefundpayment.add(objRefundPayment);
               }
               //commented for closed cases
               if(lstAppOpportuniyties[0].StageName=='Closed'){
                    nmRefund_Payment__c objRefundPayment=new nmRefund_Payment__c();
                    objRefundPayment.Total_Refund_Amount__c=intTotalMountTorefund+intLatefees;
                    objRefundPayment.nm_Payment_Status__c='Payment made';
                     // RP.nm_Amount__c=opp.nm_AmountReceived__c;
                    objRefundPayment.Account__c=lstAppOpportuniyties[0].Accountid ;
                    objRefundPayment.Mode_Of_Payment__c=ModeofPaymentSem1;
                    //objRefundPayment.Additional_Deduction__c=0;
                    objRefundPayment.nm_Information_Center__c=lstAppOpportuniyties[0].nm_InformationCenters__c;
                    lstRefundpayment.add(objRefundPayment);
               }
               
                
            }
            
           if(lstToUpdate.size()>0)
           {
               for(Opportunity objOppUpdat:lstToUpdate)
               {
                    if(objOppUpdat.StageName=='Closed')
                    {
                       objOppUpdat.StageName='Registration Cancelled';
                    }
                    else
                    {
                        
                         objOppUpdat.StageName='Admission Cancelled';
                    }
               }
           }   
           update lstToUpdate;
       
            
        }
      if(strEmailid !=null && strEmailid !=''){
          list<lead> objLead=[select id from lead where Email=:strEmailid and isConverted=true];
           if(objLead.size()>0)
           {
               try{
                       delete objLead;
                  }
                 catch(Exception e)
                 {
                 
                 }
           }
      }
       set<id> stid=new set<id>();
        if(lstRefundpayment.size()>0)
        {
              insert lstRefundpayment;
              for(nmRefund_Payment__c objRfPay:lstRefundpayment)
              {
                  stid.add(objRfPay.id);
              }
              
        }
        if(accountIds.size()>0){
           CancelFutureHandler.CancelAdmission(accountIds,stid);
         }
          
    }
   }
<------------------------------------------------------------------------------------------------------------------------------------------------------------------------->
Test Class :-
@istest(SeeAllData=true)
public class CancelAdmissionTracker {

  Public static nm_Centers__c objCen;
   Public static User objUser;
    Public static nm_UserMapping__c objUserMap;
       Public static nm_Program__c objProgram;
       Public static nm_WorkExperience__c objWrkExp;
       public static nmRefund_Payment__c objRefundPayment; 
       public static Account objAccount;
       public static Opportunity opps;
 
  static testMethod  void testmethod1() 
    {   
      
        loadData();
        objAccount.nm_StudentStatus__c='Registration Cancelled'; ------> (the status does not get updated post inserting.)
        Test.StartTest();
        update objAccount;
        Test.StopTest();
        
    }
    
    static void loadData()
    {
    // List<Opportunity> lstOpps= new List<Opportunity>();
      List<nm_EligiblityCriteria__c> lstElegCritria= new List<nm_EligiblityCriteria__c>();
      List<Account> lstAcc1= new List<Account>();
      List<Lead>  lstLead = new List<Lead>();
      nm_EligiblityCriteria__c  objEC = new nm_EligiblityCriteria__c();
      CommonTrackerClass.createEligibiltyCriteria(objEC);
      lstElegCritria.add(objEC);
      System.debug('**eligibility'+objEC);
      nm_EligiblityCriteria__c  objEC1 = new nm_EligiblityCriteria__c();
      CommonTrackerClass.createEligibiltyCriteria(objEC1);
      lstElegCritria.add(objEC1);
              
   
        
        
      
         Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator']; 
        objUser = new User(Alias = 'newUser', Email='newuser@testorg.com', 
        EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
        LocaleSidKey='en_US', ProfileId = p.Id,
        TimeZoneSidKey='America/Los_Angeles', UserName='newuseoijior@testorg.com');
        insert objUser;    
        
        
      
         Recordtype RT=[select id from Recordtype where sobjectType='nm_Centers__c' AND name ='Information Center'];
         objCen= new nm_Centers__c();
         objCen.RecordTypeID = RT.id;         
         objCen.nm_CenterCode__c = '002';
         objCen.nm_CenterCity__c = 'Delhi';
         objCen.nm_City__c = 'Delhi';
         objCen.nm_StateProvince__c = 'Delhi';
         objCen.nm_Street__c = 'Krishna Nagar';
         objCen.nm_PostalCode__c = '110051';
        // objCen.Owner=objUser;
         
         insert objCen;
         
          objUserMap= new nm_UserMapping__c();
      objUserMap.nm_Centers__c=objCen.id;
      objUserMap.nm_User__c=objUser.id;
      objUserMap.nm_Phone__c='326392156';
      objUserMap.nm_Head__c= true;
      insert objUserMap;
      
        objAccount= new Account(); 
        objAccount.nm_PreStudentNo__c ='77213';
        objAccount.nm_StudentStatus__c='Confirmed';       
        objAccount.nm_SerialNo__c=2;
        objAccount.nm_IsDocumentApproved__c = true;
        objAccount.nm_Centers__c=objCen.id;        
        objAccount.lastname ='singh';
        objAccount.FirstName='Chandra';
        objAccount.nm_AccountEmail__c='chandra@gmail.com';
        objAccount.lastname ='kumar';
        objAccount.PersonMobilePhone='8377985721';
        objAccount.PersonEmail='chandra@gmail.com';
        objAccount.nm_EligiblityCriteria__c=objEC1.Id;
        objAccount.nmCaptureOpportuntiyStage__c='Registration Done';
        objAccount.ownerid = objUser.id;
        insert objAccount;

     }
}
 
Hi All,
i have been struggling with page rendering in the last few weeks. The requirement is that i have two buttons namely "Add experience" and "remove Experience". On the click of these buttons a set of fields is to be added to the visualforce page and removed from the visualforce page respectively.
Please suggest how can we remove a set of fields from the VF page on a click. Do we use <apex:para name field to render the page ?.

Thanks
Hi All,
Require urgent help. I have custom object of dispatch orders . I want to create a batch class which makes a DO based on the Opportunitie's which are have StageName="Closed Won". Please share a general format along with the cron string value which can initiate record creation every 15 mins.
i have a written a code but the record has failed. 

thanks
 
Hey Guys,

I am currently working on a module named Logistics where they manage distance education movement of Books across India. Hence this is to be tracked on SFDC
I have an object called Stock which is maintained at different places across india
So my query is :-

I have a Dispatch Order custom object ,based on which the stock at the respective centers is to be decremented 
based on the dispatch Order.

Eg Stock at -->A--->400
   Stock at---->B--->300

Dispatch order made 50 books from A to B
hence updated object value for 
A-->350
B--->350.

Please help me with the best way to go about this.
Cheers !!!
Hi All,
Need Help !!... i have written a trigger which updates payments on change of status on account. Pasting code here. Somehow my test class does not give any coverage at all. Its urgent !


trigger :-
trigger CancelAdmission on Account(after update) 
{   
    // if(system.isFuture()) return;

    if(checkRecursive.ischeckcanceltrigger==true)
    {
        checkRecursive.ischeckcanceltrigger=false;
    }
    else
    {
        return;
    }
    
    Set<Id> accountIds = new Set<Id>();
    Set<Id> oppsIds = new Set<Id>();
  
    List<Lead>  reverselead = new list<Lead>();
    List<nmRefund_Payment__c> refund = new List<nmRefund_Payment__c>();
    String strEmailid;
   
    for(Account ac : Trigger.new)
    {
    system.debug('<-----------------nm_StudentStatus__c------------>'+ac.nm_StudentStatus__c);
         if(ac.nm_StudentStatus__c=='Admission Cancelled' || ac.nm_StudentStatus__c=='Registration Cancelled') 
         {
              accountIds.add(ac.Id);
         }
      system.debug('<--------------------------accountIds-------------->'+accountIds);       
    }
    if(accountIds.size()>0)
    {
         //List<Deduction_Amount__c> daupdate = new List<Deduction_Amount__c>();
          List<Opportunity> lstAppOpportuniyties = new List<Opportunity>();
          list<Opportunity> lstUpdate=new list<Opportunity>();
          list<nmRefund_Payment__c> lstRefundpayment=new list<nmRefund_Payment__c>();
          map<String,Opportunity> mapsemWise=new map<String,Opportunity>();
          lstAppOpportuniyties=[select id,Account.Is_Lateral_c__c,nm_InformationCenters__c,Account.PersonEmail,nm_Program__r.nm_Type__c,Amount,StageName,nm_Session__c,nm_Semester__c,nm_StudentSession__c,AccountId,Name,(select id,nm_ModeOfPayment__c,nm_Amount__c,nm_PaymentType__c,nm_PaymentStatus__c from Opportunities__r where (nm_PaymentType__c='Admission' OR nm_PaymentType__c='Late Fees')) from Opportunity where AccountId in: accountIds order by nm_Semester__c Desc];
          list<Opportunity> lstToUpdate=new list<Opportunity>();
          if(lstAppOpportuniyties.size()>0)
          {
             for(Opportunity objOpp:lstAppOpportuniyties)
             {
                mapsemWise.put(objOpp.nm_Semester__c,objOpp);
             }
          }
         
          strEmailid=lstAppOpportuniyties[0].Account.PersonEmail;
          
      if(lstAppOpportuniyties.size()>0)
      {
            Opportunity objopp=lstAppOpportuniyties[0];
            String StrSemister=lstAppOpportuniyties[0].nm_Semester__c;
            list<nm_Payment__c> lstPayment=new list<nm_Payment__c>();
            
           //Sem 1
              if((lstAppOpportuniyties[0].StageName=='Closed Won' || lstAppOpportuniyties[0].StageName =='Closed'))
            {
                
                Integer intTotalMountTorefund=0;
                
                String ModeofPaymentSem1;
                lstToUpdate.add(lstAppOpportuniyties[0]);
                integer intLatefees=0;
                if(lstToUpdate.size()>0)
                {
                    for(opportunity objOppGetAmountsem1:lstToUpdate)
                    {
                        for(nm_Payment__c objPayment:objOppGetAmountsem1.Opportunities__r)
                        {
                            if(objPayment.nm_PaymentType__c=='Admission' && (objPayment.nm_PaymentStatus__c=='Payment Made' || objPayment.nm_PaymentStatus__c=='Payment Approved'))
                            {
                                 ModeofPaymentSem1=objPayment.nm_ModeOfPayment__c;
                                 intTotalMountTorefund+=Integer.valueof(objPayment.nm_Amount__c);
                            }
                            if(objPayment.nm_PaymentType__c=='Late Fees' && (objPayment.nm_PaymentStatus__c=='Payment Made' || objPayment.nm_PaymentStatus__c=='Payment Approved'))
                            {
                                intLatefees+=Integer.valueof(objPayment.nm_Amount__c);
                            } 
                             
                        }
                    }
                }
               if(lstAppOpportuniyties[0].StageName=='Closed Won'){
                    nmRefund_Payment__c objRefundPayment=new nmRefund_Payment__c();
                    objRefundPayment.Total_Refund_Amount__c=intTotalMountTorefund;
                    objRefundPayment.nm_Payment_Status__c='Payment made';
                     // RP.nm_Amount__c=opp.nm_AmountReceived__c;
                    objRefundPayment.Account__c=lstAppOpportuniyties[0].Accountid;
                    objRefundPayment.Mode_Of_Payment__c=ModeofPaymentSem1;
                    //objRefundPayment.Additional_Deduction__c=2000;
                    objRefundPayment.nm_Information_Center__c=lstAppOpportuniyties[0].nm_InformationCenters__c;
                    lstRefundpayment.add(objRefundPayment);
               }
               //commented for closed cases
               if(lstAppOpportuniyties[0].StageName=='Closed'){
                    nmRefund_Payment__c objRefundPayment=new nmRefund_Payment__c();
                    objRefundPayment.Total_Refund_Amount__c=intTotalMountTorefund+intLatefees;
                    objRefundPayment.nm_Payment_Status__c='Payment made';
                     // RP.nm_Amount__c=opp.nm_AmountReceived__c;
                    objRefundPayment.Account__c=lstAppOpportuniyties[0].Accountid ;
                    objRefundPayment.Mode_Of_Payment__c=ModeofPaymentSem1;
                    //objRefundPayment.Additional_Deduction__c=0;
                    objRefundPayment.nm_Information_Center__c=lstAppOpportuniyties[0].nm_InformationCenters__c;
                    lstRefundpayment.add(objRefundPayment);
               }
               
                
            }
            
           if(lstToUpdate.size()>0)
           {
               for(Opportunity objOppUpdat:lstToUpdate)
               {
                    if(objOppUpdat.StageName=='Closed')
                    {
                       objOppUpdat.StageName='Registration Cancelled';
                    }
                    else
                    {
                        
                         objOppUpdat.StageName='Admission Cancelled';
                    }
               }
           }   
           update lstToUpdate;
       
            
        }
      if(strEmailid !=null && strEmailid !=''){
          list<lead> objLead=[select id from lead where Email=:strEmailid and isConverted=true];
           if(objLead.size()>0)
           {
               try{
                       delete objLead;
                  }
                 catch(Exception e)
                 {
                 
                 }
           }
      }
       set<id> stid=new set<id>();
        if(lstRefundpayment.size()>0)
        {
              insert lstRefundpayment;
              for(nmRefund_Payment__c objRfPay:lstRefundpayment)
              {
                  stid.add(objRfPay.id);
              }
              
        }
        if(accountIds.size()>0){
           CancelFutureHandler.CancelAdmission(accountIds,stid);
         }
          
    }
   }
<------------------------------------------------------------------------------------------------------------------------------------------------------------------------->
Test Class :-
@istest(SeeAllData=true)
public class CancelAdmissionTracker {

  Public static nm_Centers__c objCen;
   Public static User objUser;
    Public static nm_UserMapping__c objUserMap;
       Public static nm_Program__c objProgram;
       Public static nm_WorkExperience__c objWrkExp;
       public static nmRefund_Payment__c objRefundPayment; 
       public static Account objAccount;
       public static Opportunity opps;
 
  static testMethod  void testmethod1() 
    {   
      
        loadData();
        objAccount.nm_StudentStatus__c='Registration Cancelled'; ------> (the status does not get updated post inserting.)
        Test.StartTest();
        update objAccount;
        Test.StopTest();
        
    }
    
    static void loadData()
    {
    // List<Opportunity> lstOpps= new List<Opportunity>();
      List<nm_EligiblityCriteria__c> lstElegCritria= new List<nm_EligiblityCriteria__c>();
      List<Account> lstAcc1= new List<Account>();
      List<Lead>  lstLead = new List<Lead>();
      nm_EligiblityCriteria__c  objEC = new nm_EligiblityCriteria__c();
      CommonTrackerClass.createEligibiltyCriteria(objEC);
      lstElegCritria.add(objEC);
      System.debug('**eligibility'+objEC);
      nm_EligiblityCriteria__c  objEC1 = new nm_EligiblityCriteria__c();
      CommonTrackerClass.createEligibiltyCriteria(objEC1);
      lstElegCritria.add(objEC1);
              
   
        
        
      
         Profile p = [SELECT Id FROM Profile WHERE Name='System Administrator']; 
        objUser = new User(Alias = 'newUser', Email='newuser@testorg.com', 
        EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US', 
        LocaleSidKey='en_US', ProfileId = p.Id,
        TimeZoneSidKey='America/Los_Angeles', UserName='newuseoijior@testorg.com');
        insert objUser;    
        
        
      
         Recordtype RT=[select id from Recordtype where sobjectType='nm_Centers__c' AND name ='Information Center'];
         objCen= new nm_Centers__c();
         objCen.RecordTypeID = RT.id;         
         objCen.nm_CenterCode__c = '002';
         objCen.nm_CenterCity__c = 'Delhi';
         objCen.nm_City__c = 'Delhi';
         objCen.nm_StateProvince__c = 'Delhi';
         objCen.nm_Street__c = 'Krishna Nagar';
         objCen.nm_PostalCode__c = '110051';
        // objCen.Owner=objUser;
         
         insert objCen;
         
          objUserMap= new nm_UserMapping__c();
      objUserMap.nm_Centers__c=objCen.id;
      objUserMap.nm_User__c=objUser.id;
      objUserMap.nm_Phone__c='326392156';
      objUserMap.nm_Head__c= true;
      insert objUserMap;
      
        objAccount= new Account(); 
        objAccount.nm_PreStudentNo__c ='77213';
        objAccount.nm_StudentStatus__c='Confirmed';       
        objAccount.nm_SerialNo__c=2;
        objAccount.nm_IsDocumentApproved__c = true;
        objAccount.nm_Centers__c=objCen.id;        
        objAccount.lastname ='singh';
        objAccount.FirstName='Chandra';
        objAccount.nm_AccountEmail__c='chandra@gmail.com';
        objAccount.lastname ='kumar';
        objAccount.PersonMobilePhone='8377985721';
        objAccount.PersonEmail='chandra@gmail.com';
        objAccount.nm_EligiblityCriteria__c=objEC1.Id;
        objAccount.nmCaptureOpportuntiyStage__c='Registration Done';
        objAccount.ownerid = objUser.id;
        insert objAccount;

     }
}
 
Hi All,
i have been struggling with page rendering in the last few weeks. The requirement is that i have two buttons namely "Add experience" and "remove Experience". On the click of these buttons a set of fields is to be added to the visualforce page and removed from the visualforce page respectively.
Please suggest how can we remove a set of fields from the VF page on a click. Do we use <apex:para name field to render the page ?.

Thanks
Hi All,
Require urgent help. I have custom object of dispatch orders . I want to create a batch class which makes a DO based on the Opportunitie's which are have StageName="Closed Won". Please share a general format along with the cron string value which can initiate record creation every 15 mins.
i have a written a code but the record has failed. 

thanks
 
Hey Guys,

I am currently working on a module named Logistics where they manage distance education movement of Books across India. Hence this is to be tracked on SFDC
I have an object called Stock which is maintained at different places across india
So my query is :-

I have a Dispatch Order custom object ,based on which the stock at the respective centers is to be decremented 
based on the dispatch Order.

Eg Stock at -->A--->400
   Stock at---->B--->300

Dispatch order made 50 books from A to B
hence updated object value for 
A-->350
B--->350.

Please help me with the best way to go about this.
Cheers !!!