• System Admin 949
  • NEWBIE
  • 0 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 13
    Questions
  • 14
    Replies

Hi,
iam tried to create the test class for this below apex class but facing some issue,can any one provide some code how to write the test class for this .
apex class:
public class CustomerProductListController
{
    @AuraEnabled
    public static List<CustomerProduct__c> getProductNotes(Id meetingRecId)
    {
        List<RecordType> rtypes = [Select Id From RecordType where Name='Customer Product' AND SobjectType = 'CustomerProduct__c'];
        List<CustomerProduct__c> pdtNoteList =  [SELECT Id, Product__r.Id,Product__r.Name, MeetingNotes__c,MeetingId__c
            FROM CustomerProduct__c  
            WHERE MeetingId__c =: meetingRecId AND RecordTypeId =: rtypes.get(0).Id
            ORDER BY createdDate DESC];
      for(CustomerProduct__c cpRec : pdtNoteList)
      {
          if(cpRec.MeetingNotes__c!=Null)
          {
               cpRec.MeetingNotes__c = cpRec.MeetingNotes__c.replaceAll('<[^>]+>',' ');
          }
           
      }
      
      System.debug('**********'+pdtNoteList);
      
      return pdtNoteList;
  }    

}

thanks.

Hi all,
I created the lightning component for clone the quote record .i added this component in vf page and call that vf page through custom button.
but its not working.any one can guide me how to do this.my  code is
apex controller
public class QuoteController { 
  
  @AuraEnabled  
    public static Quote getDetailsFromQuote(string recordId){
       Quote q = [select Id,Name,AccountId,ContactId,OpportunityId
        from Quote Where Id = :recordId limit 1];
       return q;
    }
 }

component

<aura:component controller="QuoteController" implements="force:lightningQuickActionWithoutHeader,lightning:actionOverride">
    
    <meta name="viewport" condoInittent="width=device-width, initial-scale=1.0"/>
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />
    <aura:attribute name="recordId" type="Id" />
    <aura:attribute name="QuoteName" type="String" />
    <aura:attribute name="account" type="String" />
    <aura:attribute name="contact" type="String" />
    <aura:attribute name="opportunity" type="String" />
  
     <aura:dependency resource="c:createRecord"/>
    <!-- Load the navigation events in the force namespace. -->
    <aura:dependency resource="markup://force:*" type="EVENT"/>
    
</aura:component>

controller.js

({
    doInit: function(component,  event, helper) {
      var recordId = component.get("v.recordId");
        if(recordId!=undefined){
        alert(recordId);
        var action = component.get("c.getDetailsFromQuote");
        action.setParams({
            recordId: recordId
        });
        action.setCallback(this, function(response){
            var state = response.getState();
           
            if (state === "SUCCESS") {
                var q = response.getReturnValue();
                component.set("v.QuoteName", q.Name); 
                component.set("v.account", q.AccountId);
                component.set("v.contact", q.ContactId);
                component.set("v.opportunity", q.OpportunityId);
                helper.createQuoteRecord(component, event, helper);
              
            }
           
        });
        
        $A.enqueueAction(action);
        }
    },
     createQuoteRecord : function (component, event, helper) {
       var name=  component.get("v.QuoteName"); 
       var account = component.get("v.account"); 
        var contact=  component.get("v.contact");
         var opportunity= component.get("v.opportunity");
        // alert(picklist);
       //  alert(campaign);
    var createQuoteEvent = $A.get("e.force:createRecord");
    createQuoteEvent.setParams({
    "entityApiName": "Quote",
    "defaultFieldValues": {
        'Name' : 'New Quote',
        'AccountId' : account,
        'ContactId' : contact,
        'OpportunityId' : opportunity
        }
    });
    createQuoteEvent.fire();
    },
    
})
helper.js
({
     doInit: function(component, event, helper) {
      //call the helper function with pass [component, Controller field and Dependent Field] Api name 
     // alert('Hi');
      helper.doInit(component, event, helper);
   },
   
})

lightning app

<aura:application access="GLOBAL" extends="ltng:outApp">
    <aura:dependency resource="c:QuoteComponent"/>
</aura:application>

vf page

<!--<apex:page standardController="Quote"
     extensions="QuoteCloneController" action="{!cloneWithItems}">
    
     <apex:pageMessages />
</apex:page>-->

 <apex:page >
 <apex:includeLightning />

 <div style="width:30%;height:100px;" id="FlipcardContainer" />

 <script>
 $Lightning.use("c:QuoteApp", function() {
 $Lightning.createComponent("c:QuoteComponent",
 { 
 borderColor : "#16325c", 
 bgColor : "#16325c" ,
 fontColor : "#FFF",
 frontText : "What's cool about Lightning Component Development",
 backText : "You dont need to enable Lightning experience, It will work on Classic Instance as well"
 },
 "FlipcardContainer",
 function(cmp) {
 console.log('Component created, do something cool here');
 });
 });
 </script>
</apex:page>
very urgent for this clone button.any one can provide the solution.
thanks in advance
   
Hi all,
I am creating the Clone button for Quote object in Lightning.the clone  button is working fine but after saving the record it won't get back to the newly created record.can any one suggest where am i getting wrong. it is redirected fine but creates two records one newly cloned record and one more is again same old record.
for example i have one record 'abc',i want to clone this and given name 'sample' and save the record.in records it will show 3 records.
abc,abc,sample.how to rectify this.i hope you understand.
my sample code is
apex class

/*public class QuoteCloneController {
    
    //added an instance varaible for the standard controller
    private ApexPages.StandardController controller {get; set;}
     // add the instance for the variables being passed by id on the url
    Quote po {get;set;}
    // set the id of the record that is created -- ONLY USED BY THE TEST CLASS
    public ID newRecordId {get;set;}

    // initialize the controller
    public QuoteCloneController(ApexPages.StandardController controller) {

        //initialize the stanrdard controller
        this.controller = controller;
        // load the current record
        po = (Quote)controller.getRecord();

    }

    // method called from the VF's action attribute to clone the po
    public PageReference cloneWithItems() {

         // setup the save point for rollback
         Savepoint sp = Database.setSavepoint();
         Quote newPO;

         try {

              //copy the Quote - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE
             po = [select Id, Name, AccountId,OpportunityId,ContactId,Sales_Price__c,Payment_Terms__c,Pricebook2Id  from Quote where id = :po.id];
             newPO = po.clone(false);
             insert newPO;

             // set the id of the new po created for testing
             // newRecordId = newPO.id;

             // copy over the line items - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE
             List<QuoteLineItem> items = new List<QuoteLineItem>();
             for (QuoteLineItem pi : [Select p.QuoteId, p.Product2Id, p.Subtotal, p.ListPrice, p.Quantity,p.UnitPrice,p.PricebookEntryId,p.OpportunityLineItemId From QuoteLineItem p where QuoteId = :po.id]) {
                  QuoteLineItem newPI = pi.clone(false);
                  newPI.QuoteId = newPO.id;
                  items.add(newPI);
             }
             insert items;

         } catch (Exception e){
             // roll everything back in case of error
            Database.rollback(sp);
            ApexPages.addMessages(e);
            return null;
         }

        return new PageReference('/'+newPO.Id+'/e?retURL=%2F'+newPO.Id);
        //return new PageReference('/'+newPO.id+'/e?retURL=%2F');
        
         
        
    }

}*/








public class QuoteCloneController {
    
    //added an instance varaible for the standard controller
    private ApexPages.StandardController controller {get; set;}
     // add the instance for the variables being passed by id on the url
    Quote po {get;set;}
    // set the id of the record that is created -- ONLY USED BY THE TEST CLASS
    public ID newRecordId {get;set;}

    // initialize the controller
    public QuoteCloneController(ApexPages.StandardController controller) {

        //initialize the stanrdard controller
        this.controller = controller;
        // load the current record
        po = (Quote)controller.getRecord();

    }

    // method called from the VF's action attribute to clone the po
     public PageReference cloneWithItems() {

         // setup the save point for rollback
         Savepoint sp = Database.setSavepoint();
         Quote newPO;

         try {

              //copy the Quote - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE
             po = [select Id, Name, AccountId,OpportunityId,ContactId,Sales_Price__c,Payment_Terms__c,Pricebook2Id  from Quote where id = :po.id];
             newPO = po.clone(false);
             insert newPO;

             // set the id of the new po created for testing
               newRecordId = newPO.id;
         } catch (Exception e){
             // roll everything back in case of error
            System.debug('Error'+e);
            Database.rollback(sp);
            ApexPages.addMessages(e);
            return null;
         }

        //return new PageReference('/'+newPO.id+'/e?retURL=%2F'+newPO.id);
         return new PageReference('/'+newPO.id+'/e?clone=1');

    }

}
vf page
<apex:page standardController="Quote"
     extensions="QuoteCloneController" action="{!cloneWithItems}">
    
     <apex:pageMessages />
</apex:page>
thanks in advance.
Hi all,
I am creating the Clone button for Quote object in Lightning.the clone  button is working fine but after saving the record it won't get back to the newly created record.can any one suggest where am i getting wrong.my sample code is
apex class
public class QuoteCloneController {
    
    //added an instance varaible for the standard controller
    private ApexPages.StandardController controller {get; set;}
     // add the instance for the variables being passed by id on the url
    Quote po {get;set;}
    // set the id of the record that is created -- ONLY USED BY THE TEST CLASS
    public ID newRecordId {get;set;}

    // initialize the controller
    public QuoteCloneController(ApexPages.StandardController controller) {

        //initialize the stanrdard controller
        this.controller = controller;
        // load the current record
        po = (Quote)controller.getRecord();

    }

    // method called from the VF's action attribute to clone the po
    public PageReference cloneWithItems() {

         // setup the save point for rollback
         Savepoint sp = Database.setSavepoint();
         Quote newPO;

         try {

              //copy the Quote - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE
             po = [select Id, Name, AccountId,OpportunityId,ContactId,Sales_Price__c,Payment_Terms__c,Pricebook2Id  from Quote where id = :po.id];
             newPO = po.clone(false);
             insert newPO;

             // set the id of the new po created for testing
               newRecordId = newPO.id;

             // copy over the line items - ONLY INCLUDE THE FIELDS YOU WANT TO CLONE
             List<QuoteLineItem> items = new List<QuoteLineItem>();
             for (QuoteLineItem pi : [Select p.QuoteId, p.Product2Id, p.Subtotal, p.ListPrice, p.Quantity,p.UnitPrice,p.PricebookEntryId,p.OpportunityLineItemId From QuoteLineItem p where QuoteId = :po.id]) {
                  QuoteLineItem newPI = pi.clone(false);
                  newPI.QuoteId = newPO.id;
                  items.add(newPI);
             }
             insert items;

         } catch (Exception e){
             // roll everything back in case of error
            Database.rollback(sp);
            ApexPages.addMessages(e);
            return null;
         }

        //return new PageReference('/'+newPO.id+'/e?retURL=%2F'+newPO.id);
        return new PageReference('/'+newPO.id+'/e?retURL=%2F');
    }

}
vf page
<apex:page standardController="Quote"
     extensions="QuoteCloneController"
     action="{!cloneWithItems}">
     <apex:pageMessages />
</apex:page>

thanks in advance
Hi All,
I have two objects one Customer and Quote.Customer is the Parent and Quote is Child.I have a picklist field in Customer i.e. Country it has some values like Ind,US,UK,Europe....etc.In Quote object also have picklist field called SalesType,it has some values.
My Scenario is when iam selecting the Country as 'Ind' in Customer object at that time the picklist field in Quote object as SalesType should be visible.if i select any picklist value in Customer except 'Ind' it should be read only .
how to achieve this??can any one suggest or provide some examples on this.
t​​​​​​​hanks in advance
 
Hi All,
In Lightning and Classic standard Quote object detail page 'clone' button is not visible.i checked in page layouts also but the button is not visible.
Is the Clone button visible in Lightning/Classic??if it is not visible anty one can provode the sample code for creating the clone button with fields.
thanks in advance
Dear Community,
I have two Objects ProductFamily__c and PlantContact__c.ProductFamily is parent and PlantContact is child.i have email fields in both objects like AR&D,Commercial,DQA,Marketing,Pilot,Production,QA,QC,R&D..etc.also one checkbox field called 'Default ' in PlantContact object.
and  to fill ProductFamily Email Fields  based on the default value on PlantContact for that type.
use trigger/Process builder shall be involed every time a plant contact is created or updated with default = true, action will then be to find the corresponding product family record and update the relevant email field based on type of plant contact that is being set default.If default=false put null value in the corresponding fields of ProductFamily.For each type in PlantContact put only one default value to the corresponding ProductFamily.
For example ProductFamily reocrd is PF-0001 and it is has only one default record like  AR&D,R&D,QA,QC,..etc child records.If the user try to add one more record for above types as default it will throws error.if the above types are don't select default=true put blank/null values in corresponding ProductFamily Record.
thanks in Advance