You need to sign in to do that
Don't have an account?
Sfdc wonder
How to avoid too many future callouts
How to avoid Too Many Future callouts!!!!!!Help me
I want to send contact info of particler lead to my 3rd party...
dis code will fine for 9-records
my trigger is
trigger conupdater on Contact(after insert,after update,before delete)
{
list <lead> l=[Select id,name,lastname,firstname from lead];
BuzzBoard_Setting__c bb=[select id,Name,Partner_key__c from BuzzBoard_Setting__c Order by CreatedDate DESC LIMIT 1];
public String mymethod;
public String type='Contact';
Map<id,id> contMap=new Map<id,id>();
if(Trigger.isAfter)
{
for(contact cont:Trigger.new){
if(cont.ContactLead__c!=null){
contMap.put(cont.id,cont.ContactLead__c);
}
}
}
if((Trigger.isAfter && Trigger.isInsert))
{
for(contact c:Trigger.New){
mymethod='INSERT';
if(contMap.containsKey(c.id)){
LeadChildsUpdater_bb.updatenotes(c.id,contMap.get(c.id),mymethod,type,bb.Partner_key__c);
}
}
}
if((Trigger.isAfter && Trigger.isUpdate))
{
for(contact c:Trigger.New){
mymethod='UPDATE';
if(contMap.containsKey(c.id)){
LeadChildsUpdater_bb.updatenotes(c.id,contMap.get(c.id),mymethod,type,bb.Partner_key__c);
}
}
}
if((Trigger.isBefore && Trigger.isDelete))
{
for(contact cont:Trigger.old){
if(cont.ContactLead__c!=null){
contMap.put(cont.id,cont.ContactLead__c);
}
}
for(contact c:Trigger.Old){
mymethod='DELETE';
if(contMap.containsKey(c.id)){
LeadChildsUpdater_bb.updatenotes(c.id,contMap.get(c.id),mymethod,type,bb.Partner_key__c);
}
}
}
}
My Controller class is ::
public class LeadChildsUpdater_bb
{
public static string resmessage;
@Future(callout=true)
public static void updatenotes(String Id,String Lead_Id,String Action,String Type,String Key)
{
HttpRequest req = new HttpRequest();
req.setEndpoint('https://demo.mybuzzboard.com/salesforce/assetsSync.php');
req.setMethod('POST');
req.setBody('Id='+EncodingUtil.urlEncode(+Id, 'UTF-8')+'&Lead_Id='+EncodingUtil.urlEncode(+Lead_Id, 'UTF-8')+'&Action='+EncodingUtil.urlEncode(+Action, 'UTF-8')+'&Type='+EncodingUtil.urlEncode(+Type, 'UTF-8')+'&Key='+EncodingUtil.urlEncode(+Key, 'UTF-8'));
Http http = new Http();
HttpResponse res = http.send(req);
if (res.getStatusCode() == 200)
{
System.debug('---------------------'+res.getBody());
}
else
{
System.debug('Callout failed: ' + res);
}
}
}
I want to send contact info of particler lead to my 3rd party...
dis code will fine for 9-records
my trigger is
trigger conupdater on Contact(after insert,after update,before delete)
{
list <lead> l=[Select id,name,lastname,firstname from lead];
BuzzBoard_Setting__c bb=[select id,Name,Partner_key__c from BuzzBoard_Setting__c Order by CreatedDate DESC LIMIT 1];
public String mymethod;
public String type='Contact';
Map<id,id> contMap=new Map<id,id>();
if(Trigger.isAfter)
{
for(contact cont:Trigger.new){
if(cont.ContactLead__c!=null){
contMap.put(cont.id,cont.ContactLead__c);
}
}
}
if((Trigger.isAfter && Trigger.isInsert))
{
for(contact c:Trigger.New){
mymethod='INSERT';
if(contMap.containsKey(c.id)){
LeadChildsUpdater_bb.updatenotes(c.id,contMap.get(c.id),mymethod,type,bb.Partner_key__c);
}
}
}
if((Trigger.isAfter && Trigger.isUpdate))
{
for(contact c:Trigger.New){
mymethod='UPDATE';
if(contMap.containsKey(c.id)){
LeadChildsUpdater_bb.updatenotes(c.id,contMap.get(c.id),mymethod,type,bb.Partner_key__c);
}
}
}
if((Trigger.isBefore && Trigger.isDelete))
{
for(contact cont:Trigger.old){
if(cont.ContactLead__c!=null){
contMap.put(cont.id,cont.ContactLead__c);
}
}
for(contact c:Trigger.Old){
mymethod='DELETE';
if(contMap.containsKey(c.id)){
LeadChildsUpdater_bb.updatenotes(c.id,contMap.get(c.id),mymethod,type,bb.Partner_key__c);
}
}
}
}
My Controller class is ::
public class LeadChildsUpdater_bb
{
public static string resmessage;
@Future(callout=true)
public static void updatenotes(String Id,String Lead_Id,String Action,String Type,String Key)
{
HttpRequest req = new HttpRequest();
req.setEndpoint('https://demo.mybuzzboard.com/salesforce/assetsSync.php');
req.setMethod('POST');
req.setBody('Id='+EncodingUtil.urlEncode(+Id, 'UTF-8')+'&Lead_Id='+EncodingUtil.urlEncode(+Lead_Id, 'UTF-8')+'&Action='+EncodingUtil.urlEncode(+Action, 'UTF-8')+'&Type='+EncodingUtil.urlEncode(+Type, 'UTF-8')+'&Key='+EncodingUtil.urlEncode(+Key, 'UTF-8'));
Http http = new Http();
HttpResponse res = http.send(req);
if (res.getStatusCode() == 200)
{
System.debug('---------------------'+res.getBody());
}
else
{
System.debug('Callout failed: ' + res);
}
}
}
I'd suggest to be safe, some kind of error handling or checking that uses limits.GetFutureCalls() and limits.GetLimitFutureCalls() so you can at least see where you are (or use those in your debugging as you troubleshoot as well).
Thanks,
Matt / ScriptMonkey
All Answers
As my first impression on the code is. Code is not bulkyfied..
Use list<ID> as parameter insted of singel value parameter.
Piyush
Thanks,
Venkat
I'd suggest to be safe, some kind of error handling or checking that uses limits.GetFutureCalls() and limits.GetLimitFutureCalls() so you can at least see where you are (or use those in your debugging as you troubleshoot as well).
Thanks,
Matt / ScriptMonkey