You need to sign in to do that
Don't have an account?
Vidya H 4
Im trying to copy picklist values to comma separated values. but I am not getting proper output please help me
I have picklist field "Funding" on Quote object and text field "Funding" on Opportunity object. I want to copy the picklist values from all Quotes related to the Opportunity and display it on "Funding" field on Opportunity separated by comma. I tried this code but not working,
I need to use string join instead of split. please help
global class UpdateFunding implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator([SELECT Id,StageName FROM opportunity where StageName='Closed Won']);
}
global void execute(Database.BatchableContext context, List<sObject> batch){
Set<Id> Opportuniyids = new Set<Id>();
for (sObject oppy : batch) {
Opportuniyids.add(oppy.Id);
}
updatequote(Opportuniyids);
}
global void finish(Database.BatchableContext context) {}
public void updatequote(set<id> oppyids){
system.debug('opportuiy ids'+oppyids);
List<opportunity> opportunities=[SELECT Id ,Funding__c FROM opportunity WHERE Id IN :oppyids];
for(Opportunity opp:opportunities) {
Set<String> systems = new Set<String>();
for (Quote__c oppObj : [SELECT Id, Funding__c, opportunity__c FROM Quote__c WHERE opportunity__c = :opp.id]) {
if (String.isNotBlank(oppObj.Funding__c)) {
systems.addAll(oppObj.Funding__c.split(';'));
}
System.debug('ccc'+systems);
}
String accountSystems = '';
for (String value : systems) {
accountSystems += value + ';';
}
accountSystems = accountSystems.removeEnd(';');
try {
update new Opportunity(Id = opp.id,Funding__c = accountSystems);
} catch (Exception e) {
System.debug('Exception: ' + e.getMessage());
}
}
}
}
I need to use string join instead of split. please help
global class UpdateFunding implements Database.Batchable<sObject> {
global Database.QueryLocator start(Database.BatchableContext bc) {
return Database.getQueryLocator([SELECT Id,StageName FROM opportunity where StageName='Closed Won']);
}
global void execute(Database.BatchableContext context, List<sObject> batch){
Set<Id> Opportuniyids = new Set<Id>();
for (sObject oppy : batch) {
Opportuniyids.add(oppy.Id);
}
updatequote(Opportuniyids);
}
global void finish(Database.BatchableContext context) {}
public void updatequote(set<id> oppyids){
system.debug('opportuiy ids'+oppyids);
List<opportunity> opportunities=[SELECT Id ,Funding__c FROM opportunity WHERE Id IN :oppyids];
for(Opportunity opp:opportunities) {
Set<String> systems = new Set<String>();
for (Quote__c oppObj : [SELECT Id, Funding__c, opportunity__c FROM Quote__c WHERE opportunity__c = :opp.id]) {
if (String.isNotBlank(oppObj.Funding__c)) {
systems.addAll(oppObj.Funding__c.split(';'));
}
System.debug('ccc'+systems);
}
String accountSystems = '';
for (String value : systems) {
accountSystems += value + ';';
}
accountSystems = accountSystems.removeEnd(';');
try {
update new Opportunity(Id = opp.id,Funding__c = accountSystems);
} catch (Exception e) {
System.debug('Exception: ' + e.getMessage());
}
}
}
}
Without knowing exactly what you are seeing, here is my guess on what you are trying to accomplish. I added some notes on best practices like avoiding SOQL and DML inside for loops.