• Revati Bhavsar
  • NEWBIE
  • 0 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 17
    Replies
I've created an Inactive custom field on account. When the “Inactive” check box is checked and saved on the Account,  the Account’s name should be renamed by conacatenating '###Inactive###'  in front of its name. E.g Account Acme Inc. should get renamed to ###Inactive### Acme Inc. I have written an apex class method for it and that method is called in trigger. But it is not getting executed as the account name field is read only and not editable. Following is the apex code and trigger.
public Class AP_Accounts {
    
    
    public static void RenameAcc(List<Account> lstAcc)
    {
        for(Account acc : lstAcc) 
        {                 
               if(acc.Inactive__c == True)
               {
               
                    String accName = '##Inactive##';
                    accName +=acc.Name;                      
                    acc.Name = accName;
      
            }  
            System.Debug('Account name'+acc.name);

        }             
        
        try {
            UPDATE lstAcc;
        }
        catch(Exception e) {
        }
    }
}

Apex Trigger:
rigger AccountBeforeInsert on Account (before insert, before update,after insert, after update) {
    List<Account> lstAcc = new List<Account>();
    
    if(Trigger.isAfter)
    {
       if (Trigger.isInsert) 
       {

            AP_Accounts.RenameAcc(Trigger.new);

       }

      }    
}

 
Hi,
How to create a note automatically, if a user changes the Shipping or billing address of an Account, which logs this activity, and stores the old value of the Address?
 
Hello,
        Below is my trigger which runs before insert before update.Can anyone help me in writing a test class for it?

trigger appTrigger on Applicant__c (before insert,before update){

    public CustBusinessPro__Criteria__c Criteria {get;set;}
    public List < CustBusinessPro__Criteria__c > criteriaList {get;set;}
     boolean status;
   CustBusinessPro__Applicant__c app1;



   
    boolean outerBreak = false;
 
    String test;
    criteriaList=new LIST<CustBusinessPro__Criteria__c>([SELECT Id,Name,CustBusinessPro__Operations__c,CustBusinessPro__Where_Clause__c,CustBusinessPro__Loan_Type__c FROM CustBusinessPro__Criteria__c] );
    
    for(CustBusinessPro__Criteria__c cd: criteriaList){
         if(outerBreak) break;
        
            for(CustBusinessPro__Applicant__c app:Trigger.new){
            
     if(app.CustBusinessPro__Type_of_Loan__c==cd.CustBusinessPro__Loan_Type__c)
         {
            // System.debug('>>>>>>>>>>>>>>>>>'+ cd.CustBusinessPro__Where_Clause__c);
            test=cd.CustBusinessPro__Where_Clause__c;
            test=test.replaceAll('AND','&&');
            test=test.replaceAll('OR','||');

            test=test.replaceAll('CustBusinessPro__Age__c',String.valueOf(app.CustBusinessPro__Age__c));
            test=test.replaceAll('CustBusinessPro__Gender__c ','\'' + app.CustBusinessPro__Gender__c  + '\'');
            test=test.replaceAll('CustBusinessPro__Country__c','\'' + app.CustBusinessPro__Country__c + '\'');
            test=test.replaceAll('CustBusinessPro__City__c','\'' + app.CustBusinessPro__City__c + '\'');
            test=test.replaceAll('CustBusinessPro__Salary__c',String.valueOf(app.CustBusinessPro__Salary__c));
            test=test.replaceAll('CustBusinessPro__Marital_Status__c','\'' + app.CustBusinessPro__Marital_Status__c + '\'');
           
           
        
          
           Boolean b=EvaluateString.evaluateStringToBoolean(test);
            System.debug('>>>>>>>>>>>>>>>>> string is'+ test+'---------------bValue'+b);
            if(b)
            {  
               Boolean result1,result2,result3,result6;
               Boolean flag=true; 
               Decimal result4,result5;
              System.debug('Criteria satisfied'+cd);
              System.debug('operations----'+cd.CustBusinessPro__Operations__c);
              String[] operations=cd.CustBusinessPro__Operations__c.split(',');
              System.debug('splitted operations>>>>'+operations);
              for(String str:operations)
              { 
                
                  if(str == 'PAN_Check')
                 { system.debug('inside  pan');
                   PAN_Check pan = new PAN_Check();
                   result1=pan.PanCheck(app.CustBusinessPro__PAN__c,app.CustBusinessPro__Last_Name__c);
                  system.debug('>>>>>>>>returned value resultPan'+result1);
                  if(result1==false)
                  {flag=false;
                   break;}
                 }
                 else if(str == 'De_Dup')
                 {
                    system.debug('inside de_dup');
                    De_Dup d = new De_Dup();
                    result2=d.DeDup(app.CustBusinessPro__PAN__c,app.CustBusinessPro__Type_of_Loan__c);
                    system.debug('>>>>>>>>returned value resultDeDUP'+result2);
                    if(result2==false)
                {flag=false;
                   break;}
                 }
                 else if(str == 'CIBIL Verification')
                 {
                  system.debug('inside cibil');
                  CIBILVerification cibil=new CIBILVerification();
                  result3=cibil.CIBILCheck(app.CustBusinessPro__CIBIL_Score__c);
                   system.debug('>>>>>>>>returned value resultCibil'+result3);
                  if(result3==false)
                  {flag=false;
                   break;}
                 }
                 else if(str == 'Eligibility Verification')
                 {
                 system.debug('inside eligibilty');
                 EligibilityVerification elig=new EligibilityVerification();
                 result4=elig.EligibilityCheck(app.CustBusinessPro__Salary__c,app.CustBusinessPro__Type_of_Loan__c,app.CustBusinessPro__Loan_Amount__c);
                 system.debug('>>>>>>>>returned value resultElig'+result4);
                 }
                 else if(str == 'EMI Verification')
                 {
                    system.debug('inside EMI');
                    EMI_Calculation emi = new  EMI_Calculation();
                   result5= emi.EMICalculation(app.CustBusinessPro__Loan_Amount__c,app.CustBusinessPro__Loan_Tenure__c);
                   system.debug('>>>>>>>>returned value resultEMI'+result5);
                 }
                 else if(str == 'NegativeAreaCheck')
                 {
                   system.debug('inside NAC');
                   NegativeAreaCheck NAC = new NegativeAreaCheck();
                   result6=NAC.PincodeCheck(app.CustBusinessPro__Postal_Code__c);
                   system.debug('>>>>>>>>returned value resultNAC'+result6);
                  if(result6==false)
                  {flag=false;
                   break;}
                 }
              }
              //app1 = [Select CustBusinessPro__Sucess_Msg__c from CustBusinessPro__Applicant__c  where id=: app.id];
                if(flag==false)
                {  System.debug('-----operations terminated');
                  // app.addError('The loan could not be granted!');
                  app.CustBusinessPro__Sucess_Msg__c = 'Fail';
                   status=false;
                    outerBreak = true;
                   break;
                }
                if(flag==true)
                  app.CustBusinessPro__Sucess_Msg__c = 'Pass';
            }
            else
            {
              System.debug('Criteria not satisfied');
             // app.addError('The loan could not be granted.');
             app.CustBusinessPro__Sucess_Msg__c = 'Fail';
              status=false;
            }
    }
   else{ break;}
}

}
if(outerbreak){
 status=false;  
 system.debug('-----all out');
}
else{
status=true;

}

}
Thanks in advance!!
I have created an apex class for EMI_calculation to estimate EMI for a particular loan applicant and it is stored in variable EMI. I want to display this
EMI value on visualforce page "Applicant" with different controller class after saving th applicant page.
Following is the EMI_Calculation class:
public with sharing class EMI_Calculation
{
  public CustBusinessPro__Applicant__c applicant{get;set;}
  public Decimal RateOfInterest{get;set;}
  public Decimal EMI{get;set;}
  
  
  public void EMICalculation(Decimal Principal, Decimal Period)
  {
    applicant = new CustBusinessPro__Applicant__c();
    RateOfInterest = 12.5/1200;
    System.debug('----------' + Principal);
    
    System.debug('----------' + Period);
    Period=Period*12.0;
    Integer myInt = Integer.valueOf(Period);
    Decimal nr = (1+RateOfInterest);
    
    Decimal powDec = nr.pow(myInt);
    EMI= (Principal*RateOfInterest*powDec)/(powDec-1);
    System.debug('-------------' + EMI + 'Rs');
    
  }
}

 
I have a custom object with API name CustBusinessPro__Applicant__c.Its field is CustBusinessPro__PAN__c.My code to access this field is:
public with sharing class PAN_Check

{

    public CustBusinessPro__Applicant__c applicant{get;set;}

    List <String> panCardList{get;set;}

    String PanFormat{get;set;}

    public PAN_Check()

    {

        applicant = new CustBusinessPro__Applicant__c();

        panCardList = new List<String> ();

        PanFormat = '[A-Z]{5}[0-9]{4}[A-Z]{1}';

    }

     

    public void PanCheck()

    {
        panCardList.add(applicant.CustBusinessPro__PAN__c);
        System.debug('----------------------' + panCardList);
Getting an error that  variable applicant.CustBusinessPro__PAN__c does not exist.Can anyone help?

Thanks in advance!!
Here is my Apex class for matching the Pan number format with user entered pan number.Getting an error how should I correct it?
public with sharing class PAN_Check
{
  public CustBusinessPro__Applicant__c applicant{get;set;}
  // List<CustBusinessPro__Applicant__c> panCardList;
  List <String> panCardList{get;set;}
  List <String> PanFormat{get;set;}
  public PAN_Check()
  {
    applicant = new CustBusinessPro__Applicant__c();
    panCardList = new List<String> ();
    PanFormat = new List<String> {'[A-Z]{5}[0-9]{4}[A-Z]{1}'} ;
  }
  
  public void PanCheck()
  {
   // panCardList = new List<CustBusinessPro__Applicant__c> ();
   // panCardList = [SELECT Id,CustBusinessPro__PAN__c FROM CustBusinessPro__Applicant__c WHERE Id =: ApexPages.currentPage().getParameters().get('id')];
      panCardList.add(applicant.CustBusinessPro__PAN__c);
    System.debug('----------------------' + panCardList);
    pattern MyPattern = pattern.compile(PanFormat);
    matcher MyMatcher = MyPattern.matcher(panCardList);
    if(MyMatcher.matches())
    {
      System.debug(panCardList + '---------------Valid');
    }
    else
    {
      System.debug(panCardList + '---------------Invalid');
    }
  }
}


Error:

Error: Compile Error: Method does not exist or incorrect signature: pattern.compile(List<String>) at line 20 column 25
I am writing a class to do pattern matching for checking whether the user entered pan number is valid or not.This pan number is a field of a custom object.Please help me how should I fetch this object and perform pattern matching.

Thanks in advance!!!
I've created an Inactive custom field on account. When the “Inactive” check box is checked and saved on the Account,  the Account’s name should be renamed by conacatenating '###Inactive###'  in front of its name. E.g Account Acme Inc. should get renamed to ###Inactive### Acme Inc. I have written an apex class method for it and that method is called in trigger. But it is not getting executed as the account name field is read only and not editable. Following is the apex code and trigger.
public Class AP_Accounts {
    
    
    public static void RenameAcc(List<Account> lstAcc)
    {
        for(Account acc : lstAcc) 
        {                 
               if(acc.Inactive__c == True)
               {
               
                    String accName = '##Inactive##';
                    accName +=acc.Name;                      
                    acc.Name = accName;
      
            }  
            System.Debug('Account name'+acc.name);

        }             
        
        try {
            UPDATE lstAcc;
        }
        catch(Exception e) {
        }
    }
}

Apex Trigger:
rigger AccountBeforeInsert on Account (before insert, before update,after insert, after update) {
    List<Account> lstAcc = new List<Account>();
    
    if(Trigger.isAfter)
    {
       if (Trigger.isInsert) 
       {

            AP_Accounts.RenameAcc(Trigger.new);

       }

      }    
}

 
I have created an apex class for EMI_calculation to estimate EMI for a particular loan applicant and it is stored in variable EMI. I want to display this
EMI value on visualforce page "Applicant" with different controller class after saving th applicant page.
Following is the EMI_Calculation class:
public with sharing class EMI_Calculation
{
  public CustBusinessPro__Applicant__c applicant{get;set;}
  public Decimal RateOfInterest{get;set;}
  public Decimal EMI{get;set;}
  
  
  public void EMICalculation(Decimal Principal, Decimal Period)
  {
    applicant = new CustBusinessPro__Applicant__c();
    RateOfInterest = 12.5/1200;
    System.debug('----------' + Principal);
    
    System.debug('----------' + Period);
    Period=Period*12.0;
    Integer myInt = Integer.valueOf(Period);
    Decimal nr = (1+RateOfInterest);
    
    Decimal powDec = nr.pow(myInt);
    EMI= (Principal*RateOfInterest*powDec)/(powDec-1);
    System.debug('-------------' + EMI + 'Rs');
    
  }
}

 
I have a custom object with API name CustBusinessPro__Applicant__c.Its field is CustBusinessPro__PAN__c.My code to access this field is:
public with sharing class PAN_Check

{

    public CustBusinessPro__Applicant__c applicant{get;set;}

    List <String> panCardList{get;set;}

    String PanFormat{get;set;}

    public PAN_Check()

    {

        applicant = new CustBusinessPro__Applicant__c();

        panCardList = new List<String> ();

        PanFormat = '[A-Z]{5}[0-9]{4}[A-Z]{1}';

    }

     

    public void PanCheck()

    {
        panCardList.add(applicant.CustBusinessPro__PAN__c);
        System.debug('----------------------' + panCardList);
Getting an error that  variable applicant.CustBusinessPro__PAN__c does not exist.Can anyone help?

Thanks in advance!!
Here is my Apex class for matching the Pan number format with user entered pan number.Getting an error how should I correct it?
public with sharing class PAN_Check
{
  public CustBusinessPro__Applicant__c applicant{get;set;}
  // List<CustBusinessPro__Applicant__c> panCardList;
  List <String> panCardList{get;set;}
  List <String> PanFormat{get;set;}
  public PAN_Check()
  {
    applicant = new CustBusinessPro__Applicant__c();
    panCardList = new List<String> ();
    PanFormat = new List<String> {'[A-Z]{5}[0-9]{4}[A-Z]{1}'} ;
  }
  
  public void PanCheck()
  {
   // panCardList = new List<CustBusinessPro__Applicant__c> ();
   // panCardList = [SELECT Id,CustBusinessPro__PAN__c FROM CustBusinessPro__Applicant__c WHERE Id =: ApexPages.currentPage().getParameters().get('id')];
      panCardList.add(applicant.CustBusinessPro__PAN__c);
    System.debug('----------------------' + panCardList);
    pattern MyPattern = pattern.compile(PanFormat);
    matcher MyMatcher = MyPattern.matcher(panCardList);
    if(MyMatcher.matches())
    {
      System.debug(panCardList + '---------------Valid');
    }
    else
    {
      System.debug(panCardList + '---------------Invalid');
    }
  }
}


Error:

Error: Compile Error: Method does not exist or incorrect signature: pattern.compile(List<String>) at line 20 column 25

Hi All,

 

I want to get all fieldnames of a object in apex. How can I do this?

 

For example for User object I want to get all its field names like AboutMe, AccountId , Email etc.

 

Any help on this really appreciated.

 

Regards,

Naren

  • January 18, 2012
  • Like
  • 0

Hi All, I have met a problem and have no idea how to handle it. Here is the situation: I need to write a SOQL sentence like "SELECT field1 FROM object1" but in my case I don't know the value of fields1 in the first place. There is a string to hold the value. How can write the SOQL sentence to use this string value. Thanks