You need to sign in to do that
Don't have an account?
Travis Lee 6
Translating Maps to Lists in Apex?
Hey there,
I'm trying to create a class that I can invoke with a process. The process exists on the Opportunity and needs to invoke a class that will unsync the current quote. I'm a new developer, but this is what I've researched so far. Based on this blog post (http://salesforcekings.blogspot.com/2014/09/how-to-automatically-sync-new-quote.html), I can't use a trigger. I found an example of a class that I think will accomplish what I need, but it's a future class (not required for my scenario, I don't think). Here is that example that I'm pilfering:
Since I need it to be invocable by a process, I believe I need to include the @InvocableMethod annotation. When I do, I get an error that says the Map<Id, Id> is an unsupported parameter type and I have to use List instead. So I started switching the Maps over to Lists and this is where I get stuck because the "get" parameter on line 11 below isn't compatible with List methods I guess? This is where my knowledge starts to drop off.
Any advice on the code above would be great, but I'd also like to understand a bit more about why I'm experiencing these errors with Maps vs. Lists. Thanks in advance!
Travis
I'm trying to create a class that I can invoke with a process. The process exists on the Opportunity and needs to invoke a class that will unsync the current quote. I'm a new developer, but this is what I've researched so far. Based on this blog post (http://salesforcekings.blogspot.com/2014/09/how-to-automatically-sync-new-quote.html), I can't use a trigger. I found an example of a class that I think will accomplish what I need, but it's a future class (not required for my scenario, I don't think). Here is that example that I'm pilfering:
public class QuoteAutoSyncUtil { @future public static void syncQuote(Map<Id, Id> quoteMap) { Map<Id, Opportunity> oppMap = new Map<Id, Opportunity>(); for(Id currentQuote : quoteMap.keyset()) { Opportunity opp = new Opportunity(); opp.Id = quoteMap.get(currentQuote); opp.SyncedQuoteId = currentQuote; oppMap.put(opp.Id, opp); } update oppMap.values(); } }
Since I need it to be invocable by a process, I believe I need to include the @InvocableMethod annotation. When I do, I get an error that says the Map<Id, Id> is an unsupported parameter type and I have to use List instead. So I started switching the Maps over to Lists and this is where I get stuck because the "get" parameter on line 11 below isn't compatible with List methods I guess? This is where my knowledge starts to drop off.
public class QuoteAutoSyncUtil { @InvocableMethod public static void syncQuote(List<Quote> quoteList) { List<Opportunity> oppList = new List<Opportunity>(); for(Id currentQuote : quoteList.keyset()) { Opportunity opp = new Opportunity(); opp.Id = quoteList.get(currentQuote); opp.SyncedQuoteId = currentQuote; oppList.add(opp); } Integer oppSize = oppList.size(); update oppList[oppSize -1 ]; } }
Any advice on the code above would be great, but I'd also like to understand a bit more about why I'm experiencing these errors with Maps vs. Lists. Thanks in advance!
Travis
List.get(index) ...using get for list is gettting an item on ith index. So it was syntax error in your code.
All Answers
List.get(index) ...using get for list is gettting an item on ith index. So it was syntax error in your code.