You need to sign in to do that
Don't have an account?
Gwirizanani Sinoia
Concatenate multiple Url links on Task Description field during task creation
I have a code snipet below works perfectly when i have one order item. However I am looking for away to Concatenate multiple order item url/ids onto tasks comements/description field.
ie if more than one order item description/comments =
https://developer.salesforce.com/ID1
https://developer.salesforce.com/ID2
https://developer.salesforce.com/ID3 etc
public class OrderProduct {
public static void createOrderProduct (List<OrderItem> newList, Map<Id,OrderItem> oldMap){
Wide__c vars = Wide__c.getOrgDefaults();
Set<Id > orderIds = new Set<Id>();
List<Order > orderRecords = new List<Order >();
set<Id > orderItemsIds = new set<Id>();
Map<Id,OrderItem> orderItemMap = new Map<Id,OrderItem>();
Map<String,OrderItem> orderItemCountryMap = new Map<String,OrderItem>();
Map<Id,String> orderItemCountryIdMap = new Map<Id,String>();
Map<Id,String> oppOrderTaskMap = new Map<Id,String>();
List<Task > taskList = new List<Task>();
List<Group> Groupid = [select Id,Name from Group where name ='Supplier Company and WBS To Do Queue'];
// get all order ids
for(OrderItem ord: newList){
orderIds.add(ord.OrderId);
}// end of for loop
string ordIdField;
system.debug('order ids' + orderIds.size());
List<Order> orderRecordsList = [SELECT Id FROM Order WHERE Id in: orderIds];
for(Order ord:orderRecordsList ){
for(OrderItem ori: newList ){
if(ori.cont__c!=ori.podIso__c && ori.OrderId == ord.Id && ori.OrderId != Null &&
ori.cont__c!=Null && ori.OrderId!=Null ){
orderItemCountryMap.put(ori.OrderProductCountryIso__c, ori);
orderItemMap.put(ori.Id, ori);
}
system.debug('order item values' + orderItemCountryMap.values());
}// frist loop
}// end of last loop
for(OrderItem ordi : orderItemCountryMap.values()){
Task taskRecord = new Task() ;
taskRecord.Subject = ordi.OrdName__c ; //+' '+vars.Profile_Ids__c + ordi.OrderOpportunityID__c
if(Groupid!=null){
taskRecord.OwnerID = Groupid[0].id;
}
taskRecord.Priority = 'High';
// taskRecord.Description = 'Comment' + ordi.Id ;
//taskRecord.Description = vars.Profile_Ids__c + orderItemMap.get(ordi.Id).Id ;
taskRecord.WhatID = ordi.OrderId;
taskRecord.Task_Country__c=ordi.podIso__c;
taskRecord.Type ='Order';
taskRecord.ActivityDate = date.today() + 2;
taskRecord.OpportunityId__c = ordi.OrderOpportunityID__c ;
If(ordi.OrderCountryCode__c == orderItemMap.get(ordi.Id).OrderCountryCode__c ){
// taskRecord.Description += '\n' + vars.Profile_Ids__c + orderItemMap.get(ordi.Id).Id;
if(String.isBlank(taskRecord.Description)){
taskRecord.Description = vars.Profile_Ids__c + orderItemMap.get(ordi.Id).Id;
}else{
taskRecord.Description += '\n' + vars.Profile_Ids__c + orderItemMap.get(ordi.Id).Id;
}
}
taskList.add(taskRecord);
}
// loop through tasks update taskRecord.Description with multiple urls
insert taskList;
}
}
ie if more than one order item description/comments =
https://developer.salesforce.com/ID1
https://developer.salesforce.com/ID2
https://developer.salesforce.com/ID3 etc
public class OrderProduct {
public static void createOrderProduct (List<OrderItem> newList, Map<Id,OrderItem> oldMap){
Wide__c vars = Wide__c.getOrgDefaults();
Set<Id > orderIds = new Set<Id>();
List<Order > orderRecords = new List<Order >();
set<Id > orderItemsIds = new set<Id>();
Map<Id,OrderItem> orderItemMap = new Map<Id,OrderItem>();
Map<String,OrderItem> orderItemCountryMap = new Map<String,OrderItem>();
Map<Id,String> orderItemCountryIdMap = new Map<Id,String>();
Map<Id,String> oppOrderTaskMap = new Map<Id,String>();
List<Task > taskList = new List<Task>();
List<Group> Groupid = [select Id,Name from Group where name ='Supplier Company and WBS To Do Queue'];
// get all order ids
for(OrderItem ord: newList){
orderIds.add(ord.OrderId);
}// end of for loop
string ordIdField;
system.debug('order ids' + orderIds.size());
List<Order> orderRecordsList = [SELECT Id FROM Order WHERE Id in: orderIds];
for(Order ord:orderRecordsList ){
for(OrderItem ori: newList ){
if(ori.cont__c!=ori.podIso__c && ori.OrderId == ord.Id && ori.OrderId != Null &&
ori.cont__c!=Null && ori.OrderId!=Null ){
orderItemCountryMap.put(ori.OrderProductCountryIso__c, ori);
orderItemMap.put(ori.Id, ori);
}
system.debug('order item values' + orderItemCountryMap.values());
}// frist loop
}// end of last loop
for(OrderItem ordi : orderItemCountryMap.values()){
Task taskRecord = new Task() ;
taskRecord.Subject = ordi.OrdName__c ; //+' '+vars.Profile_Ids__c + ordi.OrderOpportunityID__c
if(Groupid!=null){
taskRecord.OwnerID = Groupid[0].id;
}
taskRecord.Priority = 'High';
// taskRecord.Description = 'Comment' + ordi.Id ;
//taskRecord.Description = vars.Profile_Ids__c + orderItemMap.get(ordi.Id).Id ;
taskRecord.WhatID = ordi.OrderId;
taskRecord.Task_Country__c=ordi.podIso__c;
taskRecord.Type ='Order';
taskRecord.ActivityDate = date.today() + 2;
taskRecord.OpportunityId__c = ordi.OrderOpportunityID__c ;
If(ordi.OrderCountryCode__c == orderItemMap.get(ordi.Id).OrderCountryCode__c ){
// taskRecord.Description += '\n' + vars.Profile_Ids__c + orderItemMap.get(ordi.Id).Id;
if(String.isBlank(taskRecord.Description)){
taskRecord.Description = vars.Profile_Ids__c + orderItemMap.get(ordi.Id).Id;
}else{
taskRecord.Description += '\n' + vars.Profile_Ids__c + orderItemMap.get(ordi.Id).Id;
}
}
taskList.add(taskRecord);
}
// loop through tasks update taskRecord.Description with multiple urls
insert taskList;
}
}