-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
13Questions
-
14Replies
test trigger problem
below is the my trigger,iam facing some problem for creation of test class.how to create the testfactory for this trigger
trigger:
trigger CheckDefaultPlantContact on PlantContact__c (before insert,before update)
{
Set<String> contactTypeSet = new Set<String>();
Set<String> prodFamilySet = new Set<String>();
Map<String, PlantContact__c> productPlanMap = new Map<String, PlantContact__c>();
For(PlantContact__c p : Trigger.New)
{
If(p.TypeOfContact__c != null)
{
contactTypeSet.add(p.TypeOfContact__c);
}
If(p.ProductFamily__c != null)
{
prodFamilySet.add(p.ProductFamily__c);
}
}
For(PlantContact__c p :[SELECT Id, TypeOfContact__c,ProductFamily__c FROM PlantContact__c WHERE TypeOfContact__c =:contactTypeSet AND Default__c = TRUE AND ProductFamily__c =: prodFamilySet])
{
productPlanMap.put(p.TypeOfContact__c+'-'+p.ProductFamily__c, p);
}
For(PlantContact__c p : Trigger.New)
{
String keyChek = p.TypeOfContact__c+'-'+p.ProductFamily__c;
If(!productPlanMap.containsKey(keyChek))
{
IF(!p.Default__c)
{
p.name.addError('Please Mark as Default. There should be one default Contact for type '+ p.TypeOfContact__c);
}
}
IF(p.Default__c)
{
If(productPlanMap.containsKey(keyChek))
{
p.name.addError('One Product Family have only one Default for each '+ p.TypeOfContact__c +' type');
}
}
}
}
can any one provide hoew to create the test class for this.
thanks in advance
-
- System Admin 949
- October 04, 2018
- Like
- 0
- Continue reading or reply
Testclass for Apex
i am facing some problem for writing the test class for below apex class,can any provide sample code for this to write the test class
apex class
public class ProductNoteListController {
@AuraEnabled
public static List<CustomerProduct__c> getProductNotes(Id meetingRecId) {
List<CustomerProduct__c> pdtNoteList = [SELECT Id, Product__r.Id,Product__r.Name, MeetingNotes__c,MeetingId__c,RecordType.DeveloperName
FROM CustomerProduct__c
WHERE MeetingId__c =: meetingRecId
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;
}
@AuraEnabled
public static void updateCustProdRT(Id recordId)
{
try
{
List<RecordType> rtypes = [Select Id From RecordType where Name='Customer Product' AND SobjectType = 'CustomerProduct__c'];
CustomerProduct__c CP = [select id from CustomerProduct__c WHERE Id=:recordId];
CP.RecordTypeId=rtypes.get(0).Id;
update CP;
}
catch(DmlException ex)
{
throw new AuraHandledException(ex.getMessage());
}
}
}
thanks in advance
-
- System Admin 949
- October 04, 2018
- Like
- 0
- Continue reading or reply
Test class in Lightning
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.
-
- System Admin 949
- October 03, 2018
- Like
- 0
- Continue reading or reply
login failed on trailhead
I am try to connect to trailhead from last day onwards.it will through error you are not authorised user.i am using proper user name and password,but unable to login ot trail head.any one give can give solution.
thanks
-
- System Admin 949
- September 27, 2018
- Like
- 0
- Continue reading or reply
Clone Button not working in Lightning Components
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
-
- System Admin 949
- September 25, 2018
- Like
- 0
- Continue reading or reply
Creating the Clone Button using Lightning Components
I am new to the Lightning Components,can any one provide the sample code for creating the custom clonebutton for Quote object.
how to learn the lightning components deeply,can any one provide the lightning blogs.
thanks in advance
-
- System Admin 949
- September 24, 2018
- Like
- 0
- Continue reading or reply
Generating the Pdf using Lightning Components
I am trying to create the pdf form for using Quote/any object details in salesforce.for this i am using lightning components.I am new to the lightning components.can any one provide the lightning material to learn lightning components perfectly.can provide the some sample code to create the lighting components to generate the Pdf for Quote object.
thanks in advance
-
- System Admin 949
- September 24, 2018
- Like
- 0
- Continue reading or reply
Clone Button Not Working
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.
-
- System Admin 949
- September 24, 2018
- Like
- 0
- Continue reading or reply
Custom Clone button using Apex
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
-
- System Admin 949
- September 21, 2018
- Like
- 0
- Continue reading or reply
Make a Picklist Field Read Only based on another Object Picklist Value
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.
thanks in advance
-
- System Admin 949
- September 21, 2018
- Like
- 0
- Continue reading or reply
Standard Clone Button on Quote Object
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
-
- System Admin 949
- September 19, 2018
- Like
- 0
- Continue reading or reply
Update Email Fields in Related Objects
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
-
- System Admin 949
- September 18, 2018
- Like
- 0
- Continue reading or reply
Picklists update using Trigger
I have two objects Account and Custom Object.Account is the parent and Custom object is child.Account has the picklist field called country and it has some values like Ind,US,UK,Europe,..etc.And Custom object also has one more picklist called Transport,it has some values like By Road,By Air,By Sea..etc.
while the user selects the value in Account picklist field as "Ind",the value in child object picklist field as "By Road".If the value in Account has Other than "Ind",the value in child object picklist field as "By Air".I did this with ProcessBuilder and created seperate process for two conditions.
I include these two conditions with Process at the time of update record actions using formulas it won't work.which formula used in this??
How to write the trigger for this updating records.can any one provide sample code or any ideas.
thanks in advance.
-
- System Admin 949
- September 18, 2018
- Like
- 0
- Continue reading or reply
Test class in Lightning
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.
- System Admin 949
- October 03, 2018
- Like
- 0
- Continue reading or reply
Clone Button not working in Lightning Components
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
- System Admin 949
- September 25, 2018
- Like
- 0
- Continue reading or reply
Clone Button Not Working
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.
- System Admin 949
- September 24, 2018
- Like
- 0
- Continue reading or reply
Custom Clone button using Apex
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
- System Admin 949
- September 21, 2018
- Like
- 0
- Continue reading or reply
Make a Picklist Field Read Only based on another Object Picklist Value
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.
thanks in advance
- System Admin 949
- September 21, 2018
- Like
- 0
- Continue reading or reply
Standard Clone Button on Quote Object
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
- System Admin 949
- September 19, 2018
- Like
- 0
- Continue reading or reply
Update Email Fields in Related Objects
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
- System Admin 949
- September 18, 2018
- Like
- 0
- Continue reading or reply