• Sanu Verma
  • NEWBIE
  • 30 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 4
    Replies
Hi,
My Scenarios is to convert each field value into CM and then display on vf page. To achieve this i created a sObject list and fetch every field into String and then do Converting Cm Operation.

here is the code:-
string query = '';
                query = 'Select ' + String.join(sObjectFieldsList, ',') + ' From Measurement__c WHERE Huntsman_Order__c = :hOrderId and Client__c = :clientId ORDER BY CreatedDate DESC';
                List<Measurement__c> measurementList = Database.query(query);

if(productionType == 'LDC'){                      
                        String NeckStr = measurementList[0].Neck_Shirt__c;
                        String RSlopeStr = measurementList[0].R_Slope_Shirt__c;
                        String FrontlengthStr = measurementList[0].Front_Length_Shirt__c;
                        String LSlopeStr = measurementList[0].L_Slope_Shirt__c;
                        String BackLengthStr = measurementList[0].Back_Length_Shirt__c;
                        String PTPStr = measurementList[0].Point_to_Point_Shirt__c;
                        String ChestStr = measurementList[0].Chest_Shirt__c;
                        String ChestAllownaceStr = measurementList[0].Chest_Allowance_Shirt__c;
                        String RSleeveStr = measurementList[0].R_Sleeve_Shirt__c;
                        String WaistStr = measurementList[0].Waist_Shirt__c;
                        String WaistAllowanceStr = measurementList[0].Waist_Allowance_Shirt__c;
                        String LSleeveStr = measurementList[0].L_Sleeve_Shirt__c;
                        String SeatStr = measurementList[0].Seat_Shirt__c;
                        String SeatAllowanceStr = measurementList[0].Seat_Allowance_Shirt__c;
                        String RCuffStr = measurementList[0].R_Wrist_Shirt__c;
                        String LBicepsStr = measurementList[0].L_Bicep_Shirt__c;
                        String RBicepsStr = measurementList[0].R_Bicep_Shirt__c;
                        String LCuffStr = measurementList[0].L_Wrist_Shirt__c;
                        
                        if(String.valueOf(measurementList[0].Neck_Shirt__c).trim().contains(' ')){
                           List<String> filterLogicSplittedbySpace = neckStr.split(' ');
                            if(filterLogicSplittedbySpace[1] != null && filterLogicSplittedbySpace[1].contains('/')){
                                List<String> splitBySlash = filterLogicSplittedbySpace[1].split('/');
                                Decimal val = (Decimal.valueOf(filterLogicSplittedbySpace[0])+(Decimal.valueOf(splitBySlash[0]) / Decimal.valueOf(splitBySlash[1]))) * 2.54; 
                                measurementList[0].Neck_Shirt__c = String.valueOf(val);
                                
                            }
                        } else {
                                Decimal val = (Decimal.valueOf(neckStr)) * 2.54; 
                                measurementList[0].Neck_Shirt__c = String.valueOf(val);
                        }
                        if(String.valueOf(measurementList[0].R_Slope_Shirt__c).trim().contains(' ')){
                           List<String> filterLogicSplittedbySpace = RSlopeStr.split(' ');
                            if(filterLogicSplittedbySpace[1] != null && filterLogicSplittedbySpace[1].contains('/')){
                                List<String> splitBySlash = filterLogicSplittedbySpace[1].split('/');
                                Decimal val = (Decimal.valueOf(filterLogicSplittedbySpace[0])+(Decimal.valueOf(splitBySlash[0]) / Decimal.valueOf(splitBySlash[1]))) * 2.54; 
                                measurementList[0].R_Slope_Shirt__c = String.valueOf(val);
                                
                            } 
                        } else {
                                Decimal val = (Decimal.valueOf(RSlopeStr)) * 2.54; 
                                measurementList[0].R_Slope_Shirt__c = String.valueOf(val);
                        }
                        if(String.valueOf(measurementList[0].Front_Length_Shirt__c).trim().contains(' ')){
                           List<String> filterLogicSplittedbySpace = FrontlengthStr.split(' ');
                            if(filterLogicSplittedbySpace[1] != null && filterLogicSplittedbySpace[1].contains('/')){
                                List<String> splitBySlash = filterLogicSplittedbySpace[1].split('/');
                                Decimal val = (Decimal.valueOf(filterLogicSplittedbySpace[0])+(Decimal.valueOf(splitBySlash[0]) / Decimal.valueOf(splitBySlash[1]))) * 2.54; 
                                measurementList[0].Front_Length_Shirt__c = String.valueOf(val);
                                
                            } 
                        } else {
                                Decimal val = (Decimal.valueOf(FrontlengthStr)) * 2.54; 
                                measurementList[0].Front_Length_Shirt__c = String.valueOf(val);
                        }
                        if(String.valueOf(measurementList[0].L_Slope_Shirt__c).trim().contains(' ')){
                           List<String> filterLogicSplittedbySpace = LSlopeStr.split(' ');
                            if(filterLogicSplittedbySpace[1] != null && filterLogicSplittedbySpace[1].contains('/')){
                                List<String> splitBySlash = filterLogicSplittedbySpace[1].split('/');
                                Decimal val = (Decimal.valueOf(filterLogicSplittedbySpace[0])+(Decimal.valueOf(splitBySlash[0]) / Decimal.valueOf(splitBySlash[1]))) * 2.54; 
                                measurementList[0].L_Slope_Shirt__c = String.valueOf(val);
                                
                            } 
                            
                        } else {
                                Decimal val = (Decimal.valueOf(LSlopeStr)) * 2.54; 
                                measurementList[0].L_Slope_Shirt__c = String.valueOf(val);
                        }

and so on. So in 1st part of Code you see i fetch every field and Store in string and then do operation. So is there a way to do it dynamically? 
I have an input text field on vf page where i called custom picklist value. But want to restrict some value on condition. means want to hide some value on condition. but not able to do so.
here is my code:-
<div class="slds-form-element slds-m-around_x-small">
                                            <label class="slds-form-element__label " style="font-size: 14px;font-weight: 600;">Payment Method:&nbsp;</label>
                                            <div class="slds-form-element__control">
                                                <apex:inputField styleClass="slds-select optionPaymentMethod" value="{!tempOpportunity.Payment_Method__c}" id = "pmethod" >
                                                    <apex:actionSupport event="onchange" action="{!dummyCall}" rerender="pnlManualPaymentMethod" />
                                                </apex:inputField>
                                                <!--<apex:selectList value="{!tempOpportunity.Payment_Method__c}" size="1" >-->
                                                <!--    <apex:selectOptions value="{!methodSelectOptionList}"/>-->
                                                <!--</apex:selectList>-->
                                            </div>
                                        </div>

and the other one
 
function showPaymentMethod() {
                          var methodType = document.querySelectorAll('[id$ = "pmethod"]') [0];
                          if(tempOpportunity.AccountId == null){
                                for(var i = 0; i < methodType.length; i++) {
                                    if(methodType.options[i].value == 'Wallet'){
                                     methodType.hide(i);
                                  }
                          }
                                    
                         }
                         return false;
On my VF page, I called standard multiple picklist fields like this way
<td><apex:inputfield value="{!order.Coat_TIC_PKT__c}" styleClass="testInput"/></td>

it's showing properly on desktop mode, but not showing properly on tab mode.

this one is the desktop mode view:- 
User-added imageand this one is the tab mode view:- 
User-added image

i want to show in tab as same as desktop
  I want to make it enable. Can anyone suggest me how do I do that?
User-added image
I created a Vf Page and their is a Custom object in which pdf is attached. I want to show that Pdf In my Vf page form Section.Can anyone suugest me how do i approach with that. pleaze do not put any link in comment section. i want example which make me easy to proceed.

Thanks.
I want to Decrypt the password of Contact portal. But In my Code Unrecognized based 64 :* error. i did that things 1st tym thts why didnt understand what is the main problem. maybe my code is wrong or somethings else. plzz help me out...

this is my code which i tried to decrypt the password field
static void decryptPass(){
        List<Customer_Community_Details__c> portal=new List<Customer_Community_Details__c>([SELECT Id, Password1__c From Customer_Community_Details__c]);
        List<User> users=[SELECT Id, Name ,UserRole.Name FROM User WHERE UserRole.Name = 'Sales Support' OR UserRole.Name = 'Customer Support'];
        
        for(Customer_Community_Details__c portals : portal)
        {
        if(users !=Null){
           Blob cryptoKey = Crypto.generateAesKey(256);
           Blob data = EncodingUtil.base64Decode(portals.Password1__c);
           Blob decryptedData = Crypto.decryptWithManagedIV('AES128', cryptoKey , data);
           String dryptData = decryptedData.toString();
            
           System.debug('Printing dryptData '+dryptData);
            portals.Password1__c=dryptData;
            
        }
        }
        
        
    }

 
 
Want to Write CronJobDetail Test class
public void abortCronJob(){
            List<CronJobDetail> detailIds = new List<CronJobDetail>([Select Id From CronJobDetail where Name ='ScheduleBatchPaymentDaysPassed']);
    System.debug('++detailsIds++=='+detailIds);
        if(detailIds != null && detailIds.size() > 0){
            Id detailId = detailIds[0].Id; 
            List<CronTrigger> cronTriggerList = new List<CronTrigger>([SELECT Id from CronTrigger WHERE CronJobDetailId = :detailIds[0].Id]);
            if(cronTriggerList.size() > 0){ 
                System.abortJob(cronTriggerList[0].Id); 
            }
        } 
}

 
How to Cover test.isRunningTest() in test class in if else conditon
for(String ownerId : ownerIds){
                if(loggedInUsers != NULL && loggedInUsers.size() > 0){
                    String a;
                    if(test.isRunningTest() == true){
                         a = null;
                        System.debug(a);
                    }else{
                         a = ownerId;
                        System.debug(a);
                    }
In a test class i tried to create task and events in same opportunity, but when i tried to do so duplicate id error occured.
Here is my code:
Opportunity opp1 = UtilityTest.getOpportunity(acc.Id);
            insert opp1;
            
            Task[] tasks = new Task[]{
                new Task(Subject = 'Call',Ownerid=userInfo.getUserId(),
                         Status = 'In Progress', WhatId = opp1.Id,
                         Priority = 'Normal'),
                    new Task(Subject = 'Call',Ownerid=userInfo.getUserId(),
                             Status = 'In Progress', WhatId = opp1.Id,
                             Priority = 'Normal')
                    };
            insert tasks;
             
            Event[] evs = new Event[]{
                new Event(Subject = 'Call',Ownerid=userInfo.getUserId(), WhatId = opp1.Id,
                          StartDateTime = date.today()+1,EndDateTime = Date.today()+2),
                    
                    new Event(Subject = 'Call',Ownerid=userInfo.getUserId(), WhatId = opp1.Id,
                              StartDateTime = date.today()+1,EndDateTime = Date.today()+2) 
                    };
			   
				insert evs;       
			 
            update opp1;

 
the problem is i am not able to update opportunity field meanss their is class which have some condtion. i write a test class to cover that class.
public with sharing class Sample{

    public static void lastThreeMonthsVolumeOnLead(List<Opportunity> opps, 
                                                    Map<Id, Opportunity> oldOpps){
        
        Map<String, BankVolumeInfoOnLeadWrapper> appIdWithBankInformation = 
                new Map<String, BankVolumeInfoOnLeadWrapper>();
		System.debug(opps);
        System.debug(oldOpps);                                                
        for(Opportunity opp : opps){
            //this condition which i want to make fullfill in test class
            if(opp.Volume_Last_Month__c != oldOpps.get(opp.Id).Volume_Last_Month__c || 
                    opp.Volume_Two_Months_Ago__c != oldOpps.get(opp.Id).Volume_Two_Months_Ago__c || 
                    opp.Volume_Three_Months_Ago__c != oldOpps.get(opp.Id).Volume_Three_Months_Ago__c ){
                System.debug('hello i m here');
                BankVolumeInfoOnLeadWrapper bankVolumeWrapper = new BankVolumeInfoOnLeadWrapper();
                bankVolumeWrapper.volumeLastMonth = opp.Volume_Last_Month__c;
                bankVolumeWrapper.volumeTwoMonthsAgo = opp.Volume_Two_Months_Ago__c;
                bankVolumeWrapper.volumeThreeMonthsAgo = opp.Volume_Three_Months_Ago__c;   

                appIdWithBankInformation.put(opp.Id, bankVolumeWrapper);
            }
        } 

        if(appIdWithBankInformation.size() != 0) updateLeadWithBankVolumes(appIdWithBankInformation);  
    }

    static void updateLeadWithBankVolumes(Map<String, BankVolumeInfoOnLeadWrapper> 
                                                appIdWithBankInformation){

        Map<Id, Lead> leadsToUpdate = new Map<Id, Lead>();

        for(Lead lead : [SELECT Id, Volume_Last_Month__c,
                                Volume_Two_Months_Ago__c, 
                                Volume_Three_Months_Ago__c, 
                                Renewal_App__c
                                FROM Lead WHERE IsConverted = false AND 
                                Renewal_App__c != null AND 
                                Renewal_App__c IN: appIdWithBankInformation.keySet()]){
            
            BankVolumeInfoOnLeadWrapper bankVolumeWrapper = 
                appIdWithBankInformation.get(lead.Renewal_App__c);
            
            lead.Volume_Last_Month__c = bankVolumeWrapper.volumeLastMonth;
            lead.Volume_Two_Months_Ago__c = bankVolumeWrapper.volumeTwoMonthsAgo;
            lead.Volume_Three_Months_Ago__c = bankVolumeWrapper.volumeThreeMonthsAgo;
            
            leadsToUpdate.put(lead.Id, lead);
        }

        if(leadsToUpdate.size() != 0) update leadsToUpdate.values();
    }

    public class BankVolumeInfoOnLeadWrapper{
        public Decimal volumeLastMonth = 0;
        public Decimal volumeTwoMonthsAgo = 0;
        public Decimal volumeThreeMonthsAgo = 0;
        public bankVolumeInfoOnLeadWrapper(){}
    }

}
In above code i made bold tht condition which i want to full fill in test class.

and here is my test class
@isTest
public class SampleTest{
    
    @isTest
    static void getlastThreeMonthsVolumeOnLead()
    {
        Test.startTest();
         insert UtilityTest.getTriggerExecutionCS();
       
        Account acc = UtilityTest.getAccountWithRecordLabel('Broker Account');
        insert acc;
        
        Account acc1=UtilityTest.getAccountWithRecordLabel('Merchant Accounts');
        acc1.Name= 'Tiger Funding';
        insert acc1;
        
        Opportunity opp=UtilityTest.getOpportunity(acc.Id);
        opp.Volume_Last_Month__c=5;
        opp.Volume_Two_Months_Ago__c=25;
        opp.Volume_Three_Months_Ago__c =20;
        opp.Name='Test1';
        insert opp;
        System.debug(opp);
        
        opp.Volume_Last_Month__c=60;
        opp.Volume_Two_Months_Ago__c=50;
        opp.Volume_Three_Months_Ago__c =40;
        opp.Name='Test12';
        update opp;
        
        System.debug(opp);
        
        
           
        
        Test.stopTest();
    }

}

When i debug oldOpp and newOpp both return same value mnss it cannot get newer one can someone help me why is it so..   
Want to Write CronJobDetail Test class
public void abortCronJob(){
            List<CronJobDetail> detailIds = new List<CronJobDetail>([Select Id From CronJobDetail where Name ='ScheduleBatchPaymentDaysPassed']);
    System.debug('++detailsIds++=='+detailIds);
        if(detailIds != null && detailIds.size() > 0){
            Id detailId = detailIds[0].Id; 
            List<CronTrigger> cronTriggerList = new List<CronTrigger>([SELECT Id from CronTrigger WHERE CronJobDetailId = :detailIds[0].Id]);
            if(cronTriggerList.size() > 0){ 
                System.abortJob(cronTriggerList[0].Id); 
            }
        } 
}

 
In a test class i tried to create task and events in same opportunity, but when i tried to do so duplicate id error occured.
Here is my code:
Opportunity opp1 = UtilityTest.getOpportunity(acc.Id);
            insert opp1;
            
            Task[] tasks = new Task[]{
                new Task(Subject = 'Call',Ownerid=userInfo.getUserId(),
                         Status = 'In Progress', WhatId = opp1.Id,
                         Priority = 'Normal'),
                    new Task(Subject = 'Call',Ownerid=userInfo.getUserId(),
                             Status = 'In Progress', WhatId = opp1.Id,
                             Priority = 'Normal')
                    };
            insert tasks;
             
            Event[] evs = new Event[]{
                new Event(Subject = 'Call',Ownerid=userInfo.getUserId(), WhatId = opp1.Id,
                          StartDateTime = date.today()+1,EndDateTime = Date.today()+2),
                    
                    new Event(Subject = 'Call',Ownerid=userInfo.getUserId(), WhatId = opp1.Id,
                              StartDateTime = date.today()+1,EndDateTime = Date.today()+2) 
                    };
			   
				insert evs;       
			 
            update opp1;

 
the problem is i am not able to update opportunity field meanss their is class which have some condtion. i write a test class to cover that class.
public with sharing class Sample{

    public static void lastThreeMonthsVolumeOnLead(List<Opportunity> opps, 
                                                    Map<Id, Opportunity> oldOpps){
        
        Map<String, BankVolumeInfoOnLeadWrapper> appIdWithBankInformation = 
                new Map<String, BankVolumeInfoOnLeadWrapper>();
		System.debug(opps);
        System.debug(oldOpps);                                                
        for(Opportunity opp : opps){
            //this condition which i want to make fullfill in test class
            if(opp.Volume_Last_Month__c != oldOpps.get(opp.Id).Volume_Last_Month__c || 
                    opp.Volume_Two_Months_Ago__c != oldOpps.get(opp.Id).Volume_Two_Months_Ago__c || 
                    opp.Volume_Three_Months_Ago__c != oldOpps.get(opp.Id).Volume_Three_Months_Ago__c ){
                System.debug('hello i m here');
                BankVolumeInfoOnLeadWrapper bankVolumeWrapper = new BankVolumeInfoOnLeadWrapper();
                bankVolumeWrapper.volumeLastMonth = opp.Volume_Last_Month__c;
                bankVolumeWrapper.volumeTwoMonthsAgo = opp.Volume_Two_Months_Ago__c;
                bankVolumeWrapper.volumeThreeMonthsAgo = opp.Volume_Three_Months_Ago__c;   

                appIdWithBankInformation.put(opp.Id, bankVolumeWrapper);
            }
        } 

        if(appIdWithBankInformation.size() != 0) updateLeadWithBankVolumes(appIdWithBankInformation);  
    }

    static void updateLeadWithBankVolumes(Map<String, BankVolumeInfoOnLeadWrapper> 
                                                appIdWithBankInformation){

        Map<Id, Lead> leadsToUpdate = new Map<Id, Lead>();

        for(Lead lead : [SELECT Id, Volume_Last_Month__c,
                                Volume_Two_Months_Ago__c, 
                                Volume_Three_Months_Ago__c, 
                                Renewal_App__c
                                FROM Lead WHERE IsConverted = false AND 
                                Renewal_App__c != null AND 
                                Renewal_App__c IN: appIdWithBankInformation.keySet()]){
            
            BankVolumeInfoOnLeadWrapper bankVolumeWrapper = 
                appIdWithBankInformation.get(lead.Renewal_App__c);
            
            lead.Volume_Last_Month__c = bankVolumeWrapper.volumeLastMonth;
            lead.Volume_Two_Months_Ago__c = bankVolumeWrapper.volumeTwoMonthsAgo;
            lead.Volume_Three_Months_Ago__c = bankVolumeWrapper.volumeThreeMonthsAgo;
            
            leadsToUpdate.put(lead.Id, lead);
        }

        if(leadsToUpdate.size() != 0) update leadsToUpdate.values();
    }

    public class BankVolumeInfoOnLeadWrapper{
        public Decimal volumeLastMonth = 0;
        public Decimal volumeTwoMonthsAgo = 0;
        public Decimal volumeThreeMonthsAgo = 0;
        public bankVolumeInfoOnLeadWrapper(){}
    }

}
In above code i made bold tht condition which i want to full fill in test class.

and here is my test class
@isTest
public class SampleTest{
    
    @isTest
    static void getlastThreeMonthsVolumeOnLead()
    {
        Test.startTest();
         insert UtilityTest.getTriggerExecutionCS();
       
        Account acc = UtilityTest.getAccountWithRecordLabel('Broker Account');
        insert acc;
        
        Account acc1=UtilityTest.getAccountWithRecordLabel('Merchant Accounts');
        acc1.Name= 'Tiger Funding';
        insert acc1;
        
        Opportunity opp=UtilityTest.getOpportunity(acc.Id);
        opp.Volume_Last_Month__c=5;
        opp.Volume_Two_Months_Ago__c=25;
        opp.Volume_Three_Months_Ago__c =20;
        opp.Name='Test1';
        insert opp;
        System.debug(opp);
        
        opp.Volume_Last_Month__c=60;
        opp.Volume_Two_Months_Ago__c=50;
        opp.Volume_Three_Months_Ago__c =40;
        opp.Name='Test12';
        update opp;
        
        System.debug(opp);
        
        
           
        
        Test.stopTest();
    }

}

When i debug oldOpp and newOpp both return same value mnss it cannot get newer one can someone help me why is it so..   
Hi,
My requirement is -A user shouldn't be able to create opportunites more than worth 100k in a day. I am writing a trigger in the apex class for this.Below is the code.
public class TriggerClass
{
  public void checkOpps(List<Opportunity> ops)
  {
    Double Total_Amount=0;
    for(Opportunity o1: [Select Amount from Opportunity where createdDate=Today AND CreatedByID=:UserInfo.getuserID()])
    {
      Total_Amount += o1.Amount;
    }
     for (opportunity o2:ops)
    {
    Total_Amount+=o2.amount;
    }
    If(Total_Amount>1000000)
    {
     o2.addError('You have exceeded Daily Limits');
     }
     }
     }

It thorws a compile error:  Compile Error: Variable does not exist: Amount 
When I comment the line-Total_Amount += o1.Amount, it gives an error-Loop variable must be an SObject or list of Opportunity  (for the first For loop).
What I am missing here.
Note- I know this can be done in many other ways, but I am interested in knowing reason for these errors in the above code