• nelrib88
  • NEWBIE
  • 10 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 20
    Questions
  • 18
    Replies
I have a third party cloud app that is already integrated with salesforce and available on appExchange.  I would like to take advantage of canvas to provide a better user experience.  I have gone through and created a new app and i can reach my third party app and login through the canvas previewer. I get to the login page of my app and i can log in but i would like it to be already logged in since users can connect through OAUTH and allow access already in my app.

I noticed that the canvas app would need to be a new salesforce app i can't just add it to my current package, is this right?
How do i automatically login the salesforce user to my app?
I see alot of heruko stuff but i do not use it my app is built using java on glassfish server, is it possible to create a salesforce canvas app with my existing java app?

I just want to be able to provide a dashboard for users in the form of a tab that allows them to use functions from my third party app in salesforce.

I have a third party app on the app exchange that is used to pull in contacts and campaigns that are later used to send as email campaigns.  Right now our app is only doing push and pull operations to send and receive the data as its needed.  i would like to modify the app so that it is alot more integrated with salesforce and not sure how the best way of doing this is.  I have read on methods such as getUpdated() and getDeleted() which could be be used in a nightly process, and have also read a bit on outbound messaging.  Doing the sync in real time is not my main priority but would be best.

 

Can someone please help me understand how many big name companies manage to keep salesforce data syncronized with there own web app. 

 

thanks,

NR

I'm having an issue with my trigger that is confusing me.  My trigger is called on a before update when a specific field on the contact becomes empty.  My trigger code calls a separate @future apex class only if the field i check against begins populated before the save and then becomes empty and then makes a callout to an external system. There is also a third party batch process that does upserts on all contacts every night and updates some fields.  The field that fires off the callout is never modyfied during this batch process.

 

The problem is during the nightly batch process the upserts are causing my trigger to call the @future class causing it to throw an error.

 

caused by: System.DmlException: Update failed. First exception on row 0 with id 0033000000z3r2cAAA; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, InvalidEmailContactTrigger: execution of BeforeUpdate

caused by: System.AsyncException: Future method cannot be called from a future or batch method: EmailIssueRemover.removeEmailIssue(MAP<Id,String>, String, String)

 

for(Contact contact : trigger.old)
        { 
            emailissue = contact.Email_Issue__c;
        }
        
        for(Contact contact : trigger.new)
        {            
            if(contact.Email_Issue__c == null && emailissue != null)
            {  
                contactsToUpdate.put(contact.Id, emailissue);
                session = contact.session_id__c;
                server = contact.server_url__c;
                lastName = contact.lastName;
                changed = true;
            } 
        }
        if(lastName == 'ApexRunTestIssue'){
            EmailIssueRemover.test(contactsToUpdate);
        } else {     
            if(changed){
                EmailIssueRemover.removeEmailIssue(contactsToUpdate, session, server);
            }
        }

 

 

Can anyone explain why this might happen.

I have built a trigger that is called when a contact/lead is updated. This trigger calls a @future method with a callout when a specific field (Email_Issue__c) starts off populated and is then saved to null.

One of our clients has a night batch upload that does an upsert on all its contacts and even though the Email_issue__c is not one of the fields being updated in the batch somehow the callout is going through. When looking through the bulk data load jobs we see the error CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:itracmedia.InvalidEmailContactTrigger: System.LimitException: itracmedia:Too many future calls: 11:-- for about 100 of 5000 records it processes.

Can someone please explain why this might be happening and what i can do to fix this issue.

 

Trigger

trigger InvalidEmailContactTrigger on Contact (before update)
{
    private String emailissue {get; set;}
    if(Trigger.isBefore)
    {
        emailissue = null;
        for(Contact contact : trigger.old)
        { 
            emailissue = contact.itracmedia__Email_Issue__c;
        }
        
        for(Contact contact : trigger.new)
        {            
            if(contact.itracmedia__Email_Issue__c == null && emailissue != null)
            {  
                if(contact.lastName == 'ApexRunTestIssue'){
                    EmailIssueRemover.test();
                } else {      
                    EmailIssueRemover.removeEmailIssue(contact.id, emailissue, contact.itracmedia__session_id__c, contact.itracmedia__server_url__c);
                }
            } 
        }
    }
}

 

Apex Class:

public class EmailIssueRemover {

  // Static variable that assumes a test is not running
  public static boolean isApexTest = false;
    
  //Future annotation to mark the method as async.
  @Future(callout=true)
  public static void removeEmailIssue(String id, String issue, String sessionid, String serverurl) {

     String server = EncodingUtil.urlEncode(serverurl,'UTF-8');
     String session = EncodingUtil.urlEncode(sessionid,'UTF-8');
   
     Http h = new Http();
     HttpRequest req = buildWebServiceRequest(id, EncodingUtil.urlEncode(issue,'UTF-8'), session, server);
     if(!isApexTest){
       HttpResponse res = invokeWebService(h, req);   
     } 
  }
    
  public static HttpRequest buildWebServiceRequest(String id, String issue, String sessionid, String serverurl){

    //Build HTTP Request object
    HttpRequest req = new HttpRequest();
    req.setEndpoint('https://www.**.com/removeEmailIssue?sessionid=' + sessionid + '&serverurl='+ serverurl + '&type='+issue+'&id='+id);
    req.setMethod('GET');
    return req;
  }
  
  public static HttpResponse invokeWebService(Http h, HttpRequest req){
     HttpResponse res = h.send(req);
     return res;
  }
  
  // Wrapper method for "main" that we will call in the Test Class
  public static void test(){
    isApexTest = true;
    removeEmailIssue('test','test','test','test');
  }
}

 


I have a trigger that is fired and does a callout whenever a specific custom field in Contacts object is updated to null.  The problem im having is every night a bulk data job is done that does an upsert on Contacts and throws the error CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:itracmedia.In

validEmailContactTrigger: System.LimitException: itracmedia:Too many future calls: 11:-- for about 100 of 5000 records it processes but the field that fires my trigger is not updated in this data load.

 

Can anyone help me by explaining what can possibly be happening. 

My setup: I have a trigger that gets fired whenever a specific custom field for a contact object is deleted.  the trigger invokes a @future apex method that sends a callout to an external system.  The trigger was designed such that from a contacts page view the field can be deleted and it would sync with the other system.

 

The problem i am facing is that there is a nightly batch script that runs and throws the error CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:itracmedia.InvalidEmailContactTrigger: System.LimitException: itracmedia:Too many future calls: 11:-- for about 100 of 5000 records it processes. 

 

I understand that the error is caused form the @future method being invoked more than 10 times, but from what i understood from reading the documentation is that the limit is focused on one trigger instance invoking the @future method more than 10 times. I believe that my trigger invokes the @future method only once for each contact that gets updated.  is it possible to get this error if the script runs so fast that there are 10 callouts being made at the same time and the 11th starts before any have finished yet.

 

My code is below for both the trigger and apex class.

 

Can someone please explain how this is happening and if you can please help me in finding a solution.

 

trigger InvalidEmailContactTrigger on Contact (before update)
{
    private String emailissue {get; set;}
    if(Trigger.isBefore)
    {
        emailissue = null;
        for(Contact contact : trigger.old)
        { 
            emailissue = contact.Email_Issue__c;
        }
        
        for(Contact contact : trigger.new)
        {            
            if(contact.Email_Issue__c == null && emailissue != null)
            {  
                if(contact.lastName == 'ApexRunTestIssue'){
                    EmailIssueRemover.test();
                } else {      
                    EmailIssueRemover.removeEmailIssue(contact.id, emailissue, contact.session_id__c, contact.server_url__c);
                }
            } 
        }
    }
}
public class EmailIssueRemover {

  // Static variable that assumes a test is not running
  public static boolean isApexTest = false;
    
  //Future annotation to mark the method as async.
  @Future(callout=true)
  public static void removeEmailIssue(String id, String issue, String sessionid, String serverurl) {

     String server = EncodingUtil.urlEncode(serverurl,'UTF-8');
     String session = EncodingUtil.urlEncode(sessionid,'UTF-8');
   
     Http h = new Http();
     HttpRequest req = buildWebServiceRequest(id, EncodingUtil.urlEncode(issue,'UTF-8'), session, server);
     if(!isApexTest){
       HttpResponse res = invokeWebService(h, req);   
     } 
  }
    
  public static HttpRequest buildWebServiceRequest(String id, String issue, String sessionid, String serverurl){

    //Build HTTP Request object
    HttpRequest req = new HttpRequest();
    req.setEndpoint('https://www.****.com/removeEmailIssue?sessionid=' + sessionid + '&serverurl='+ serverurl + '&type='+issue+'&id='+id);
    req.setMethod('GET');
    return req;
  }
  
  public static HttpResponse invokeWebService(Http h, HttpRequest req){
     HttpResponse res = h.send(req);
     return res;
  }
  
  // Wrapper method for "main" that we will call in the Test Class
  public static void test(){
    isApexTest = true;
    removeEmailIssue('test','test','test','test');
  }
}

i have a trigger that im trying to create a test for and not sure why the coverage is always 0%.

 

my trigger is

trigger InvalidEmailContactTrigger on Contact (before update)
{
    private String emailissue {get; set;}
    if(Trigger.isBefore)
    {
        emailissue = null;
        for(Contact contact : trigger.old)
        { 
            emailissue = contact.itracmedia__Email_Issue__c;
        }
        
        for(Contact contact : trigger.new)
        {            
            if(contact.itracmedia__Email_Issue__c == null && emailissue != null)
            {             
                EmailIssueRemover.removeEmailIssue(contact.id, emailissue);
            } 
        }
    }
}

 and my test code is

@isTest
private class TestInvalidEmailContactTrigger
{
    public static testmethod void testInvalidEmailContactTrigger()
    {                       
        //Insert a new instance of Contact Object with test values 
        Contact c = new Contact(LastName = 'Test');
        c.itracmedia__Email_Issue__c = 'TestIssue';
        insert c;
        c.itracmedia__Email_Issue__c = null;
        update c;
    }
}

 Can someone help me with getting this test to run successfully.

 

thanks,

NR

Is it possible for an account to have the Bulk Api enabled if using the professional edition. 

im wondering how people get around selecting fields for any specific object.  currently i have hard coded what fields i query from the api, the problem im facing is that when one of those hard coded fields are set to hidden for a specific user i get no response at all from the api. is there anyway around this except for asking all my clients to make every field visible that is needed.

what visual force component can be used to display a list of contacts.

im new to apex code and im trying to create a new tool for use in salesforce that will allow someone to segment their campaign.  i would like to create a filter criteria section like the one found in manage compaign members when u go about adding contacts/leads to a campaign. Can someone please provide the code or help me create the drop down picklists under the Field section. i know how to manually add items to the list but i would like to do in such a way that the picklist is created dynamically based on the fields the current user has available for contacts/leads.

 

thanks,

NR

i have one client trying to install our package but it is failling at the installaltion process and gives an error of Contact.Language__c: limit exceeded.  This custom field is one they already have created into there contact object. our package does contain a similar custom field with the same name but has a namespace appeneded to it which should make it unique.  i have installed the package on several developer accounts with no issues so im just really stumpped with this. Also they are trying to install this in a sandbox account and already contain 90 custom fields for the contact.  Can someone please explain what is going on here.

 

thanks,

NR

i have a problem which im finding hard to fix and is kind of urgent.  i have a third party app that connects to salesforce and uploads campiagns from salesforce to my database.  These capaigns can range from a couple contacts/leads to 100,000 and i would like to find out how its possible to upload a campaign from salesforce to my database.  im currently using the restapi to fetch the contacts and create a list on my side the problem is that im only getting 2000 records.  is it possible to create somethign along the lines of what i already have but scale it to any amount of contacts.

 

        HttpClient httpclient = new HttpClient();
        GetMethod get = new GetMethod(sfSession.getInstanceUrl() + "/services/data/v20.0/query");

        // set the token in the header
        get.setRequestHeader("Authorization", "OAuth " + sfSession.getAccessToken());

        // set the SOQL as a query param
        NameValuePair[] params = new NameValuePair[1];

        params[0] = new NameValuePair("q", "select Contact.Id, Contact.FirstName, Contact.LastName, Contact.Salutation, Contact.Title, Contact.Email, Contact.MailingStreet, Contact.MailingCity, Contact.MailingState, Contact.MailingPostalCode, Contact.MailingCountry, Contact.Phone, Contact.Fax, Contact.MobilePhone, Contact.HomePhone, Contact.LeadSource, Contact.Birthdate from CampaignMember where CampaignId = '" + campaignId + "' and Contact.Id <> NULL");
        get.setQueryString(params);

        try
        {
            httpclient.executeMethod(get);

            if (get.getStatusCode() == HttpStatus.SC_OK)
            {
                try
                {
                    JSONObject response = new JSONObject(new JSONTokener(new InputStreamReader(get.getResponseBodyAsStream())));
                    System.out.println("Auth response: " + response.toString(2));
                    JSONArray results = response.getJSONArray("records");

                    for (int i = 0; i < results.length(); i++)
                    {
                        JSONObject result = results.getJSONObject(i).getJSONObject("Contact");
                        String salesforceContactid = result.getString("Id");
                        Contacts contact = null;

                        try
                        {
                            contact = (Contacts) em.createQuery("select c from Contacts c where c.salesforceContact.salesforceContactid = :salesforceContactid")
                                    .setParameter("salesforceContactid", salesforceContactid)
                                    .getSingleResult();
                        }
                        catch (NoResultException e)
                        {
                            contact = new Contacts();
                            contact.setLists(new LinkedList<Lists>());
                            contact.setCreateDate(new Date());
                        }

                        contact.setLastModified(new Date());

                        if (!result.isNull("FirstName")) contact.setFirstname(result.getString("FirstName").substring(0, Math.min(result.getString("FirstName").length(), 40)));
                        if (!result.isNull("LastName")) contact.setLastname(result.getString("LastName").substring(0, Math.min(result.getString("LastName").length(), 40)));
                        if (!result.isNull("Salutation")) contact.setSalutation(result.getString("Salutation").substring(0, Math.min(result.getString("Salutation").length(), 10)));
                        if (!result.isNull("Title")) contact.setTitle(result.getString("Title").substring(0, Math.min(result.getString("Title").length(), 40)));
                        if (!result.isNull("Email")) contact.setEmail(result.getString("Email").substring(0, Math.min(result.getString("Email").length(), 80)));
                        if (!result.isNull("MailingStreet")) contact.setMailingaddressline1(result.getString("MailingStreet").substring(0, Math.min(result.getString("MailingStreet").length(), 80)));
                        if (!result.isNull("MailingCity")) contact.setCity(result.getString("MailingCity").substring(0, Math.min(result.getString("MailingCity").length(), 40)));
                        if (!result.isNull("MailingState")) contact.setProvince(result.getString("MailingState").substring(0, Math.min(result.getString("MailingState").length(), 40)));
                        if (!result.isNull("MailingPostalCode")) contact.setPostalcode(result.getString("MailingPostalCode").substring(0, Math.min(result.getString("MailingPostalCode").length(), 40)));
                        if (!result.isNull("MailingCountry")) contact.setCountry(result.getString("MailingCountry").substring(0, Math.min(result.getString("MailingCountry").length(), 40)));
                        if (!result.isNull("Phone")) contact.setBusinessphone(result.getString("Phone").substring(0, Math.min(result.getString("Phone").length(), 40)));
                        if (!result.isNull("Fax")) contact.setBusinessfax(result.getString("Fax").substring(0, Math.min(result.getString("Fax").length(), 40)));
                        if (!result.isNull("MobilePhone")) contact.setMobilephone(result.getString("MobilePhone").substring(0, Math.min(result.getString("MobilePhone").length(), 40)));
                        if (!result.isNull("HomePhone")) contact.setHomephone(result.getString("HomePhone").substring(0, Math.min(result.getString("HomePhone").length(), 40)));
                        if (!result.isNull("LeadSource")) contact.setLeadsource(result.getString("LeadSource").substring(0, Math.min(result.getString("LeadSource").length(), 40)));
                        if (!result.isNull("Birthdate")) contact.setBirthdate(result.getString("Birthdate").substring(0, Math.min(result.getString("Birthdate").length(), 20)));

                        // no point in creating contacts with no email
                        if (contact.getEmail() == null || contact.getEmail().isEmpty())
                        {
                            continue;
                        }

                        if (contact.getContactid() == null)
                        {
                            contact.setCreateDate(new Date());
                            // create contact
                            em.persist(contact);

                            // create mapping to sales force id
                            SalesforceContact salesforceContact = new SalesforceContact();
                            salesforceContact.setSalesforceUser(session.getUser().getSalesforceUser());
                            salesforceContact.setSalesforceContactid(salesforceContactid);
                            salesforceContact.setSalesforceType(SalesforceType.Contact);
                            salesforceContact.setContact(contact);
                            em.persist(salesforceContact);

                            // set mapping
                            contact.setSalesforceContact(salesforceContact);
                            em.merge(contact);
                        }
                        else
                        {
                            // update contact info
                            em.merge(contact);
                        }

                        // allow account access to the contact
                        if (!contact.hasAccess(session.getAccount()))
                        {
                            ContactAccount contactAccount = new ContactAccount();
                            contactAccount.setAccount(session.getAccount());
                            contactAccount.setContact(contact);
                            contactAccount.setDate(new Date());
                            em.persist(contactAccount);

                            contact.getContactAccounts().put(session.getAccount(), contactAccount);
                            em.merge(contact);
                        }

                        if (!contact.getLists().contains(list))
                        {
                            contact.getLists().add(list);
                            list.setTotalcontacts(list.getTotalcontacts() + 1);
                        }

                        // update list count
                        em.merge(list);
                    }
                }
                catch (JSONException e)
                {
                    e.printStackTrace(System.err);
                }
            }
        }
        catch (Exception e)
        {
            e.printStackTrace(System.err);
        }

 thanks,

NR

how would i be able to create a trigger for when an email address becomes invalid.  this happens when trying to send an email and the email bounces back.  the email address becomes flaged and you have to confirm it but i would like to also set a custom checkbox when this happens.

 

thanks,

NR

im trying to create a process where users can create new objects into their salesforce account from a crm site.  im trying to get the sample code below but can't get it to work. can someone please help me fix this or if im doing it totally wrong please let me know.

PostMethod m = new PostMethod(sfSession.getInstanceUrl() + "/services/data/v20.0/sobjects/Account/") {

            @Override
            public String getName() {
                return "PATCH";
            }
        };

        m.setRequestHeader("Authorization", "OAuth " + sfSession.getAccessToken());

        Map<String, Object> accUpdate = new HashMap<String, Object>();
        accUpdate.put("Name", "Patch test");
        accUpdate.put("AnnualRevenue", 10);
        ObjectMapper mapper = new ObjectMapper();
        try {
            m.setRequestEntity(new StringRequestEntity(mapper.writeValueAsString(accUpdate), "application/json", "UTF-8"));
        } catch (UnsupportedEncodingException ex) {
            Logger.getLogger(Iprofile.class.getName()).log(Level.SEVERE, null, ex);
        }

        HttpClient c = new HttpClient();
        int sc = c.executeMethod(m);
        System.out.println("PATCH call returned a status code of " + sc);

 

i have 2 custom related lists in my package and when i user goes and installs my package the related lists installed do not come with any columns except for the default one. what im wondering is if it is possible to set the columns for a related list so that when someone installs my app the related list has the defined columns already set.

 

thanks,

NR

i have been trying to look for an answer to this for some time now.  is it possible to get the email templates of a user. if so what object would i be referencing.

 

thanks

im trying to download a specific document that is selected by a user. im using the code below, the url being sent is https://na7.salesforce.com/servlet/servlet.FileDownload?file=D015A0000005QphPIAS. the issue im facing is that the saved file always contains the body of the salesforce login page (the returned file code is below).

 

HttpClient httpclient = new HttpClient();
                GetMethod get = new GetMethod(salesForceFacade.getSfSession().getInstanceUrl() + "/servlet/servlet.FileDownload?file="+salesforceDocument.getId());

                // set the token in the header
                get.setRequestHeader("Authorization", "OAuth " + salesForceFacade.getSfSession().getAccessToken());
                httpclient.executeMethod(get);
                System.out.println(get.getURI());
                System.out.println(get.getDoAuthentication());
                System.out.println(get.getResponseBodyAsString());
               
               // URL url = new URL(salesForceFacade.getSfSession().getInstanceUrl()+"/servlet/servlet.FileDownload?file%3D"+salesforceDocument.getId());
                    InputStream is = get.getResponseBodyAsStream();
                    OutputStream os = new FileOutputStream("C:\\Users\\user\\Desktop\\"+salesforceDocument.getName()+"."+salesforceDocument.getType());

                    byte[] b = new byte[1024];
                    int length;

                    while ((length = is.read(b)) != -1) {
                            os.write(b, 0, length);
                    }

                    is.close();
                    os.close();

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">





<script>
var escapedHash = '';
var url = 'https://login.salesforce.com/?ec=302&startURL=%2Fservlet%2Fservlet.FileDownload%3Ffile%3D015A0000001QphPIAS';
if (window.location.hash) {
   escapedHash = '%23' + window.location.hash.slice(1);
}
if (window.location.replace){ 
window.location.replace(url + escapedHash);
} else {;
window.location.href = url + escapedHash;
} 
</script>

</head>


</html>



<!--
...................................................................................................
...................................................................................................
...................................................................................................
...................................................................................................
-->

 

im working on integrating salesforce with my companies crm software.  i have created a button in the salesforce campaign tab that alllows a user to upload all the members of the campaign to my companies database. My issues arise when a user tries to upload a campaign that is bigger than the 10000 row limit for soql queries.  im looking for some advice on how i would be able to get more than 10000 rows of data from salesforce.

i have created an app for salesforce integration that is available through the appexchange.  the issue im having is that after a user installs the app in their salesforce they are not able to view any of the custom buttons that i have created unless they manually change there page layout.  the package contains all components that were modified including fields, buttons and page layouts. 

 

i need to get this fixed and wondering why it would happen.

 

thanks

Nelson

I'm having an issue with my trigger that is confusing me.  My trigger is called on a before update when a specific field on the contact becomes empty.  My trigger code calls a separate @future apex class only if the field i check against begins populated before the save and then becomes empty and then makes a callout to an external system. There is also a third party batch process that does upserts on all contacts every night and updates some fields.  The field that fires off the callout is never modyfied during this batch process.

 

The problem is during the nightly batch process the upserts are causing my trigger to call the @future class causing it to throw an error.

 

caused by: System.DmlException: Update failed. First exception on row 0 with id 0033000000z3r2cAAA; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, InvalidEmailContactTrigger: execution of BeforeUpdate

caused by: System.AsyncException: Future method cannot be called from a future or batch method: EmailIssueRemover.removeEmailIssue(MAP<Id,String>, String, String)

 

for(Contact contact : trigger.old)
        { 
            emailissue = contact.Email_Issue__c;
        }
        
        for(Contact contact : trigger.new)
        {            
            if(contact.Email_Issue__c == null && emailissue != null)
            {  
                contactsToUpdate.put(contact.Id, emailissue);
                session = contact.session_id__c;
                server = contact.server_url__c;
                lastName = contact.lastName;
                changed = true;
            } 
        }
        if(lastName == 'ApexRunTestIssue'){
            EmailIssueRemover.test(contactsToUpdate);
        } else {     
            if(changed){
                EmailIssueRemover.removeEmailIssue(contactsToUpdate, session, server);
            }
        }

 

 

Can anyone explain why this might happen.

I have built a trigger that is called when a contact/lead is updated. This trigger calls a @future method with a callout when a specific field (Email_Issue__c) starts off populated and is then saved to null.

One of our clients has a night batch upload that does an upsert on all its contacts and even though the Email_issue__c is not one of the fields being updated in the batch somehow the callout is going through. When looking through the bulk data load jobs we see the error CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:itracmedia.InvalidEmailContactTrigger: System.LimitException: itracmedia:Too many future calls: 11:-- for about 100 of 5000 records it processes.

Can someone please explain why this might be happening and what i can do to fix this issue.

 

Trigger

trigger InvalidEmailContactTrigger on Contact (before update)
{
    private String emailissue {get; set;}
    if(Trigger.isBefore)
    {
        emailissue = null;
        for(Contact contact : trigger.old)
        { 
            emailissue = contact.itracmedia__Email_Issue__c;
        }
        
        for(Contact contact : trigger.new)
        {            
            if(contact.itracmedia__Email_Issue__c == null && emailissue != null)
            {  
                if(contact.lastName == 'ApexRunTestIssue'){
                    EmailIssueRemover.test();
                } else {      
                    EmailIssueRemover.removeEmailIssue(contact.id, emailissue, contact.itracmedia__session_id__c, contact.itracmedia__server_url__c);
                }
            } 
        }
    }
}

 

Apex Class:

public class EmailIssueRemover {

  // Static variable that assumes a test is not running
  public static boolean isApexTest = false;
    
  //Future annotation to mark the method as async.
  @Future(callout=true)
  public static void removeEmailIssue(String id, String issue, String sessionid, String serverurl) {

     String server = EncodingUtil.urlEncode(serverurl,'UTF-8');
     String session = EncodingUtil.urlEncode(sessionid,'UTF-8');
   
     Http h = new Http();
     HttpRequest req = buildWebServiceRequest(id, EncodingUtil.urlEncode(issue,'UTF-8'), session, server);
     if(!isApexTest){
       HttpResponse res = invokeWebService(h, req);   
     } 
  }
    
  public static HttpRequest buildWebServiceRequest(String id, String issue, String sessionid, String serverurl){

    //Build HTTP Request object
    HttpRequest req = new HttpRequest();
    req.setEndpoint('https://www.**.com/removeEmailIssue?sessionid=' + sessionid + '&serverurl='+ serverurl + '&type='+issue+'&id='+id);
    req.setMethod('GET');
    return req;
  }
  
  public static HttpResponse invokeWebService(Http h, HttpRequest req){
     HttpResponse res = h.send(req);
     return res;
  }
  
  // Wrapper method for "main" that we will call in the Test Class
  public static void test(){
    isApexTest = true;
    removeEmailIssue('test','test','test','test');
  }
}

 


My setup: I have a trigger that gets fired whenever a specific custom field for a contact object is deleted.  the trigger invokes a @future apex method that sends a callout to an external system.  The trigger was designed such that from a contacts page view the field can be deleted and it would sync with the other system.

 

The problem i am facing is that there is a nightly batch script that runs and throws the error CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY:itracmedia.InvalidEmailContactTrigger: System.LimitException: itracmedia:Too many future calls: 11:-- for about 100 of 5000 records it processes. 

 

I understand that the error is caused form the @future method being invoked more than 10 times, but from what i understood from reading the documentation is that the limit is focused on one trigger instance invoking the @future method more than 10 times. I believe that my trigger invokes the @future method only once for each contact that gets updated.  is it possible to get this error if the script runs so fast that there are 10 callouts being made at the same time and the 11th starts before any have finished yet.

 

My code is below for both the trigger and apex class.

 

Can someone please explain how this is happening and if you can please help me in finding a solution.

 

trigger InvalidEmailContactTrigger on Contact (before update)
{
    private String emailissue {get; set;}
    if(Trigger.isBefore)
    {
        emailissue = null;
        for(Contact contact : trigger.old)
        { 
            emailissue = contact.Email_Issue__c;
        }
        
        for(Contact contact : trigger.new)
        {            
            if(contact.Email_Issue__c == null && emailissue != null)
            {  
                if(contact.lastName == 'ApexRunTestIssue'){
                    EmailIssueRemover.test();
                } else {      
                    EmailIssueRemover.removeEmailIssue(contact.id, emailissue, contact.session_id__c, contact.server_url__c);
                }
            } 
        }
    }
}
public class EmailIssueRemover {

  // Static variable that assumes a test is not running
  public static boolean isApexTest = false;
    
  //Future annotation to mark the method as async.
  @Future(callout=true)
  public static void removeEmailIssue(String id, String issue, String sessionid, String serverurl) {

     String server = EncodingUtil.urlEncode(serverurl,'UTF-8');
     String session = EncodingUtil.urlEncode(sessionid,'UTF-8');
   
     Http h = new Http();
     HttpRequest req = buildWebServiceRequest(id, EncodingUtil.urlEncode(issue,'UTF-8'), session, server);
     if(!isApexTest){
       HttpResponse res = invokeWebService(h, req);   
     } 
  }
    
  public static HttpRequest buildWebServiceRequest(String id, String issue, String sessionid, String serverurl){

    //Build HTTP Request object
    HttpRequest req = new HttpRequest();
    req.setEndpoint('https://www.****.com/removeEmailIssue?sessionid=' + sessionid + '&serverurl='+ serverurl + '&type='+issue+'&id='+id);
    req.setMethod('GET');
    return req;
  }
  
  public static HttpResponse invokeWebService(Http h, HttpRequest req){
     HttpResponse res = h.send(req);
     return res;
  }
  
  // Wrapper method for "main" that we will call in the Test Class
  public static void test(){
    isApexTest = true;
    removeEmailIssue('test','test','test','test');
  }
}

i have a trigger that im trying to create a test for and not sure why the coverage is always 0%.

 

my trigger is

trigger InvalidEmailContactTrigger on Contact (before update)
{
    private String emailissue {get; set;}
    if(Trigger.isBefore)
    {
        emailissue = null;
        for(Contact contact : trigger.old)
        { 
            emailissue = contact.itracmedia__Email_Issue__c;
        }
        
        for(Contact contact : trigger.new)
        {            
            if(contact.itracmedia__Email_Issue__c == null && emailissue != null)
            {             
                EmailIssueRemover.removeEmailIssue(contact.id, emailissue);
            } 
        }
    }
}

 and my test code is

@isTest
private class TestInvalidEmailContactTrigger
{
    public static testmethod void testInvalidEmailContactTrigger()
    {                       
        //Insert a new instance of Contact Object with test values 
        Contact c = new Contact(LastName = 'Test');
        c.itracmedia__Email_Issue__c = 'TestIssue';
        insert c;
        c.itracmedia__Email_Issue__c = null;
        update c;
    }
}

 Can someone help me with getting this test to run successfully.

 

thanks,

NR

Is it possible for an account to have the Bulk Api enabled if using the professional edition. 

i have 2 custom related lists in my package and when i user goes and installs my package the related lists installed do not come with any columns except for the default one. what im wondering is if it is possible to set the columns for a related list so that when someone installs my app the related list has the defined columns already set.

 

thanks,

NR

im trying to download a specific document that is selected by a user. im using the code below, the url being sent is https://na7.salesforce.com/servlet/servlet.FileDownload?file=D015A0000005QphPIAS. the issue im facing is that the saved file always contains the body of the salesforce login page (the returned file code is below).

 

HttpClient httpclient = new HttpClient();
                GetMethod get = new GetMethod(salesForceFacade.getSfSession().getInstanceUrl() + "/servlet/servlet.FileDownload?file="+salesforceDocument.getId());

                // set the token in the header
                get.setRequestHeader("Authorization", "OAuth " + salesForceFacade.getSfSession().getAccessToken());
                httpclient.executeMethod(get);
                System.out.println(get.getURI());
                System.out.println(get.getDoAuthentication());
                System.out.println(get.getResponseBodyAsString());
               
               // URL url = new URL(salesForceFacade.getSfSession().getInstanceUrl()+"/servlet/servlet.FileDownload?file%3D"+salesforceDocument.getId());
                    InputStream is = get.getResponseBodyAsStream();
                    OutputStream os = new FileOutputStream("C:\\Users\\user\\Desktop\\"+salesforceDocument.getName()+"."+salesforceDocument.getType());

                    byte[] b = new byte[1024];
                    int length;

                    while ((length = is.read(b)) != -1) {
                            os.write(b, 0, length);
                    }

                    is.close();
                    os.close();

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta HTTP-EQUIV="PRAGMA" CONTENT="NO-CACHE">





<script>
var escapedHash = '';
var url = 'https://login.salesforce.com/?ec=302&startURL=%2Fservlet%2Fservlet.FileDownload%3Ffile%3D015A0000001QphPIAS';
if (window.location.hash) {
   escapedHash = '%23' + window.location.hash.slice(1);
}
if (window.location.replace){ 
window.location.replace(url + escapedHash);
} else {;
window.location.href = url + escapedHash;
} 
</script>

</head>


</html>



<!--
...................................................................................................
...................................................................................................
...................................................................................................
...................................................................................................
-->

 

im working on integrating salesforce with my companies crm software.  i have created a button in the salesforce campaign tab that alllows a user to upload all the members of the campaign to my companies database. My issues arise when a user tries to upload a campaign that is bigger than the 10000 row limit for soql queries.  im looking for some advice on how i would be able to get more than 10000 rows of data from salesforce.