• The new Learner
  • NEWBIE
  • 125 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 54
    Questions
  • 81
    Replies
HI Experts,

I have written a visual force component and an apex class, problem over here is that, i can able to cover upto 73%, and not able to cover soql queries , lines which i bolded those are the lines which i am not able to cover. can anyone help me  please below is my code.
 
public with sharing class CampaignApprovalReject {
    
    
  public String camIds {get;set;}
    public Campaign camp{get;set;}
    Public ProcessInstanceStep pStep{get;set;}
    Public String sfdcBaseURL{get;set;}
    
    
    public CampaignApprovalReject (){
        
    }
    public ProcessInstanceStep getApprovalSteps() {
       
        if (camIds != null) 
        {
           
            pStep = [Select SystemModstamp,StepStatus, ProcessInstanceId, OriginalActorId,OriginalActor.Name,
                     Comments, ActorId From ProcessInstanceStep where ProcessInstance.TargetObjectId=:camIds order by SystemModstamp desc limit 1];  
            system.debug('@@@pStep'+pStep); 
        }
        return pStep ;
    }
    
    Public campaign getcampaigns(){
        if (camIds != null) 
        {
            camp= [Select id,name,Type,Description__c,ParentName__c from campaign where id=:camIds limit 1];
            
        }
        
        return camp;
    }
 
    
    public List<ProcessInstanceHistory> getrecallApprovalSteps() 
    {
        if (camIds != null) 
        {
            camp= [Select Id, (Select TargetObjectId, SystemModstamp, StepStatus, RemindersSent, ProcessInstanceId, OriginalActorId, IsPending, IsDeleted, Id, CreatedDate, CreatedById, Comments, ActorId From ProcessSteps order by SystemModstamp desc) from campaign where Id = :camIds ];
            return camp.ProcessSteps;
        }
        return new List<ProcessInstanceHistory>();
    }
    
    Public String getURL(){
        if (camIds != null) {
            sfdcBaseURL = URL.getSalesforceBaseUrl().toExternalForm()+'/'+camp.id;
        }
        return sfdcBaseURL;
    }
    
}

Below is my test class.
 
@isTest
public class Campaign_Test {
    @isTest static void myTest() 
    {
        
        Campaign a = new Campaign ();
        a.Name='Example';
        a.Description__c='test';
        a.Status='Planned';
        a.StartDate=system.today();
        a.CurrencyIsoCode='USD';
        a.Parent__c=true;
        a.type='Nurture';
        insert a;
        Campaign a2=[Select id,name,Type,CAP_WT_Campaign_Short_Description__c from campaign where name='Example' LIMIT 1];
        System.assert(a2!=null);        
        Approval.ProcessSubmitRequest req1 =  new Approval.ProcessSubmitRequest();
        req1.setComments('Submitting request for approval.');
        req1.setObjectId(a.id);
        req1.setProcessDefinitionNameOrId('Example_Process');
        req1.setSkipEntryCriteria(true);
        CampaignApprovalReject cmp = new CampaignApprovalReject();
        ProcessInstanceStep  process = cmp.getApprovalSteps();
        Campaign itemObj = cmp.getcampaigns();
        list<ProcessInstanceHistory> PI=cmp.getrecallApprovalSteps();
        string itemob=cmp.getURL();
        cmp.camIds='Example';
        System.assertEquals('Example', a.Name);
        
    }
}

 
HI Experts,

I have requirment where i need to create VF email template, using custom labels for each section to allow for users receiving the template to see it in their own language.  Can anyone help me how to create it.
HI Experts,

I have requirment where i need to login attempts of a community user ,its more than 5 login attempts , i need to populate an error message. can anyone help me please.
I have to populate the image based on the below conditions.

1. when the record type is "sales" or "service" and Date__c is greater than (Today() -160) then it should be green.
2. when the record type is "sales" or "service" and Date__c is less than (Today() -160) then it should be red.
3. when the record type is "sales" or "service" or "marketing" and status is not equal "renewed" and date__c <today then it should be red.
4. when image__c field is is not blank then it should it should be grey.

can anyone help me please.
Hi Experts,

I want to display a logo from second page page onwards, in an visulforce page can anyone help me how to do that.(from second page onwards that image has to be there in every page )
HI Experts,

Can anyone help me out, how to create below table format using html or apex table.
User-added image
Hi Experts,

I am rendering a pdf and populating data for every single record i want to break and again i need to show in seprate table next record. can anyone let me know please how to do that.
Hi Experts,

I have requirment i need  download account related contact object records as pdf, i can able to make it as pdf, but , i want download once i click on that button,i am using this page as button source. can anyone help me.
 
<apex:page readOnly="true"     
           standardController="Account"    
           applyHtmlTag="false"     
           sidebar="false"     
           showHeader="false"     
           cache="true"     
           renderAs="advanced_pdf">    
        
    <head>    
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />    
        <style type="text/css">    
            
            @page {    
              
                size: A4 landscape;    
                border: 2px solid black;    
                padding-left: 8px;    
                padding-right: 8px;      
                  
            }    
                
            th {    
              
                text-align: center;    
                font-weight: bold;    
                  
            }    
                
                
            td {    
              
                text-align: center;    
                font-size: 14px;    
                  
            }    
                
        </style>    
          
    </head>    
      
    <center>    
      
        <h3>Testing Advanced PDF = {!Account.Name}</h3>    
          
    </center><br/><br/>    
      
    <table border="1" width="99%">    
      
        <tr>    
          
            <th>First Name</th>    
            <th>Last Name</th>    
              
        </tr>    
        <apex:repeat value="{!Account.Contacts}" var="con">    
          
            <tr>    
              
                <td>{!con.FirstName}</td>    
                <td>{!con.LastName}</td>    
                  
            </tr>    
              
        </apex:repeat>    
          
    </table>    
    
</apex:page>

 
Hi Experts,

Can anyone let me know how to cast sobject to a specific object vice versa please. below i am getting the records, now i want to cast that object to specifi object.
SObjectType objectType = records.getSObjectType();
HI Experts,

i am trying to get the difference between two dates using business hours difference method like below to exclude holidays and weeknds while converting milliseconds in to date i am not getting anything can anyone help please.
 
here is method


 long temp= BusinessHours.diff(
                            ri.Completion_Date__c,
                            ri.Completion_Date__c-3,
                            businessHoursId);

output: DEBUG|temp-1020 

DateTime gmtDatetime = DateTime.newInstance(temp);

output: gmtDatetime1969-12-31 23:59:58

 
HI Experts,

I Have requirment ,where i need to find out the businessday between two days, eg: if startdate is today, and startday-3, i need to find out the businessday between these two days by excluding holidays and weekends.
Hi Experts, 

I want to find out the business day between two dates need to exclude holidays and weekends. Can anyone help me pls 
Hi Experts,

I am getting below error for the case comment. can anyone help me please. Error: SObject type CaseComment is not supported by this unit of work. 
below is the code. can anyone help me how to fix this issue.

 
public void registerNew(SObject record, Schema.sObjectField relatedToParentField, SObject relatedToParentRecord)
    {
        if(record.Id != null)
            throw new UnitOfWorkException('Only new records can be registered as new');
        String sObjectType = record.getSObjectType().getDescribe().getName();
        if(!m_newListByType.containsKey(sObjectType))
            throw new UnitOfWorkException(String.format('SObject type {0} is not supported by this unit of work', new String[] { sObjectType }));
        m_newListByType.get(sObjectType).add(record);
        if(relatedToParentRecord!=null && relatedToParentField!=null)
            registerRelationship(record, relatedToParentField, relatedToParentRecord);
    }

 
Hi Experts,

There is an email is comes from webservice, in that email we are searching for the policy number with that policy number we are creating case but problem here is that its  reading phone number also and creating case, so i observerd that phone number is coming prefix as "tel,T,telephone,phone,fax,F,+27" if i find anythig like this i need to ignore.
below is the expression we are using. can anyone help me please

public static final String REGEX_PATTERN_POLICY_NUMBER = '[0-9]{6,12}';
How can i redirect to the contact page , once the opportunity record get created. can anyone help me please.
 
/lightning/o/Opportunity/new?defaultFieldValues=Name={!Account.Name},ContactId={!Contact.Id}&backgroundContext=%2Flightning%2Fr%2FContact%2F{!Contact.Id}%2Fview

 
Hi Experts, 

I am not able to cover the code coverage for below else methods can anyone help me out, i have striked lines which i am not able to cover , till i can able to cover only 53% , please help me out.
public static void updateBeforeChange(List<SObject> newSobjs, Map<Id,SObject> oldSobjsMap)
    {
        List<Case> newCases = (List<Case>) newSobjs;
        Map<Id, Case> oldCasesMap = (Map<Id, Case>)oldSobjsMap;
        BusinessHours bh = [SELECT Id,SundayStartTime, MondayStartTime, TuesdayStartTime,WednesdayStartTime, ThursdayStartTime, FridayStartTime,SaturdayStartTime, SundayEndTime, MondayEndTime,TuesdayEndTime,WednesdayEndTime, ThursdayEndTime, FridayEndTime,SaturdayEndTime FROM BusinessHours WHERE IsDefault=true];//Quering the businesshours to user in IsWithin function
        system.debug('BusinessHoursBusinessHours  '+bh);
        for(Case cs : newCases)
        {
            Case oldCs = oldCasesMap.get(cs.Id);
            Boolean oldrecordtype= oldcs.RecordType_Name__c.equals('N_L_QNA');
            Boolean oldrecordtype1= oldcs.RecordType_Name__c.equals('L_QNA');
            Boolean newrecordtype = cs.RecordType_Name__c.equals('UW_L_QNA');
            Boolean newrecordtype1= cs.RecordType_Name__c.equals('N_L_QNA');
            string oldCsstatus = oldCasesMap.get(cs.Id).Status; 
            string dayOfWeek=cs.lastmodifieddate.format('EEEE');
            System.debug('Day : ' + dayOfWeek);
            DateTime dT = cs.LastModifiedDate;
            Date myDate = date.newinstance(dT.year(), dT.month(), dT.day());
            System.debug('myDate : ' + myDate );
            String Mon ='Monday';
            String Tue ='Tuesday';
            String Wed ='Wednesday';
            String Thur ='Thursday';
            String Fri ='Friday';
            String Sat= 'Saturday';
            String Sun= 'Sunday';
            
            
            Boolean isWithin = BusinessHours.isWithin(bh.id,  cs.LastModifiedDate);
            
            
            if((oldrecordtype  || oldrecordtype1 ) && (newrecordtype || newrecordtype1) )
            {
                if(isWithin==true && (dayOfWeek == Mon || dayOfWeek == Tue|| dayOfWeek == Wed|| dayOfWeek == Thur|| dayOfWeek == Fri))
                {
                    
                   
                    cs.Sent_Hours__c= B_BusinessHours.getTimeDifferenceInMinutes(
                        cs.CreatedDate,
                        cs.LastModifiedDate,
                        businessHoursId);
                  
                    
                    Decimal mydecval = cs.Sent_Formula__c;
                    system.debug('mydecvalmydecvalmydecval'+mydecval);
                    Integer myintval = mydecval.intValue(); //Converting Decimal Value to Integer
                    system.debug('myintvalmyintvalmyintval'+myintval);
                    
                   
                    cs.Sent_to__c = B_BusinessHours.addMinutes(
                        myintval,
                        businessHoursId);
                }
                
                else if (dayOfWeek == Mon)
                {
                    cs.Sent_to__c= DateTime.newInstance(myDate,bh.MondayEndTime); 
                }
                else if(dayOfWeek == Tue)
                {
                    cs.Sent_to__c=  DateTime.newInstance(myDate,bh.TuesdayEndTime) ;
                }
                else if(dayOfWeek == Wed)
                {
                    cs.Sent_to__c=  DateTime.newInstance(myDate,bh.WednesdayEndTime) ;
                }
                else if(dayOfWeek == Thur)
                {
                    cs.Sent_to__c=  DateTime.newInstance(myDate,bh.ThursdayEndTime) ;
                   
                }
                else if(dayOfWeek == Fri)
                {
                    cs.Sent_to__c=  DateTime.newInstance(myDate,bh.FridayEndTime) ;
                }
                else if(dayOfWeek == Sat)
                {
                    Date satdate = myDate- 1;
                    cs.Sent_to__c=  DateTime.newInstance(satdate,bh.FridayEndTime) ;
                }
                else if(dayOfWeek == Sun)
                {
                    Date Sundate=myDate- 2;
                    cs.Sent_to__c=  DateTime.newInstance(Sundate,bh.FridayEndTime) ;**
                }
                
                
            }
            
            
            
        }
        
    }
    
    public static Id businessHoursId
    {
        get
        {
            if (businessHoursId == null)
            {
                businessHoursId = B_BusinessHours.getBusinessHoursId();
            }
            return businessHoursId;
        }
        set;
    }
}
Below is my test class :
 
Public static testMethod void Case_Test_method1() 
{
  
  Id recordtyepe= Schema.SObjectType.Case.getRecordTypeInfosByName().get(' L - QNA').getRecordTypeId();
  Id recordtyepes= Schema.SObjectType.Case.getRecordTypeInfosByName().get('UW - L - QNA').getRecordTypeId();

  BusinessHours bhs=[SELECT Id,SundayStartTime, MondayStartTime, TuesdayStartTime,WednesdayStartTime, ThursdayStartTime, FridayStartTime,SaturdayStartTime, SundayEndTime, MondayEndTime,TuesdayEndTime,WednesdayEndTime, ThursdayEndTime, FridayEndTime,SaturdayEndTime FROM BusinessHours WHERE IsDefault=true];
  Boolean isWithin = BusinessHours.isWithin(bhs.id, datetime.newInstance(2020, 03, 09, 05, 30, 0));
  //System.assert(bhs.size()==1);
 if(isWithin==false)
 {
  case c1 = new case();
  c1.Origin='email';
  c1.Status='Assigned';
  c1.RecordtypeId= recordtyepe;
  c1.Process__c='Verify';
  c1.Process__c= 'Preparation';
  insert c1;
  
 //long hours = B_BusinessHours.getTimeDifferenceInMinutes(c1.createddate,c1.lastmodifieddate,bhs.id);

  //c1.Sent_to_Prepare_Quote_Hours__c=hours;
  c1.Status='Quote Completed and Emailed to Broker';
  c1.Process__c='Quote Preparation';
  c1.Process__c='Classify/Verify';
  c1.RecordtypeId =recordtyepes;
  c1.Sent_to__c= system.now();
  try{
  update c1;
  }
  catch(exception e){}
 }
 }
    }


 
Hi Experts,

I am not Not able to cover the below class handler which works before update , can anyone help me out. please. still its only 53%, majority of the issue is wiht else part which i bolded.
 
public without sharing class Stamp_Case
{
    
    public static void updateBeforeChange(List<SObject> newSobjs, Map<Id,SObject> oldSobjsMap)
    {
        List<Case> newCases = (List<Case>) newSobjs;
        Map<Id, Case> oldCasesMap = (Map<Id, Case>)oldSobjsMap;
        BusinessHours bh = [SELECT Id,SundayStartTime, MondayStartTime, TuesdayStartTime,WednesdayStartTime, ThursdayStartTime, FridayStartTime,SaturdayStartTime, SundayEndTime, MondayEndTime,TuesdayEndTime,WednesdayEndTime, ThursdayEndTime, FridayEndTime,SaturdayEndTime FROM BusinessHours WHERE IsDefault=true];//Quering the businesshours to user in IsWithin function
        system.debug('BusinessHoursBusinessHours  '+bh);
        for(Case cs : newCases)
        {
            Case oldCs = oldCasesMap.get(cs.Id);
            Boolean oldrecordtype= oldcs.RecordType_Name__c.equals('N_L_QNA');
            Boolean oldrecordtype1= oldcs.RecordType_Name__c.equals('L_QNA');
            Boolean newrecordtype = cs.RecordType_Name__c.equals('UW_L_QNA');
            Boolean newrecordtype1= cs.RecordType_Name__c.equals('N_L_QNA');
            string oldCsstatus = oldCasesMap.get(cs.Id).Status; 
            string dayOfWeek=cs.lastmodifieddate.format('EEEE');
            System.debug('Day : ' + dayOfWeek);
            DateTime dT = cs.LastModifiedDate;
            Date myDate = date.newinstance(dT.year(), dT.month(), dT.day());
            System.debug('myDate : ' + myDate );
            String Mon ='Monday';
            String Tue ='Tuesday';
            String Wed ='Wednesday';
            String Thur ='Thursday';
            String Fri ='Friday';
            String Sat= 'Saturday';
            String Sun= 'Sunday';
            
            
            Boolean isWithin = BusinessHours.isWithin(bh.id,  cs.LastModifiedDate);
            
            
            if((oldrecordtype  || oldrecordtype1 ) && (newrecordtype || newrecordtype1) )
            {
                if(isWithin==true && (dayOfWeek == Mon || dayOfWeek == Tue|| dayOfWeek == Wed|| dayOfWeek == Thur|| dayOfWeek == Fri))
                {
                    
                   
                    cs.Sent_Hours__c= B_BusinessHours.getTimeDifferenceInMinutes(
                        cs.CreatedDate,
                        cs.LastModifiedDate,
                        businessHoursId);
                  
                    
                    Decimal mydecval = cs.Sent_Formula__c;
                    system.debug('mydecvalmydecvalmydecval'+mydecval);
                    Integer myintval = mydecval.intValue(); //Converting Decimal Value to Integer
                    system.debug('myintvalmyintvalmyintval'+myintval);
                    
                   
                    cs.Sent_to__c = B_BusinessHours.addMinutes(
                        myintval,
                        businessHoursId);
                }
                
                **else if (dayOfWeek == Mon)
                {
                    cs.Sent_to__c= DateTime.newInstance(myDate,bh.MondayEndTime); 
                }
                else if(dayOfWeek == Tue)
                {
                    cs.Sent_to__c=  DateTime.newInstance(myDate,bh.TuesdayEndTime) ;
                }
                else if(dayOfWeek == Wed)
                {
                    cs.Sent_to__c=  DateTime.newInstance(myDate,bh.WednesdayEndTime) ;
                }
                else if(dayOfWeek == Thur)
                {
                    cs.Sent_to__c=  DateTime.newInstance(myDate,bh.ThursdayEndTime) ;
                   
                }
                else if(dayOfWeek == Fri)
                {
                    cs.Sent_to__c=  DateTime.newInstance(myDate,bh.FridayEndTime) ;
                }
                else if(dayOfWeek == Sat)
                {
                    Date satdate = myDate- 1;
                    cs.Sent_to__c=  DateTime.newInstance(satdate,bh.FridayEndTime) ;
                }
                else if(dayOfWeek == Sun)
                {
                    Date Sundate=myDate- 2;
                    cs.Sent_to__c=  DateTime.newInstance(Sundate,bh.FridayEndTime) ;**
                }
                
                
            }
            
            if((cs.status =='Emailed to Broker' || cs.status==' Emailed to Distribution') && oldCsstatus != cs.status)
            {
                **if(isWithin==true && (dayOfWeek == Mon || dayOfWeek == Tue|| dayOfWeek == Wed|| dayOfWeek == Thur|| dayOfWeek == Fri))
                {
                    cs.Dist_Hours__c = B_BusinessHours.getTimeDifferenceInMinutes(
                        cs.CreatedDate,
                        cs.LastModifiedDate,
                        businessHoursId);
                    
                    Decimal mydecval = cs.Dist_Formula__c;
                   
                    Integer myintval = mydecval.intValue();
                    system.debug('myintvalmyintvalmyintval'+myintval);
                    cs.Dist__c= B_BusinessHours.addMinutes(
                        myintval,
                        businessHoursId);
                }
                else if (dayOfWeek == Mon)
                {
                    cs.Dist__c= DateTime.newInstance(myDate,bh.MondayEndTime); 
                }
                else if(dayOfWeek == Tue)
                {
                    cs.Dist__c=  DateTime.newInstance(myDate,bh.TuesdayEndTime) ;
                }
                else if(dayOfWeek == Wed)
                {
                    cs.Dist__c=  DateTime.newInstance(myDate,bh.WednesdayEndTime) ;
                }
                else if(dayOfWeek == Thur)
                {
                    cs.Dist__c=  DateTime.newInstance(myDate,bh.ThursdayEndTime) ;
                  
                }
                else if(dayOfWeek == Fri)
                {
                    cs.Dist__c=  DateTime.newInstance(myDate,bh.FridayEndTime) ;
                }
                else if(dayOfWeek == Sat)
                {
                    Date satdate = myDate- 1;
                    cs.Dist__c=  DateTime.newInstance(satdate,bh.FridayEndTime) ;
                }
                else if(dayOfWeek == Sun)
                {
                    Date Sundate=myDate- 2;
                    cs.Dist__c=  DateTime.newInstance(Sundate,bh.FridayEndTime) ;
                }**
                
            }
            
            if(cs.Process__c=='Verify' && cs.Verify_Date__c== null)
            {
                
                if(isWithin==true && (dayOfWeek == Mon || dayOfWeek == Tue|| dayOfWeek == Wed|| dayOfWeek == Thur|| dayOfWeek == Fri))
                { 
                    
                    cs.Date_Hours__c= B_BusinessHours.getTimeDifferenceInMinutes(
                        cs.CreatedDate,
                        cs.LastModifiedDate,
                        businessHoursId);
                    
                    Decimal mydecval = cs.Date_Formula__c;
                  
                    Integer myintval = mydecval.intValue();
                   
                    cs.Verify_Date__c= B_BusinessHours.addMinutes(
                        myintval,
                        businessHoursId);
                }
                
                **else if (dayOfWeek == Mon)
                {
                    cs.Verify_Date__c = DateTime.newInstance(myDate,bh.MondayEndTime); 
                }
                else if(dayOfWeek == Tue)
                {
                    cs.Verify_Date__c =  DateTime.newInstance(myDate,bh.TuesdayEndTime) ;
                }
                else if(dayOfWeek == Wed)
                {
                    cs.Verify_Date__c =  DateTime.newInstance(myDate,bh.WednesdayEndTime) ;
                }
                else if(dayOfWeek == Thur)
                {
                    cs.Verify_Date__c =  DateTime.newInstance(myDate,bh.ThursdayEndTime) ;
                   
                }
                else if(dayOfWeek == Fri)
                {
                    cs.Verify_Date__c =  DateTime.newInstance(myDate,bh.FridayEndTime) ;
                }
                else if(dayOfWeek == Sat)
                {
                    Date satdate = myDate- 1;
                    cs.Verify_Date__c =  DateTime.newInstance(satdate,bh.FridayEndTime) ;
                }
                else if(dayOfWeek == Sun)
                {
                    Date Sundate=myDate- 2;
                    cs.Verify_Date__c =  DateTime.newInstance(Sundate,bh.FridayEndTime) ;**
                } 
                
            }
            
            if(cs.Process__c=='Preparation' && cs.Preparation_Date__c== null)
            {
                
                if(isWithin==true && (dayOfWeek == Mon || dayOfWeek == Tue|| dayOfWeek == Wed|| dayOfWeek == Thur|| dayOfWeek == Fri))
              {
                
                cs.Preparation_Date_Hours__c= B_BusinessHours.getTimeDifferenceInMinutes(
                    cs.CreatedDate,
                    cs.LastModifiedDate,
                    businessHoursId);
                
                Decimal mydecval = cs.Preparation_Date_Formula__c;
                
                Integer myintval = mydecval.intValue();
                
                cs.Preparation_Date__c = B_BusinessHours.addMinutes(
                    myintval,
                    businessHoursId);
                
            }
            
            else if (dayOfWeek == Mon)
            {
                **cs.Preparation_Date__c = DateTime.newInstance(myDate,bh.MondayEndTime);** 
            }
            else if(dayOfWeek == Tue)
            {
                **cs.Preparation_Date__c =  DateTime.newInstance(myDate,bh.TuesdayEndTime) ;**
            }
            else if(dayOfWeek == Wed)
            {
                **cs.Preparation_Date__c =  DateTime.newInstance(myDate,bh.WednesdayEndTime) ;**
            }
            else if(dayOfWeek == Thur)
            {
                cs.Preparation_Date__c =  DateTime.newInstance(myDate,bh.ThursdayEndTime) ;
               
            }
            **else if(dayOfWeek == Fri)
            {
                cs.Preparation_Date__c =  DateTime.newInstance(myDate,bh.FridayEndTime) ;
            }
            else if(dayOfWeek == Sat)
            {
                Date satdate = myDate- 1;
                cs.Preparation_Date__c =  DateTime.newInstance(satdate,bh.FridayEndTime) ;
            }
            else if(dayOfWeek == Sun)
            {
                Date Sundate=myDate- 2;
                cs.Preparation_Date__c =  DateTime.newInstance(Sundate,bh.FridayEndTime) ;**
            } 
            
          }
            
        }
        
    }
    
    public static Id businessHoursId
    {
        get
        {
            if (businessHoursId == null)
            {
                businessHoursId = B_BusinessHours.getBusinessHoursId();
            }
            return businessHoursId;
        }
        set;
    }
}


Below is my Test class.

        @isTest
    public class Case_Test{
    
    Public static testMethod void Test_method() 
    {
    
      Id recordtyepe= Schema.SObjectType.Case.getRecordTypeInfosByName().get('- L - QNA').getRecordTypeId();
      Id recordtyepes= Schema.SObjectType.Case.getRecordTypeInfosByName().get('UW - L - QNA').getRecordTypeId();
      List<BusinessHours> bhs=[select id from BusinessHours where IsDefault=true];
     
      case c = new case();
      c.Origin='email';
      c.Status='Assigned';
      c.RecordtypeId= recordtyepe;
      c.Process__c='Verify';
      c.Process__c= 'Preparation';
      insert c;
      c.Process__c='Preparation';
      c.Process__c='Verify';
      c.RecordtypeId =recordtyepes;
      Test.setCreatedDate(c.Id,  datetime.newInstance(2019, 11, 11, 11, 30, 0));
       Test.startTest();
       case cs= [SELECT Id, CreatedDate,LastModifiedDate FROM case  where origin='email' limit 1];
       System.assertEquals(cs.CreatedDate,  DateTime.newInstance(2019,11,11,11,30,0));
       Test.stopTest();
       update c;
     
    }
    }

 
Hi Experts,

I have requirment i need create a button(not java script button because i cant use in lighting) when i click on that button new record page has to open and also i want set a default value in that new record page, can anyone hlep me please.
Hi Experts,

I am trying to update the State and Country ISO Code picklist values using packages but i am getting below error while deploying using workbench. can anyone tell me how to update it please

here is the package:

<?xml version="1.0" encoding="UTF-8"?>
<Package xmlns="http://soap.sforce.com/2006/04/metadata">
    <types>
        <members>Address</members>
        <name>Settings</name>
    </types>
    <version>42.0</version>
</Package>

Error:
Invalid iso code AB for country Aruba
Hi Experts,

Can anyone help me how to write test class for the below method.

public override void onCommit(){
        
        OM_ManageService manageRemittanceSVC = (OM_ManageRService)this.svc;
        String accJSON = OM_WorkService.getJSONAttribute(manageRemittanceSVC.jsonString, 'AccountInfo');
        Map<String, List<SObject>> accObjects =  OM_WorkService.getSObjects(accJSON);
        Account acc = (Account)accObjects.get('Account')[0];
        
        if(acc!= null){
            upsert acc;
            super.onCommit();
            
            }
            
        Below is the OM_WorkService.getJSONAttribut    
             
             public static String getJSONAttribute(String jsonStr, String attr){
        Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(jsonStr);
        if(m.containsKey(attr))
            return (String)m.get(attr);
        
        return null;
    }
 
Hi Experts,

Can anyone help me how to write test class for the below method.

public override void onCommit(){
        
        OM_ManageService manageRemittanceSVC = (OM_ManageRService)this.svc;
        String accJSON = OM_WorkService.getJSONAttribute(manageRemittanceSVC.jsonString, 'AccountInfo');
        Map<String, List<SObject>> accObjects =  OM_WorkService.getSObjects(accJSON);
        Account acc = (Account)accObjects.get('Account')[0];
        
        if(acc!= null){
            upsert acc;
            super.onCommit();
            
            }
            
        Below is the OM_WorkService.getJSONAttribut    
             
             public static String getJSONAttribute(String jsonStr, String attr){
        Map<String, Object> m = (Map<String, Object>)JSON.deserializeUntyped(jsonStr);
        if(m.containsKey(attr))
            return (String)m.get(attr);
        
        return null;
    }
 
HI Experts,

I have written a visual force component and an apex class, problem over here is that, i can able to cover upto 73%, and not able to cover soql queries , lines which i bolded those are the lines which i am not able to cover. can anyone help me  please below is my code.
 
public with sharing class CampaignApprovalReject {
    
    
  public String camIds {get;set;}
    public Campaign camp{get;set;}
    Public ProcessInstanceStep pStep{get;set;}
    Public String sfdcBaseURL{get;set;}
    
    
    public CampaignApprovalReject (){
        
    }
    public ProcessInstanceStep getApprovalSteps() {
       
        if (camIds != null) 
        {
           
            pStep = [Select SystemModstamp,StepStatus, ProcessInstanceId, OriginalActorId,OriginalActor.Name,
                     Comments, ActorId From ProcessInstanceStep where ProcessInstance.TargetObjectId=:camIds order by SystemModstamp desc limit 1];  
            system.debug('@@@pStep'+pStep); 
        }
        return pStep ;
    }
    
    Public campaign getcampaigns(){
        if (camIds != null) 
        {
            camp= [Select id,name,Type,Description__c,ParentName__c from campaign where id=:camIds limit 1];
            
        }
        
        return camp;
    }
 
    
    public List<ProcessInstanceHistory> getrecallApprovalSteps() 
    {
        if (camIds != null) 
        {
            camp= [Select Id, (Select TargetObjectId, SystemModstamp, StepStatus, RemindersSent, ProcessInstanceId, OriginalActorId, IsPending, IsDeleted, Id, CreatedDate, CreatedById, Comments, ActorId From ProcessSteps order by SystemModstamp desc) from campaign where Id = :camIds ];
            return camp.ProcessSteps;
        }
        return new List<ProcessInstanceHistory>();
    }
    
    Public String getURL(){
        if (camIds != null) {
            sfdcBaseURL = URL.getSalesforceBaseUrl().toExternalForm()+'/'+camp.id;
        }
        return sfdcBaseURL;
    }
    
}

Below is my test class.
 
@isTest
public class Campaign_Test {
    @isTest static void myTest() 
    {
        
        Campaign a = new Campaign ();
        a.Name='Example';
        a.Description__c='test';
        a.Status='Planned';
        a.StartDate=system.today();
        a.CurrencyIsoCode='USD';
        a.Parent__c=true;
        a.type='Nurture';
        insert a;
        Campaign a2=[Select id,name,Type,CAP_WT_Campaign_Short_Description__c from campaign where name='Example' LIMIT 1];
        System.assert(a2!=null);        
        Approval.ProcessSubmitRequest req1 =  new Approval.ProcessSubmitRequest();
        req1.setComments('Submitting request for approval.');
        req1.setObjectId(a.id);
        req1.setProcessDefinitionNameOrId('Example_Process');
        req1.setSkipEntryCriteria(true);
        CampaignApprovalReject cmp = new CampaignApprovalReject();
        ProcessInstanceStep  process = cmp.getApprovalSteps();
        Campaign itemObj = cmp.getcampaigns();
        list<ProcessInstanceHistory> PI=cmp.getrecallApprovalSteps();
        string itemob=cmp.getURL();
        cmp.camIds='Example';
        System.assertEquals('Example', a.Name);
        
    }
}

 
I have to populate the image based on the below conditions.

1. when the record type is "sales" or "service" and Date__c is greater than (Today() -160) then it should be green.
2. when the record type is "sales" or "service" and Date__c is less than (Today() -160) then it should be red.
3. when the record type is "sales" or "service" or "marketing" and status is not equal "renewed" and date__c <today then it should be red.
4. when image__c field is is not blank then it should it should be grey.

can anyone help me please.
Hi Experts,

I want to display a logo from second page page onwards, in an visulforce page can anyone help me how to do that.(from second page onwards that image has to be there in every page )
Hi Experts,

I am rendering a pdf and populating data for every single record i want to break and again i need to show in seprate table next record. can anyone let me know please how to do that.
Hi Experts,

I have requirment i need  download account related contact object records as pdf, i can able to make it as pdf, but , i want download once i click on that button,i am using this page as button source. can anyone help me.
 
<apex:page readOnly="true"     
           standardController="Account"    
           applyHtmlTag="false"     
           sidebar="false"     
           showHeader="false"     
           cache="true"     
           renderAs="advanced_pdf">    
        
    <head>    
        <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />    
        <style type="text/css">    
            
            @page {    
              
                size: A4 landscape;    
                border: 2px solid black;    
                padding-left: 8px;    
                padding-right: 8px;      
                  
            }    
                
            th {    
              
                text-align: center;    
                font-weight: bold;    
                  
            }    
                
                
            td {    
              
                text-align: center;    
                font-size: 14px;    
                  
            }    
                
        </style>    
          
    </head>    
      
    <center>    
      
        <h3>Testing Advanced PDF = {!Account.Name}</h3>    
          
    </center><br/><br/>    
      
    <table border="1" width="99%">    
      
        <tr>    
          
            <th>First Name</th>    
            <th>Last Name</th>    
              
        </tr>    
        <apex:repeat value="{!Account.Contacts}" var="con">    
          
            <tr>    
              
                <td>{!con.FirstName}</td>    
                <td>{!con.LastName}</td>    
                  
            </tr>    
              
        </apex:repeat>    
          
    </table>    
    
</apex:page>

 
HI Experts,

I Have requirment ,where i need to find out the businessday between two days, eg: if startdate is today, and startday-3, i need to find out the businessday between these two days by excluding holidays and weekends.
Hi Experts, 

I want to find out the business day between two dates need to exclude holidays and weekends. Can anyone help me pls 
Hi Experts,

I am getting below error for the case comment. can anyone help me please. Error: SObject type CaseComment is not supported by this unit of work. 
below is the code. can anyone help me how to fix this issue.

 
public void registerNew(SObject record, Schema.sObjectField relatedToParentField, SObject relatedToParentRecord)
    {
        if(record.Id != null)
            throw new UnitOfWorkException('Only new records can be registered as new');
        String sObjectType = record.getSObjectType().getDescribe().getName();
        if(!m_newListByType.containsKey(sObjectType))
            throw new UnitOfWorkException(String.format('SObject type {0} is not supported by this unit of work', new String[] { sObjectType }));
        m_newListByType.get(sObjectType).add(record);
        if(relatedToParentRecord!=null && relatedToParentField!=null)
            registerRelationship(record, relatedToParentField, relatedToParentRecord);
    }

 
Hi Experts,

There is an email is comes from webservice, in that email we are searching for the policy number with that policy number we are creating case but problem here is that its  reading phone number also and creating case, so i observerd that phone number is coming prefix as "tel,T,telephone,phone,fax,F,+27" if i find anythig like this i need to ignore.
below is the expression we are using. can anyone help me please

public static final String REGEX_PATTERN_POLICY_NUMBER = '[0-9]{6,12}';
How can i redirect to the contact page , once the opportunity record get created. can anyone help me please.
 
/lightning/o/Opportunity/new?defaultFieldValues=Name={!Account.Name},ContactId={!Contact.Id}&backgroundContext=%2Flightning%2Fr%2FContact%2F{!Contact.Id}%2Fview

 
Hi Experts,

I am not Not able to cover the below class handler which works before update , can anyone help me out. please. still its only 53%, majority of the issue is wiht else part which i bolded.
 
public without sharing class Stamp_Case
{
    
    public static void updateBeforeChange(List<SObject> newSobjs, Map<Id,SObject> oldSobjsMap)
    {
        List<Case> newCases = (List<Case>) newSobjs;
        Map<Id, Case> oldCasesMap = (Map<Id, Case>)oldSobjsMap;
        BusinessHours bh = [SELECT Id,SundayStartTime, MondayStartTime, TuesdayStartTime,WednesdayStartTime, ThursdayStartTime, FridayStartTime,SaturdayStartTime, SundayEndTime, MondayEndTime,TuesdayEndTime,WednesdayEndTime, ThursdayEndTime, FridayEndTime,SaturdayEndTime FROM BusinessHours WHERE IsDefault=true];//Quering the businesshours to user in IsWithin function
        system.debug('BusinessHoursBusinessHours  '+bh);
        for(Case cs : newCases)
        {
            Case oldCs = oldCasesMap.get(cs.Id);
            Boolean oldrecordtype= oldcs.RecordType_Name__c.equals('N_L_QNA');
            Boolean oldrecordtype1= oldcs.RecordType_Name__c.equals('L_QNA');
            Boolean newrecordtype = cs.RecordType_Name__c.equals('UW_L_QNA');
            Boolean newrecordtype1= cs.RecordType_Name__c.equals('N_L_QNA');
            string oldCsstatus = oldCasesMap.get(cs.Id).Status; 
            string dayOfWeek=cs.lastmodifieddate.format('EEEE');
            System.debug('Day : ' + dayOfWeek);
            DateTime dT = cs.LastModifiedDate;
            Date myDate = date.newinstance(dT.year(), dT.month(), dT.day());
            System.debug('myDate : ' + myDate );
            String Mon ='Monday';
            String Tue ='Tuesday';
            String Wed ='Wednesday';
            String Thur ='Thursday';
            String Fri ='Friday';
            String Sat= 'Saturday';
            String Sun= 'Sunday';
            
            
            Boolean isWithin = BusinessHours.isWithin(bh.id,  cs.LastModifiedDate);
            
            
            if((oldrecordtype  || oldrecordtype1 ) && (newrecordtype || newrecordtype1) )
            {
                if(isWithin==true && (dayOfWeek == Mon || dayOfWeek == Tue|| dayOfWeek == Wed|| dayOfWeek == Thur|| dayOfWeek == Fri))
                {
                    
                   
                    cs.Sent_Hours__c= B_BusinessHours.getTimeDifferenceInMinutes(
                        cs.CreatedDate,
                        cs.LastModifiedDate,
                        businessHoursId);
                  
                    
                    Decimal mydecval = cs.Sent_Formula__c;
                    system.debug('mydecvalmydecvalmydecval'+mydecval);
                    Integer myintval = mydecval.intValue(); //Converting Decimal Value to Integer
                    system.debug('myintvalmyintvalmyintval'+myintval);
                    
                   
                    cs.Sent_to__c = B_BusinessHours.addMinutes(
                        myintval,
                        businessHoursId);
                }
                
                **else if (dayOfWeek == Mon)
                {
                    cs.Sent_to__c= DateTime.newInstance(myDate,bh.MondayEndTime); 
                }
                else if(dayOfWeek == Tue)
                {
                    cs.Sent_to__c=  DateTime.newInstance(myDate,bh.TuesdayEndTime) ;
                }
                else if(dayOfWeek == Wed)
                {
                    cs.Sent_to__c=  DateTime.newInstance(myDate,bh.WednesdayEndTime) ;
                }
                else if(dayOfWeek == Thur)
                {
                    cs.Sent_to__c=  DateTime.newInstance(myDate,bh.ThursdayEndTime) ;
                   
                }
                else if(dayOfWeek == Fri)
                {
                    cs.Sent_to__c=  DateTime.newInstance(myDate,bh.FridayEndTime) ;
                }
                else if(dayOfWeek == Sat)
                {
                    Date satdate = myDate- 1;
                    cs.Sent_to__c=  DateTime.newInstance(satdate,bh.FridayEndTime) ;
                }
                else if(dayOfWeek == Sun)
                {
                    Date Sundate=myDate- 2;
                    cs.Sent_to__c=  DateTime.newInstance(Sundate,bh.FridayEndTime) ;**
                }
                
                
            }
            
            if((cs.status =='Emailed to Broker' || cs.status==' Emailed to Distribution') && oldCsstatus != cs.status)
            {
                **if(isWithin==true && (dayOfWeek == Mon || dayOfWeek == Tue|| dayOfWeek == Wed|| dayOfWeek == Thur|| dayOfWeek == Fri))
                {
                    cs.Dist_Hours__c = B_BusinessHours.getTimeDifferenceInMinutes(
                        cs.CreatedDate,
                        cs.LastModifiedDate,
                        businessHoursId);
                    
                    Decimal mydecval = cs.Dist_Formula__c;
                   
                    Integer myintval = mydecval.intValue();
                    system.debug('myintvalmyintvalmyintval'+myintval);
                    cs.Dist__c= B_BusinessHours.addMinutes(
                        myintval,
                        businessHoursId);
                }
                else if (dayOfWeek == Mon)
                {
                    cs.Dist__c= DateTime.newInstance(myDate,bh.MondayEndTime); 
                }
                else if(dayOfWeek == Tue)
                {
                    cs.Dist__c=  DateTime.newInstance(myDate,bh.TuesdayEndTime) ;
                }
                else if(dayOfWeek == Wed)
                {
                    cs.Dist__c=  DateTime.newInstance(myDate,bh.WednesdayEndTime) ;
                }
                else if(dayOfWeek == Thur)
                {
                    cs.Dist__c=  DateTime.newInstance(myDate,bh.ThursdayEndTime) ;
                  
                }
                else if(dayOfWeek == Fri)
                {
                    cs.Dist__c=  DateTime.newInstance(myDate,bh.FridayEndTime) ;
                }
                else if(dayOfWeek == Sat)
                {
                    Date satdate = myDate- 1;
                    cs.Dist__c=  DateTime.newInstance(satdate,bh.FridayEndTime) ;
                }
                else if(dayOfWeek == Sun)
                {
                    Date Sundate=myDate- 2;
                    cs.Dist__c=  DateTime.newInstance(Sundate,bh.FridayEndTime) ;
                }**
                
            }
            
            if(cs.Process__c=='Verify' && cs.Verify_Date__c== null)
            {
                
                if(isWithin==true && (dayOfWeek == Mon || dayOfWeek == Tue|| dayOfWeek == Wed|| dayOfWeek == Thur|| dayOfWeek == Fri))
                { 
                    
                    cs.Date_Hours__c= B_BusinessHours.getTimeDifferenceInMinutes(
                        cs.CreatedDate,
                        cs.LastModifiedDate,
                        businessHoursId);
                    
                    Decimal mydecval = cs.Date_Formula__c;
                  
                    Integer myintval = mydecval.intValue();
                   
                    cs.Verify_Date__c= B_BusinessHours.addMinutes(
                        myintval,
                        businessHoursId);
                }
                
                **else if (dayOfWeek == Mon)
                {
                    cs.Verify_Date__c = DateTime.newInstance(myDate,bh.MondayEndTime); 
                }
                else if(dayOfWeek == Tue)
                {
                    cs.Verify_Date__c =  DateTime.newInstance(myDate,bh.TuesdayEndTime) ;
                }
                else if(dayOfWeek == Wed)
                {
                    cs.Verify_Date__c =  DateTime.newInstance(myDate,bh.WednesdayEndTime) ;
                }
                else if(dayOfWeek == Thur)
                {
                    cs.Verify_Date__c =  DateTime.newInstance(myDate,bh.ThursdayEndTime) ;
                   
                }
                else if(dayOfWeek == Fri)
                {
                    cs.Verify_Date__c =  DateTime.newInstance(myDate,bh.FridayEndTime) ;
                }
                else if(dayOfWeek == Sat)
                {
                    Date satdate = myDate- 1;
                    cs.Verify_Date__c =  DateTime.newInstance(satdate,bh.FridayEndTime) ;
                }
                else if(dayOfWeek == Sun)
                {
                    Date Sundate=myDate- 2;
                    cs.Verify_Date__c =  DateTime.newInstance(Sundate,bh.FridayEndTime) ;**
                } 
                
            }
            
            if(cs.Process__c=='Preparation' && cs.Preparation_Date__c== null)
            {
                
                if(isWithin==true && (dayOfWeek == Mon || dayOfWeek == Tue|| dayOfWeek == Wed|| dayOfWeek == Thur|| dayOfWeek == Fri))
              {
                
                cs.Preparation_Date_Hours__c= B_BusinessHours.getTimeDifferenceInMinutes(
                    cs.CreatedDate,
                    cs.LastModifiedDate,
                    businessHoursId);
                
                Decimal mydecval = cs.Preparation_Date_Formula__c;
                
                Integer myintval = mydecval.intValue();
                
                cs.Preparation_Date__c = B_BusinessHours.addMinutes(
                    myintval,
                    businessHoursId);
                
            }
            
            else if (dayOfWeek == Mon)
            {
                **cs.Preparation_Date__c = DateTime.newInstance(myDate,bh.MondayEndTime);** 
            }
            else if(dayOfWeek == Tue)
            {
                **cs.Preparation_Date__c =  DateTime.newInstance(myDate,bh.TuesdayEndTime) ;**
            }
            else if(dayOfWeek == Wed)
            {
                **cs.Preparation_Date__c =  DateTime.newInstance(myDate,bh.WednesdayEndTime) ;**
            }
            else if(dayOfWeek == Thur)
            {
                cs.Preparation_Date__c =  DateTime.newInstance(myDate,bh.ThursdayEndTime) ;
               
            }
            **else if(dayOfWeek == Fri)
            {
                cs.Preparation_Date__c =  DateTime.newInstance(myDate,bh.FridayEndTime) ;
            }
            else if(dayOfWeek == Sat)
            {
                Date satdate = myDate- 1;
                cs.Preparation_Date__c =  DateTime.newInstance(satdate,bh.FridayEndTime) ;
            }
            else if(dayOfWeek == Sun)
            {
                Date Sundate=myDate- 2;
                cs.Preparation_Date__c =  DateTime.newInstance(Sundate,bh.FridayEndTime) ;**
            } 
            
          }
            
        }
        
    }
    
    public static Id businessHoursId
    {
        get
        {
            if (businessHoursId == null)
            {
                businessHoursId = B_BusinessHours.getBusinessHoursId();
            }
            return businessHoursId;
        }
        set;
    }
}


Below is my Test class.

        @isTest
    public class Case_Test{
    
    Public static testMethod void Test_method() 
    {
    
      Id recordtyepe= Schema.SObjectType.Case.getRecordTypeInfosByName().get('- L - QNA').getRecordTypeId();
      Id recordtyepes= Schema.SObjectType.Case.getRecordTypeInfosByName().get('UW - L - QNA').getRecordTypeId();
      List<BusinessHours> bhs=[select id from BusinessHours where IsDefault=true];
     
      case c = new case();
      c.Origin='email';
      c.Status='Assigned';
      c.RecordtypeId= recordtyepe;
      c.Process__c='Verify';
      c.Process__c= 'Preparation';
      insert c;
      c.Process__c='Preparation';
      c.Process__c='Verify';
      c.RecordtypeId =recordtyepes;
      Test.setCreatedDate(c.Id,  datetime.newInstance(2019, 11, 11, 11, 30, 0));
       Test.startTest();
       case cs= [SELECT Id, CreatedDate,LastModifiedDate FROM case  where origin='email' limit 1];
       System.assertEquals(cs.CreatedDate,  DateTime.newInstance(2019,11,11,11,30,0));
       Test.stopTest();
       update c;
     
    }
    }

 
Hi Experts,

I have requirment i need create a button(not java script button because i cant use in lighting) when i click on that button new record page has to open and also i want set a default value in that new record page, can anyone hlep me please.
Hi Experts,

Can anyone help me how out, how to the stop the triggers not to fire any profile using custom setting. Thanks in advance
Hi Experts,

We have requirment where we need to replace Opportunity Proudct with the standard object oportunity product object, so i have edited entire controller code
but problem here is that when i replace stadnardcontroller with the OpportunityLineItem in the visualforce page its not allowing me to work its throwing an error called "Error: List controllers are not supported for OpportunityLineItem    ", 
can anyone help me out, how to fix this issue. 
 
Vf page: 
<apex:page standardController="Product__c" recordSetVar="oppProds" extensions="ProductController" showHeader="false" standardStylesheets="true" sidebar="false"
  docType="html-5.0">
   
    <body>
        <apex:form id="frm">
            <div align="center">
                <div class="h1Div" >
                    <input type="button" id="btnBack1" value="Back" class="sf1buttonSFBlue backButtonControlClass" onClick="javascript: goBack();" style="float: left;margin-top: -5px;margin-right: 15px;height: 35px;"/>
                    <h1>Opportunity Products</h1>
                    <img src="{!$Resource.SF1HeaderLogoSmall}" style="float:right;width: 100px;"/>
                </div>
                <br/>
                <apex:pageMessages id="MESSAGES"/>
            </div>
            
            <div class="sf1divBlock">
                <div class="sf1headerLabel">
                    <apex:outputLabel value="{!cOpp.Name}" style="margin-left: 5px;"/>
                </div>
                <br/>
                <apex:outputPanel id="OPPPRODPANEL">
                    <table id="OPPPRODTABLE" class="sf1Table" style="width:100%;">
                        <thead>
                            <tr>
                                <th width="50%"> Product </th>
                                <th width="12%"> Include in next quote </th>
                                <th width="22.5%"> Quantity </th>
                                <th width="22.5%"> Requested Price </th>
                                <th class="DMLActions" width="5%"> Action </th>
                            </tr>
                        </thead> 
                        <tbody>
                            <apex:variable var="rowClass" value="odd"/>
                            <apex:variable var="rowNum" value="{!0}"/> 
                            <apex:repeat value="{!clstOppProds}" var="oppProd">
                                <tr class="{!rowClass}">
                                    <td>
                                        <div class="scrollable-dropdown-menu">
                                            <input type="text" id="prodName{!rowNum}" name="prodName{!rowNum}" class="sf1Input"/>
                                        </div>
                                        <script>
                                            //Initialize the type ahead
                                            var prodName{!rowNum} = jQuery('#prodName{!rowNum}');
                                            if(prodName{!rowNum}){
                                                prodName{!rowNum}.typeahead(
                                                    {
                                                        minLength: 3,
                                                        highlight: true
                                                    },
                                                    {
                                                        limit: 999,
                                                        display: 'value',
                                                        source: function(searchText, syncCallback, asyncCallback) {
                                                            searchText = searchText.split('\\').join('\\\\');
                                                            searchText = searchText.split('\'').join('\\\'');
                                                            var sObj = new SObjectModel.Product2();
                                                            sObj.retrieve({ 
                                                                where:{
                                                                    or:{
                                                                        Name: {like: searchText + '%'},
                                                                        or:{
                                                                            Description: {like: searchText + '%'},
                                                                            Product2: {like : searchText + '%'}
                                                                        }
                                                                    },
                                                                    and:{
                                                                        Active__c: {eq: true},
                                                                        or:{
                                                                            RecordTypeId: {eq: '{!ProductRTId}'},
                                                                            and:{
                                                                                Status__c: {eq: 'Approved'},
                                                                                Product__c: {eq: ''}
                                                                            }
                                                                        }
                                                                    }
                                                                },
                                                                orderby: [{Name: 'ASC'}],
                                                                limit:999},
                                                                function(err,records){
                                                                    if(err){
                                                                        alert(err);
                                                                    } else {
                                                                        var dataList = [];
                                                                        var maxLength = 1;
                                                                        jQuery.each(records, function(index, record){
                                                                            dataList.push({
                                                                                id: record.get('Id'),
                                                                                value: jQuery('<div/>').html(record.get('Name')).text(),
                                                                                code: jQuery('<div/>').html(record.get('Type_Code__c')).text(),
                                                                                desc2: jQuery('<div/>').html(record.get('Description')).text()
                                                                            });
                                                                        });
                                                                        asyncCallback(dataList);
                                                                    }
                                                                }
                                                            ) 
                                                        },
                                                        templates: {
                                                            suggestion: function (data) {
                                                                var desc = data.value;
                                                                if(data.desc2) desc += ' - ' + data.desc2;
                                                                return '<div><table class="tt-table"><tr><td class="tt-table-td1">' + desc + '</td><td class="tt-table-td2">' + data.code + '</td></tr></table></div>';
                                                            }
                                                        }
                                                    }
                                                ).on('typeahead:selected', function (object, datum) {
                                                    setProd({!rowNum},datum.id,datum.value);
                                                }).on('typeahead:autocompleted', function (object, datum) {
                                                    setProd({!rowNum},datum.id,datum.value);
                                                }).on('typeahead:change', function (event, data) {
                                                    //Reset the fields to blank
                                                    
                                                });
                                            }
                                            prodName{!rowNum}.typeahead('val', '{!JSENCODE(oppProd.Product__r.Name)}');
                                        </script>
                                    </td>
                                    
                                    <td>
                                        <apex:inputField value="{!oppProd.Next_Quote__c}" style="width:30px; height:20px;"/>
                                    </td>
                                    <td>
                                        <apex:inputField value="{!oppProd.Quantity__c}" styleClass="sf1Input"/>
                                    </td>
                                    <td>
                                        <apex:inputField value="{!oppProd.Price__c}" styleClass="sf1Input"/>
                                    </td>
                                    <td valign="top" class="DMLActions">
                                        <input type="button" id="btnDelete{!oppProd.id}" class="sf1buttonDelete" value="" onClick="removeRow('{!rowNum}');" />
                                    </td>
                                </tr>
                                <apex:variable var="rowClass" value="{!IF(rowClass == 'odd','','odd')}"/> 
                                <apex:variable var="rowNum" value="{!rowNum + 1}"/> 
                            </apex:repeat>
                        </tbody>
                    </table>
                </apex:outputPanel>
                <table class="sf1InputTableTwoCol">
                    <tr>
                        <td>
                            <input type="button" id="btnBack" class="sf1buttonSFBlue" value="Back" onClick="goBack();" />
                            <input type="button" id="btnAddNew" class="sf1buttonSFBlue" value="Add New" onClick="addNew();" />
                            <input type="button" id="btnSave" class="sf1buttonSFBlue" value="Save" onClick="doSave();" />
                        </td>
                    </tr>
                </table>
            </div>
            
            <apex:actionFunction name="setProd" action="{!setProd}" reRender="MESSAGES" status="status">
                <apex:param name="p1" value="" assignTo="{!selectedRowNum}"/>
                <apex:param name="p2" value="" assignTo="{!selectedRowProdId}"/>
                <apex:param name="p3" value="" assignTo="{!selectedRowProdName}"/>
            </apex:actionFunction>
            <apex:actionFunction name="removeRow" action="{!removeRow}" reRender="MESSAGES,OPPPRODPANEL" status="status">
                <apex:param name="p1" value="" assignTo="{!selectedRowNum}"/>
            </apex:actionFunction>
            <apex:actionFunction name="goBack" action="{!cancel}" reRender="MESSAGES" status="status"/>
            <apex:actionFunction name="doSave" action="{!doSave}" reRender="MESSAGES" status="status"/>
            <apex:actionFunction name="addNew" action="{!addNew}" reRender="MESSAGES,OPPPRODPANEL" status="status"/>
            
            <apex:actionstatus id="status">
                <apex:facet name="start">
                    <div class="waitingSearchDiv" id="el_loading" style="background-color: #fbfbfb;height: 100%;opacity:0.65;width:100%;">
                        <div class="waitingHolder" style="top:220px;">
                            <img class="waitingImage" src="{!$Resource.Salesfroce1Loading}" title="Processing..." />
                        </div>
                    </div>
                </apex:facet> 
            </apex:actionstatus>
        </apex:form>
    </body>
</apex:page>


Apex class:

public class ProductController {
    public Opportunity cOpp {get;set;}
    public Integer selectedRowNum {get;set;}
    public String selectedRowProdId {get;set;}
    public String selectedRowProdName {get;set;}
    public List<OpportunityLineItem> clstOppProds {get;set;}
    public List<OpportunityLineItem> clstDelOppProds {get;set;}
    public String getJDEProductRTId(){
        return [SELECT Id FROM RecordType WHERE SObjectType = 'Product2' AND Name = 'New Products' LIMIT 1].get(0).Id;
    }
	
	   public ProductController(ApexPages.StandardSetController ssc) {
        selectedRowNum = null;
        selectedRowProdId = null;
        selectedRowProdName = null;
        String oppId = ApexPages.currentPage().getParameters().get('id');
        cOpp = null;
        for(Opportunity o : [SELECT Id,Name FROM Opportunity WHERE Id = :oppId]) cOpp = o;
        clstOppProds = new List<OpportunityLineItem>();
        clstDelOppProds = new List<OpportunityLineItem>();
        if(oppId != null) clstOppProds = [SELECT Id,Opportunityid,Next_Quote__c,Product2id,Product2.Name,Quantity__c,Price__c FROM OpportunityLineItem WHERE Opportunityid = :oppId];
    }
	
	 public PageReference setProd(){
         PageReference pg = null;
         OpportunityLineItem op = clstOppProds.get(selectedRowNum);
         Product2 pt = new Product2(id=selectedRowProdId,name=selectedRowProdName);
         op.Product2id = selectedRowProdId;
         op.Product2.Name = pt.Name;
         return pg;
     }
	 
	 public PageReference removeRow(){
         PageReference pg = null;
         OpportunityLineItem op = clstOppProds.remove(selectedRowNum);
         if(op.Id != null) clstDelOppProds.add(op);
         return pg;
     }
	 
	   public PageReference addNew(){
         PageReference pg = null;
         clstOppProds.add(new OpportunityLineItem(Opportunityid=cOpp.Id));
         return pg;
     }
	 public PageReference doSave(){
         PageReference pg = null;
         SavePoint sp = Database.setSavePoint();
         try{
             delete clstDelOppProds;
             upsert clstOppProds;
             pg = new PageReference('/'+cOpp.Id);
         }catch(Exception e){
             Database.rollback(sp);
             Apexpages.addMessage(new Apexpages.Message(Apexpages.Severity.ERROR, e.getMessage()));
         }
         return pg;
     }
}

 
Hi Experts,

I have small requirement where i need to filter a long text area field called Desc__c which i am not able to do that can anyone help me please.

OrderItem oli1 = new OrderItem ();
        oli1.Orderid = order.Id;
        oli1.Desc__c= 'Test OLI 1'; 
      insert oli1;


 OrderItem oli2 = [SELECT Id, Orderid
                    FROM OrderItem WHERE  Desc__c = 'Test OLI 1' LIMIT 1];

In this filter condition its throwing an error can anyone help me please thanks in adavance
Hi Experts,

Can anyone helps me , while running my test class i am getting below error. Below is my code anyone help  me please. the area which i made bold in the insert command i receiving this can anyone helps me please.

DUPLICATE_VALUE, This price definition already exists in this price book: []   


Account a = new Account(Name='testAccount',RecordTypeId = Schema.SObjectType.Account.getRecordTypeInfosByName().get('Customer').getRecordTypeId()); //Added by Purnima for Story S-562343
         insert a; 
        
        Id pricebookId = Test.getStandardPricebookId();
        
        Product2 prod = new Product2(Name = 'Laptop X200', 
                                     Family = 'Hardware');
        insert prod;
        
     
        
        /*PricebookEntry standardPrice = new PricebookEntry(
            Pricebook2Id = pricebookId, Product2Id = prod.Id,
            UnitPrice = 10000, IsActive = true);
        insert standardPrice;*/
        
        PriceBookEntry stdPriceBookEntry = new PriceBookEntry();
        stdPriceBookEntry.Product2Id=prod.Id;
        stdPriceBookEntry.Pricebook2Id=pricebookId;
        stdPriceBookEntry.UnitPrice=2000;
        stdPriceBookEntry.IsActive=true;
        insert stdPriceBookEntry;

        
        Pricebook2 customPB = new Pricebook2(Name='Custom Pricebook', isActive=true);
        insert customPB;
        
        PricebookEntry customPrice = new PricebookEntry(
            Pricebook2Id = customPB.Id, Product2Id = prod.Id,
            UnitPrice = 12000, IsActive = true);
        insert customPrice;
         Product_Type__c productType = new Product_Type__c();        
        productType.Product_Type_Code__c = 'End';
      
        insert productType;
        
        
        Opportunity opp = new Opportunity(Name='Test', 
                                          Account = a, 
                                         // Product__c='GRI Retail',
                                          NextStep='test',
                                          PriceBook2 = customPB,
                                          CloseDate = System.today(),
                                          AccountId=a.Id, 
                                         // Opportunity_Name__c='testOpp',
                                         // Product_Family__c='Retail',
                                        Industry__c='Other',
                                        Description='TestTestTest',
                                          StageName='Closed Won - One Time' 
                                          );
       
       insert opp; 
        
    
     
    List<Opportunity_Product__c> oppProdList = new List<Opportunity_Product__c>();
     for(Integer i=1;i<=10;i++)
     oppProdList.add(new Opportunity_Product__c (Opportunity__c = opp.Id,Product__c = productType.id));
     
     System.debug('test@@@'+ oppProdList );
        
        insert oppProdList;
        
        

     
     
     ApexPages.StandardSetController sc = new ApexPages.StandardSetController(oppProdList);
    
     
    
      PageReference pageRef = Page.OpportunityProducts;
        pageRef.getParameters().put('id', String.valueOf(''));
        Test.setCurrentPage(pageRef);
    
    
    //Test.setCurrentPageReference(Page.OpportunityProducts);
    
    OpportunityController obj= new OpportunityController(sc);
    obj.selectedRowNum=1;
    obj.selectedRowProdId=productType.id;
    obj.selectedRowProdName=productType.Name;
    obj.cOpp=opp;
    List<Opportunity_Product__c> testopp= new List<Opportunity_Product__c>();
    obj.clstOppProds=oppProdList;
    List<Opportunity_Product__c> testOpps= new  List<Opportunity_Product__c>();
    obj.clstDelOppProds=oppProdList;
    
    obj.getJDEProductRTId();
   
    //Product_Type__c pt = new Product_Type__c(id='test', name='test');
    System.debug('clstOppProds==>' + obj.clstOppProds);
        System.debug('clstDelOppProds==>' + obj.clstDelOppProds);
    
    PageReference pg = obj.doSave(); 
    PageReference pg1 = obj.addNew(); 
    //PageReference pg3 = obj.setProd();
    PageReference pg2 = obj.removeRow();