You need to sign in to do that
Don't have an account?
Asakti
batch class for below trigger please help,
trigger opportunityProduct on OpportunityLineItem (after insert) {
Set<Id> oppId = new Set<Id>();
for(OpportunityLineItem opp : Trigger.new)
{
oppId.add(opp.OpportunityId);
}
List<Opportunity> oppList = new List<Opportunity>();
List<String> products = new List<String>();
for(Opportunity opp : [Select Name,(Select Name,product2Id,product2.Name_Details__c from OpportunityLineItems) from Opportunity where Id in:oppId ])
{
for(OpportunityLineItem oppLine : opp.OpportunityLineItems)
{
if(OpportunityLineItem.Name != null)
{
products.add(oppLine.product2.Name_Details__c);
}
}
opp.Product_Details__c = String.join(products,', ');
oppList.add(opp);
}
update oppList;
}
batchclass i have written
global class productNameOnOpportunity implements Database.Batchable<sObject>{
global Database.QueryLocator start(Database.BatchableContext BC){
String query = 'Select Name,Product_Details__c (Select Name,product2Id,product2.Name_Details__c from OpportunityLineItems) from Opportunity';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext info, List<Opportunity> Opp)
{
List<String> names = new List<String>();
List<Opportunity> oppList = new List<Opportunity>();
for(OpportunityLineItem oppLine : Opp)
{
if(OpportunityLineItem.Name != null)
{
names.add(OpportunityLineItem.product2.Name_Details__c);
Opp.Product_Details__c = String.join(names,',');
oppList.add(Opp);
}
}
if(oppList.size()>0)
{
update oppList;
}
}
global void finish(Database.BatchableContext info){
}
}
Set<Id> oppId = new Set<Id>();
for(OpportunityLineItem opp : Trigger.new)
{
oppId.add(opp.OpportunityId);
}
List<Opportunity> oppList = new List<Opportunity>();
List<String> products = new List<String>();
for(Opportunity opp : [Select Name,(Select Name,product2Id,product2.Name_Details__c from OpportunityLineItems) from Opportunity where Id in:oppId ])
{
for(OpportunityLineItem oppLine : opp.OpportunityLineItems)
{
if(OpportunityLineItem.Name != null)
{
products.add(oppLine.product2.Name_Details__c);
}
}
opp.Product_Details__c = String.join(products,', ');
oppList.add(opp);
}
update oppList;
}
batchclass i have written
global class productNameOnOpportunity implements Database.Batchable<sObject>{
global Database.QueryLocator start(Database.BatchableContext BC){
String query = 'Select Name,Product_Details__c (Select Name,product2Id,product2.Name_Details__c from OpportunityLineItems) from Opportunity';
return Database.getQueryLocator(query);
}
global void execute(Database.BatchableContext info, List<Opportunity> Opp)
{
List<String> names = new List<String>();
List<Opportunity> oppList = new List<Opportunity>();
for(OpportunityLineItem oppLine : Opp)
{
if(OpportunityLineItem.Name != null)
{
names.add(OpportunityLineItem.product2.Name_Details__c);
Opp.Product_Details__c = String.join(names,',');
oppList.add(Opp);
}
}
if(oppList.size()>0)
{
update oppList;
}
}
global void finish(Database.BatchableContext info){
}
}
All Answers
Variable does not exist: Name_Details__c
Variable does not exist: Product_Details__c
line 17 Method does not exist or incorrect signature: void add(List<Opportunity>) from the type List<Opportunity>
Select Name,Product_Details__c (Select Name,product2Id,product2.Name_Details__c from OpportunityLineItems) from Opportunity
You are using Code
for(OpportunityLineItem oppLine : Opp)
{
if(OpportunityLineItem.Name != null)
{
names.add(OpportunityLineItem.product2.Name_Details__c);
Opp.Product_Details__c = String.join(names,',');
oppList.add(Opp);
}
}
Here Opp is not list of OpportunityLineItem Its a list of Opportunity which you are getting in scope;
Try this:
for(Opportunity op : Opp)
{
for(OpportunityLineItem oppLine : op.OpportunityLineItems)
{
//Your Logic
}
}
getting the above error