You need to sign in to do that
Don't have an account?
Swapnil W
update lookup field with apex class and trigger
Hi All,
Really need help with this issue: I am trying to populate field Version__c [Lookup(Product)] on QuotLine__c object, whenever New_Management_Version__c (checkbox field) on Product object is set to true. But don't know why Version__c is not getting populated.
Also would like to mention here, QuoteLine child object of Product parent object.
Here is my Apex Class:
public without sharing class QuoteLineManager{
public static void updateVersion(List<QuoteLine__c> lstQuoteLine){
List<QuoteLine__c> softwareQlines = new List<QuoteLine__c>();
List<QuoteLine__c> versionQlines = new List<QuoteLine__c>();
for(QuoteLine__c ql:lstQuoteLine){
if(ql.ProductFamily__c == 'Software'){
softwareQlines.add(ql);
}
if(ql.ProductFamily__c == 'Version'){
versionQlines.add(ql);
}
}
for(QuoteLine__c softQl:softwareQlines){
for(QuoteLine__c versQl:versionQlines){
if(versQl.Parent_Product_Name__c == softQl.Parent_Product_Name__c){
softQl.Version__c = versQl.SBQQ__Product__c;
}
}
}
}
}
Apex Trigger:
trigger QuoteLineBeforeUpdate on QuoteLine__c (before update) {
List<QuoteLine__c> listQuotelinesNewVersionManagementTrue = new List<QuoteLine__c>();
// need to verify if the New Version Management is true :
for (QuoteLine__c ql : Trigger.new) {
if (ql.ProductFamily__c == 'Software' && ql.Product__r.New_Version_Management__c == true ){
//if is true I put it in the list
listQuotelinesNewVersionManagementTrue.add(ql);
}
}
if (!listQuotelinesNewVersionManagementTrue.isEmpty()) {
QuoteLineManager.updateVersion(listQuotelinesNewVersionManagementTrue);
}
}
Please let me know if you didn't get clear picture of issue. Looking forward for positive feedback. Thanks in advance.
Really need help with this issue: I am trying to populate field Version__c [Lookup(Product)] on QuotLine__c object, whenever New_Management_Version__c (checkbox field) on Product object is set to true. But don't know why Version__c is not getting populated.
Also would like to mention here, QuoteLine child object of Product parent object.
Here is my Apex Class:
public without sharing class QuoteLineManager{
public static void updateVersion(List<QuoteLine__c> lstQuoteLine){
List<QuoteLine__c> softwareQlines = new List<QuoteLine__c>();
List<QuoteLine__c> versionQlines = new List<QuoteLine__c>();
for(QuoteLine__c ql:lstQuoteLine){
if(ql.ProductFamily__c == 'Software'){
softwareQlines.add(ql);
}
if(ql.ProductFamily__c == 'Version'){
versionQlines.add(ql);
}
}
for(QuoteLine__c softQl:softwareQlines){
for(QuoteLine__c versQl:versionQlines){
if(versQl.Parent_Product_Name__c == softQl.Parent_Product_Name__c){
softQl.Version__c = versQl.SBQQ__Product__c;
}
}
}
}
}
Apex Trigger:
trigger QuoteLineBeforeUpdate on QuoteLine__c (before update) {
List<QuoteLine__c> listQuotelinesNewVersionManagementTrue = new List<QuoteLine__c>();
// need to verify if the New Version Management is true :
for (QuoteLine__c ql : Trigger.new) {
if (ql.ProductFamily__c == 'Software' && ql.Product__r.New_Version_Management__c == true ){
//if is true I put it in the list
listQuotelinesNewVersionManagementTrue.add(ql);
}
}
if (!listQuotelinesNewVersionManagementTrue.isEmpty()) {
QuoteLineManager.updateVersion(listQuotelinesNewVersionManagementTrue);
}
}
Please let me know if you didn't get clear picture of issue. Looking forward for positive feedback. Thanks in advance.
public without sharing class QuoteLineManager{
public static void updateVersion(List<QuoteLine__c> lstQuoteLine, List <String> lstparentProductName){
List<QuoteLine__c> updatedQlines = new List<QuoteLine__c>();
List<QuoteLine__c> versionQlines = [select Id, SBQQ__ProductFamily__c, SBQQ__Product__c, Parent_Product_Name__c from SBQQ__QuoteLine__c where SBQQ__ProductFamily__c = 'Version' and Parent_Product_Name__c =:lstparentProductName];
for(QuoteLine__c softQl:lstQuoteLine){
for(QuoteLine__c versQl:versionQlines){
if(versQl.Parent_Product_Name__c == softQl.Parent_Product_Name__c){
softQl.Version__c = versQl.SBQQ__Product__c;
updatedQlines.add(softQl);
}
}
}
update updatedQlines;
}
}
All Answers
try with this code
////Trigger
trigger QuoteLineBeforeUpdate on QuoteLine__c (before update) {
List<QuoteLine__c> listQuotelinesNewVersionManagementTrue = new List<QuoteLine__c>();
//Extra list to capture quoteline Parent_Product_Name__c
List<String> quotelineParentProductName= new List<String>();
// need to verify if the New Version Management is true :
for (QuoteLine__c ql : Trigger.new) {
if (ql.ProductFamily__c == 'Software' && ql.Product__r.New_Version_Management__c == true ){
//if is true I put it in the list
listQuotelinesNewVersionManagementTrue.add(ql);
quotelineParentProductName.add(ql.Parent_Product_Name__c);
}
}
if (!listQuotelinesNewVersionManagementTrue.isEmpty()) {
QuoteLineManager.updateVersion(listQuotelinesNewVersionManagementTrue,quotelineParentProductName);
}
}
////CLASS
public without sharing class QuoteLineManager{
public static void updateVersion(List<QuoteLine__c> lstQuoteLine, List <String> lstparentProductName){
//List<QuoteLine__c> softwareQlines = new List<QuoteLine__c>();
List<QuoteLine__c> versionQlines = [select ProductFamily__c,SBQQ__Product__c,Parent_Product_Name__c from QuoteLine__c where ProductFamily__c == 'Version' and ProductFamily__c :lstparentProductName ];
for(QuoteLine__c softQl:lstQuoteLine){
for(QuoteLine__c versQl:versionQlines){
if(versQl.Parent_Product_Name__c == softQl.Parent_Product_Name__c){
softQl.Version__c = versQl.SBQQ__Product__c;
}
}
}
}
}
I tried your code and for line
List<QuoteLine__c> versionQlines = [Select Id, SBQQ__ProductFamily__c, SBQQ__Product__c, Parent_Product_Name__c FROM SBQQ__QuoteLine__c WHERE SBQQ__ProductFamily__c == 'Version' AND SBQQ__ProductFamily__c:lstparentProductName] in apex class
its giving error as 'Expression cannot be a statement'.
List<QuoteLine__c> versionQlines = [select Id, SBQQ__ProductFamily__c, SBQQ__Product__c, Parent_Product_Name__c from SBQQ__QuoteLine__c where SBQQ__ProductFamily__c == 'Version' and SBQQ__ProductFamily__c:lstparentProductName];
is giving error as:
List<QuoteLine__c> versionQlines = [select Id, SBQQ__ProductFamily__c, SBQQ__Product__c, Parent_Product_Name__c from SBQQ__QuoteLine__c where SBQQ__ProductFamily__c = 'Version' and Parent_Product_Name__c =:lstparentProductName];
public without sharing class QuoteLineManager{
public static void updateVersion(List<QuoteLine__c> lstQuoteLine, List <String> lstparentProductName){
List<QuoteLine__c> updatedQlines = new List<QuoteLine__c>();
List<QuoteLine__c> versionQlines = [select Id, SBQQ__ProductFamily__c, SBQQ__Product__c, Parent_Product_Name__c from SBQQ__QuoteLine__c where SBQQ__ProductFamily__c = 'Version' and Parent_Product_Name__c =:lstparentProductName];
for(QuoteLine__c softQl:lstQuoteLine){
for(QuoteLine__c versQl:versionQlines){
if(versQl.Parent_Product_Name__c == softQl.Parent_Product_Name__c){
softQl.Version__c = versQl.SBQQ__Product__c;
updatedQlines.add(softQl);
}
}
}
update updatedQlines;
}
}