• Keaton Klein
  • NEWBIE
  • 75 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 11
    Questions
  • 14
    Replies
I have been using the soap API and the following line has been working great.
qr1 = binding.queryAll("select id, external_id__c from contact where external_id__C like '%" + naidno2 + "%'");
I am now trying to do something similar using the REST API and I am getting a 400 error.  If I remove the wild cards then the query runs just fine but in some cases the wild cards are necessary.
 
xhr8.open("GET", "https://na17.salesforce.com/services/data/v34.0/query/?q=select id, name from contact where cheetah_id__c like '%" + ContactCode + "%'");

 
Okay, i have this trigger which seems to work for all of its intended purposes but occasionally we are getting a CPU Limit Exception.  I've noticed that we get the CPU Limi Exception while Marketo is trying to update the Lead Score.  Any thoughts?
trigger LeadTrigger on Lead (after insert, after update, before insert, before update) {
    
     if (!FollowUpTaskHelper.hasAlreadyCreatedFollowUpTasks()) {    
             FollowUpTaskHelper.setAlreadyCreatedFollowUpTasks();
         string stringfield = '';
         Lead LeadLog = new Lead();
    Set<Id> Taskids = new Set<Id>();
    Set<Id> CloseRelatedTaskIds = new Set<Id>();
    Set<Id> CloseRelatedTaskIds2 = new Set<Id>();
    Set<Id> ReassignTaskLeads = new Set<Id>();
    Set<Id> NothingTranspiredTaskIds = new Set<Id>();
    Set<Id> TrustIds = new Set<Id>();
	Map<Id,task> TasksToUpdate = new Map<Id,Task>();
	Map<Id,task> TasksToUpdate2 = new Map<Id,Task>();
    Map<Id,task> TasksToUpdateRA = new Map<Id,Task>();
    Map<Id,lead> LeadsToUpdate = new Map<Id,Lead>();
    Map<Id,lead> LeadsToUpdate2 = new Map<Id,Lead>();
    Task TaskLog = new Task();
    Task TaskLog2 = new Task();
 string thefield123 = '';
            string thefield1234 ='';
    List<Lead> ls = new List<Lead>();
    list<user> ldusers = [select id, name from user where name = 'marketo' OR name = 'Marketo' OR name = 'Brad Davis' OR name = 'brad davis' order by name];      
   
    for(lead a: trigger.new)
    {
        if(a.isconverted == false){
        
                if(ldusers.size() != 0){
        if(a.ownerid == ldusers[1].id){
            a.ownerid = ldusers[0].id;
        }
        if(a.ownerid ==ldusers[0].id){
        ls.add(new Lead(id = a.id));
        }
    }
 
  
    Database.DMLOptions dmo = new Database.DMLOptions();
    dmo.assignmentRuleHeader.useDefaultRule = true;
    dmo.EmailHeader.triggerUserEmail = true;    
    Database.update(ls, dmo);        
      
        if( a.Close_All_Current_Marketo_Open_Tasks__c == true  )
        {
            a.Close_All_Current_Marketo_Open_Tasks__c = false;
            CloseRelatedTaskIds.add(a.Id);
        }
             CloseRelatedTaskIds2.add(a.Id);    
			leadstoupdate2.put(a.id, a);
        
    }
     }
         
         
    
    for(task t:[SELECT id, whoid, subject, ownerid from task WHERE (whoid in: CloseRelatedTaskIds AND status != 'completed') OR (whoid in: CloseRelatedTaskIds2 AND status != 'completed') limit 100]){
        if(CloseRelatedTaskIds.contains(t.whoId))	{
        if(t.subject.contains('marketo') || t.subject.contains('Marketo') || t.subject.contains('MARKETO')){
        taskstoupdate.put(t.Id, t);
        
            if(taskstoupdate.get(t.Id) != null){
            tasklog = TasksToUpdate.get(t.id);
            tasklog.status = 'completed';
            stringfield = tasklog.subject;
            
            tasklog.subject = tasklog.subject + 'Set by trigger ezwf';
            taskstoupdate.put(tasklog.Id,tasklog);    

           }
   }
    }
         if(CloseRelatedTaskIds2.contains(t.whoId))	{
         			taskstoupdate2.put(t.Id, t);
        
            if(taskstoupdate2.get(t.Id) != null){
            tasklog2 = TasksToUpdate2.get(t.id);
            LeadLog = leadstoupdate2.get(t.WhoId);    
            tasklog2.ownerid = Leadlog.ownerid;
            TasksToUpdate2.put(TaskLog2.Id,TaskLog2);   
           }
         }
        
    }


       
      if(taskstoupdate != null && taskstoupdate.values() != null &&taskstoupdate.values().size() > 0){
        update TasksToUpdate.values();
    } 
               if(taskstoupdate2 != null && taskstoupdate2.values() != null &&taskstoupdate2.values().size() > 0){
        update TasksToUpdate2.values();
    } 
FollowUpTaskHelper.setAlreadyCreatedFollowUpTasksFalse();
     }
    
}

 
I have 2 triggers which are nearly identical, one sends an email to Leads and the other sends emails to Contacts.  They both work but the HTML Status related list is only populated for the emails sent to Contacts.  When an email is sent to a lead it shows up under activity history but not HTML Status.  It is important to be able to see if/when an email was opened.

I have snippets from both the Lead and Contact triggers so you can see they are nearly identical.  Any thoughts on why HTML Status works for my Contacts but not my Leads?
 
if (combine==true){        
                   	contactlog = mapcontactToUpdate.get(e.id);	
                	mapcontactToUpdate.put(contactlog.id, contactlog);
                    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                    string etidasstring = a.ezwf__Email_Template_ID__c;
                    emailt = e.Lastname; 
                    mail.setSenderDisplayName(UserInfo.getName());
                    mail.setReplyTo(UserInfo.getUserEmail()); 
                    mail.setTargetObjectId(e.id);
                    mail.setTemplateId(etidasstring);
                    mail.setSaveAsActivity(true); 
                	myEmails.add(mail);	
            }
              if (myEmails.size() > 0)
            {
                       Messaging.sendEmail(myEmails);
            }

if (combine==true){        
                   	Leadlog = mapLeadToUpdate.get(e.id);	
                	mapLeadToUpdate.put(Leadlog.id, Leadlog);
                    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                    string etidasstring = a.ezwf__Email_Template_ID__c;
                    emailt = e.Lastname; 
                    mail.setSenderDisplayName(UserInfo.getName());
                    mail.setReplyTo(UserInfo.getUserEmail()); 
                    mail.setTargetObjectId(e.id);
                    mail.setTemplateId(etidasstring);
                    mail.setSaveAsActivity(true); 
                	myEmails.add(mail);	
            }
              if (myEmails.size() > 0)
            {
                       Messaging.sendEmail(myEmails);
            }

 
I have a trigger which uses mass email message to send to a list of leads.  It works great when leadids is populated with 5 or 6 IDs but if it is populatd with 7 or more i get the error message stating MASS_MAIL_LIMIT_EXCEEDED, Failed to send email: []

It is my understanding that we can use mass email to send to a list of up to 250 leads/contacts.  Any thoughts on why i am being limited to 6?  Below is a snippet from my code.

Also, when the emails are sent it shows up under Activity History but it does not show up under HTML Email Status so i cannot see if the email was opened by the recipient.
 
if (LeadIds != null && !LeadIds.isEmpty())
            {
                	Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();

                	string etidasstring = a.ezwf__Email_Template_ID__c;
                     
                    mail.setSenderDisplayName(UserInfo.getName());
                    mail.setReplyTo(UserInfo.getUserEmail()); 
                    
                    mail.setTargetObjectIds(LeadIds); 
                    mail.setTemplateId(etidasstring);
                    mail.setSaveAsActivity(true); 
                     
                    Messaging.sendEmail(new Messaging.MassEmailMessage[] {mail});
            }

 
I have a picklist which gives the option to select an object (contact, lead, account, etc).  I have a second and third picklist which allow you to pick a field (depending on the object selected in the previous picklist). 

The object picklist has an action support tag which updates the field picklist when the object picklist is updated, this works great.

 <apex:actionSupport event="onchange" rerender="picklist1" />

What i would like is to have 2 field picklists, both of which are updated depending on the object picklist being changed.  Something like...

 <apex:actionSupport event="onchange" rerender="picklist1; picklist2" />

Any input would be appreciated.  Thank you :)


 
Alright, I have a controller which works without errors but I am attempting to use it as an extension to the custom controller for a VF page.  When I update the VF page to use the standard controller I get the following error.

Visualforce Error
System.NullPointerException: Attempt to de-reference a null object
Class.ezwf.objectController.getObjectFields: line 59, column 1

I have posted the extension and the VF page below.  Any tips would be greaty appreciated.

 
public with sharing class testme {
private final Auto_ab__c ezab;
    public testme(ApexPages.StandardController stdController) {
        this.ezab = (Auto_ab__c)stdController.getRecord();
    }
    
    public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();

    public String selectedObject {get; set;}
    
    public Auto_ab__c testContact1a;
    
    public String AutoabName {get; set;}
    
    public String TriggerValue {get; set;}
    
    public String abTemplateID {get; set;}
    
    public String selectedField {get; set;}
    
    public String selectedab {get; set;}
    
    public String templatename {get; set;}
    
    public String addobject {get; set;}
    
    public String editid {get; set;}

    public String abid;
    
    
    Public testme()
    {   
        selectedObject = 'account';
    }

    public List<SelectOption> getObjectNames() 
    {
        List<SelectOption> objNames = new List<SelectOption>();
        List<String> entities = new List<String>(schemaMap.keySet());
        entities.sort();
        for(String name : entities)
        {
            objNames.add(new SelectOption(name,name));
        }
        return objNames;
     }
    
    ///////////
    
        
    ///////////

     public List<SelectOption> getObjectFields() 
     {
            Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
            Schema.SObjectType ObjectSchema = schemaMap.get(selectedObject);
            Map<String, Schema.SObjectField> fieldMap = ObjectSchema.getDescribe().fields.getMap();
            List<SelectOption> fieldNames = new List<SelectOption>();
            for (String fieldName: fieldMap.keySet()) 
            {  
                fieldNames.add(new SelectOption(fieldName,fieldName));
              //fieldMap.get(fieldName).getDescribe().getLabel();//It provides to get the object fields label.
            }
            return fieldNames;        
      }
         
    public List<SelectOption> getObjectabs() 
     {
                         List<SelectOption> abNames = new List<SelectOption>();
         for (abTemplate abName: [select id, name from abtemplate]) 
            {  
                abNames.add(new SelectOption(abname.id,abname.name));
              //fieldMap.get(fieldName).getDescribe().getLabel();//It provides to get the object fields label.
            }
            return abNames;
     }
    
    /*
    public string getTemplateName()
    {
        
        
    }
        */

    
    public List<Selectoption> getAllCustomSObjects()
{
    List<Selectoption> sObjectList = new List<Selectoption>();
    for(Schema.SObjectType objTyp : Schema.getGlobalDescribe().Values())
    {
        Schema.DescribeSObjectResult describeSObjectResultObj = objTyp.getDescribe();
        if(describeSObjectResultObj.isCustom())
        {
            String name = objTyp.getDescribe().getName();
            // Exclude all the unwanted Sobjects e.g. History, Share etc..
            if(!name.containsignorecase('history') && !name.containsignorecase('tag')&&
             !name.containsignorecase('share') && !name.containsignorecase('feed'))
            {
                //SobjectList.add(name);
                SobjectList.add(new SelectOption(name,name));
            }
        }
    }
    system.debug('SObjectList****' + SObjectList);
    return SObjectList;
}
public PageReference save() {   
    Contact testContact1a = new Contact(LastName='TestContact',  description = 'TestContact');
    //public String templatename { get {return [SELECT state__c FROM site__c WHERE id = :site LIMIT 1].state__c; } set; }
             string templatename = [select name from abtemplate where id =:Selectedab].name;
             Auto_ab__c newdata = new Auto_ab__c(name=AutoabName, trigger_value_1__c=TriggerValue, Object_1__c=selectedObject,  Trigger_Field_1__c = selectedField, ab_Template_ID__c=Selectedab, ab_Template_name__c=TemplateName );
             insert newdata;
            return Page.Easyab;
    }
    
    public PageReference edit() {   
    Contact testContact1a = new Contact(LastName='TestContact',  description = 'TestContact');
    //public String templatename { get {return [SELECT state__c FROM site__c WHERE id = :site LIMIT 1].state__c; } set; }
             string templatename = [select name from abtemplate where id =:Selectedab].name;
             Auto_ab__c newdata = new Auto_ab__c(id=ApexPages.currentPage().getParameters().get('id'), name=AutoabName, trigger_value_1__c=TriggerValue, Object_1__c=selectedObject,  Trigger_Field_1__c = selectedField, ab_Template_ID__c=Selectedab, ab_Template_name__c=TemplateName );
             update newdata;
            return Page.Easyab;
    }
    
}
 
<apex:page standardcontroller="Auto_ab__c" extensions="objectcontroller">
<apex:form > 
      <apex:pageBlock >
<apex:pageBlockSection columns="2">
    <apex:pageBlockSectionItem >
        <apex:outputlabel value="Name/Description:"/>
                  <apex:inputText value="{!AutoabName}" />
    </apex:pageBlockSectionItem>
                  <apex:pageBlockSectionItem >
                  <apex:outputlabel value="Object Names :"/> 
                      <apex:actionRegion >
                           	<apex:selectList value="{!selectedObject}" size="1">
                            <apex:selectOption itemValue="Contact" itemLabel="Contact"/>
            				<apex:selectOption itemValue="Lead" itemLabel="Lead*" />
                            <apex:actionSupport event="onchange" rerender="myFields"/>
                            </apex:selectList>
                     </apex:actionRegion>                         
              </apex:pageBlockSectionItem>
          </apex:pageBlockSection>

<apex:pageBlockSection columns="2">

    

              <apex:pageBlockSectionItem >
                      <apex:outputlabel value="Field Names :"/>   
                      <apex:outputPanel id="myFields">   
                        <apex:actionRegion >  
                           <apex:selectList value="{!selectedField}" size="1">
                                <apex:selectOptions value="{!ObjectFields}"/>
                            </apex:selectList>
                        </apex:actionRegion>      
                     </apex:outputPanel>
              </apex:pageBlockSectionItem>
              
            <apex:pageBlockSectionItem >
                <apex:outputlabel value="Trigger Value:"/>
                          <apex:inputText value="{!TriggerValue}" />
            </apex:pageBlockSectionItem>
              
          </apex:pageBlockSection>
          
<apex:pageBlockSection columns="2">

    

              <apex:pageBlockSectionItem >
                      <apex:outputlabel value="ab Names :"/>   
                      <apex:outputPanel id="myabs">   
                        <apex:actionRegion >  
                           <apex:selectList value="{!selectedab}" size="1">
                                <apex:selectOptions value="{!objectabs}"/>
                            </apex:selectList>
                        </apex:actionRegion>      
                     </apex:outputPanel>
              </apex:pageBlockSectionItem>

              
          </apex:pageBlockSection>
          
                    <apex:pageBlockButtons >
        <apex:commandButton action="{!save}" value="Save"/>
        <apex:commandButton action="{!edit}" value="Edit"/>
      </apex:pageBlockButtons>
      </apex:pageBlock>

  </apex:form>
</apex:page>

 
I have the following code which works for the opportunity object, but when i duplicated the code for some other objects i am getting an error stating that i have too many SQL queries.  
Set<Id> OpportunityIds = new Set<Id>();
    Map<Id,Opportunity> mapOpportunityLogWithId = new Map<Id,Opportunity>();
    Map<Id,Opportunity> mapOpportunityLogToUpdate = new Map<Id,Opportunity>();    

    for(Opportunity a:[SELECT Description FROM Opportunity WHERE ID IN:OpportunityIds]){
        mapOpportunityLogWithId.put(a.Id,a);
    }
How do i bulkify the for loop, making it more efficient with less SQL queries?  I attempted something like the code below but on line 6 i get a problem stating "Initial term of field expression must be a concrete SObject: List"
Set<Id> OpportunityIds = new Set<Id>();
    List<Opportunity> mapOpportunityLogWithId = new List<Opportunity>();
    Map<Id,Opportunity> mapOpportunityLogToUpdate = new Map<Id,Opportunity>();    

    for(Opportunity[] a:[SELECT Description FROM Opportunity WHERE ID IN:OpportunityIds]){
        mapOpportunityLogWithId.put(a.Id,a);
    }

 
I have a C# program what was working great until i modified this query.  The query currently reads...

qr1 = binding.queryAll("select id, external_id__c from contact where external_id__C in '" + naidno2 + "'");

This line of code produces this error message... "Binding variable only allowed in Apex code"

naidno2 is a string which contains unique IDs separated by commas, i.e. "A4568,R4568,D6548,A4568"
 
I have this trigger with the following test and i am only getting 31% coverage.  The concept of test still has me confused, any help would be greatly appreciated.
trigger AcceptanceSigned on Task (after insert, after update) {
    Set<Id> LogIds = new Set<Id>();
    Map<Id,Account> mapacctLogWithId = new Map<Id,Account>();
    Map<Id,Account> mapAccLogToUpdate = new Map<Id,Account>();
    
    for(Task t: trigger.new){
        if(t.WhatId != null && string.valueof(t.WhatId).startsWith('a01')){
            LogIds.add(t.WhatId);
        }
    }
    for(Account a:[SELECT Description, easy_workflow__c FROM Account WHERE ID IN:LogIds]){
        mapacctLogWithId.put(a.Id,a);
    }
    
    for(Task t: trigger.new){
        if(t.WhatId != null && string.valueof(t.WhatId).startsWith('a01') && t.Status == 'Completed' && mapacctLogWithId != null && mapacctLogWithId.get(t.WhatId) != null){
            Account accLog = new Account();
            if(mapAccLogToUpdate != null && mapAccLogToUpdate.get(t.WhatId) != null){
                accLog = mapAccLogToUpdate.get(t.WhatId);
            }
            else if(mapAccLogToUpdate != null && mapAccLogToUpdate.get(t.WhatId) == null){
                accLog = mapacctLogWithId.get(t.WhatId);
            }
            accLog.easy_workflow__c = accLog.easy_workflow__c + ';'+ t.subject;
            //accLog.easy_workflow__c = accLog.easy_workflow__c.replace(t.subject,'');
            if(t.Subject == 'Sign Acceptance Form'){
                accLog.Description = 'Acceptance Form Signed';    
            }
            mapAccLogToUpdate.put(accLog.Id,accLog);
        }
        
                if(t.WhatId != null && string.valueof(t.WhatId).startsWith('a01') && t.Status == 'Open' && mapacctLogWithId != null && mapacctLogWithId.get(t.WhatId) != null){
            Account accLog = new Account();
            if(mapAccLogToUpdate != null && mapAccLogToUpdate.get(t.WhatId) != null){
                accLog = mapAccLogToUpdate.get(t.WhatId);
            }
            else if(mapAccLogToUpdate != null && mapAccLogToUpdate.get(t.WhatId) == null){
                accLog = mapacctLogWithId.get(t.WhatId);
            }
            //accLog.easy_workflow__c = accLog.easy_workflow__c + ';'+ t.subject
                    if(accLog.easy_workflow__c != null && accLog.easy_workflow__c !=''){
            accLog.easy_workflow__c = accLog.easy_workflow__c.replace(t.subject,'');
                    }
            if(t.Subject == 'Sign Acceptance Form'){
                accLog.Description = 'Acceptance Form Signed';    
            }
            mapAccLogToUpdate.put(accLog.Id,accLog);
        }
    
    if(mapAccLogToUpdate != null && mapAccLogToUpdate.values() != null &&mapAccLogToUpdate.values().size() > 0){
        update mapAccLogToUpdate.values();
    }
    } }
@isTest(SeeAllData = true)
public class AcceptanceSignedTest {
         public static testMethod void testAcceptanceSigned(){
             test.startTest();
             Account testLog = new Account(name='Test', description = 'Test');
             insert testLog;
             
             Task testTask = new Task(Subject = 'Sign Acceptance Form', whatId = testLog.ID, Status = 'Completed');
             insert testTask;
             
             Account testLog2 = new Account(name='Test2', description = 'Test2');
             insert testLog2;
             
             Task testTask2 = new Task(Subject = 'Test', whatId = testLog2.ID, Status = 'Completed');
             insert testTask2;
             
             Account testLoga = new Account(name='Test', description = 'Test');
             insert testLoga;
             
             Task testTaska = new Task(Subject = 'Sign Acceptance Form', whatId = testLog.ID, Status = 'Open');
             insert testTaska;
             
             Account testLog2a = new Account(name='Test2', description = 'Test2');
             insert testLog2a;
             
             Task testTask2a = new Task(Subject = 'Test', whatId = testLog2.ID, Status = 'Open');
             insert testTask2a;
             test.stopTest();
        }
}


 
I have the trigger & test below which is giving me 38% coverage.  I am very new to APEX and the testing still has me confused.  Any help on creating a test class for this trigger would be greatly appreciated.
 
trigger AcceptanceSigned on Task (after insert, after update) {
    Set<Id> LogIds = new Set<Id>();
for(Task t: [SELECT Subject,WhatId, Status FROM TASK WHERE ID IN:trigger.new]){
String wId = t.WhatId;
if(wId!=null && wId.startsWith('a01') && !LogIds.contains(t.WhatId) && t.Status == 'Completed' && t.Subject == 'Sign Acceptance Form'){
LogIds.add(t.WhatId);
    for(Account_Log__c a:[SELECT Stage__c, status_list__c FROM Account_Log__c WHERE ID IN:LogIds]){
                 a.Stage__c = 'Acceptance Form Signed';
        update a; 
}
}  
    if(wId!=null && wId.startsWith('a01') && !LogIds.contains(t.WhatId) && t.Status == 'Completed'){
LogIds.add(t.WhatId);
    for(Account_Log__c a:[SELECT Stage__c, Status_List__c FROM Account_Log__c WHERE ID IN:LogIds]){
        		 a.Status_List__c = a.Status_List__c + ';'+ t.subject;
        update a; 
}
}  
}  
}
 
@isTest
public class AcceptanceSignedTest {
         private static testMethod void testAcceptanceSigned(){
             test.startTest(); 
             Account_Log__c testLog = new Account_Log__c(Grantor_and_or_Family_Trustee_etc_1__c='Test');
             testLog.Grantor_and_or_Family_Trustee_etc_2__c = 'Test';
             insert(testLog);
             LIST<Account_Log__c> a = [SELECT ID, Grantor_and_or_Family_Trustee_etc_1__c FROM Account_Log__c WHERE Grantor_and_or_Family_Trustee_etc_1__c = 'Test'];
             Task testTask = new Task(Subject = 'Test', whatId = a[0].ID); 
             insert(testTask); 
             Account_Log__c updatedLog = [SELECT Grantor_and_or_Family_Trustee_etc_1__c FROM Account_Log__c WHERE Grantor_and_or_Family_Trustee_etc_1__c = 'Test'];
             system.AssertEquals('Test',updatedLog.Grantor_and_or_Family_Trustee_etc_1__c);
             test.stopTest(); 
        }
}

 
I have written some code which adds records to an object.  In case case i am trying to add a record to a custom object.  When running this code i get an error message stating that the sObject type 'Trust_Contact__C' is not supported.  As a test a created a new custom object 'Test_Object__C" and ran the same exact code but changed the type to 'Test_Object__C' and i commented out the a few of the fields (second code sample).  What really confuses me is that it worked with the Test Object and not with the Trust Contact object.  I also inserted screenshots from each object in Salesforce.  Any ideas?
 
cmd.CommandText = "SELECT  top(10)   dbo.keat_crossreference.* FROM  dbo.keat_crossreference";
                cmd.CommandType = CommandType.Text;
                cmd.Connection = sqlConnection1;

                sqlConnection1.Open();

                reader = cmd.ExecuteReader();
                var nexty = reader;
                // Data is accessible through the DataReader object here.
                int ir = 0;
                sObject[] cons = new sObject[1];
                apex.sObject contact;
                var pretrust ="pre";
                var buildid = "";
                var pair = "";
                var crdesc = "";
                var acctno = "";
                var naidno = "";
                while (reader.Read())
                {
                    if (reader.GetValue(reader.GetOrdinal("account_no")).ToString()==pretrust)
                    {
                         
                         buildid = buildid +','+ reader.GetValue(reader.GetOrdinal("buildid")).ToString();
                         pair = pair + ',' + reader.GetValue(reader.GetOrdinal("pair")).ToString();
                         crdesc = crdesc + ',' + reader.GetValue(reader.GetOrdinal("cross_ref_type_cd_dsc")).ToString();
                         acctno = acctno + ',' + reader.GetValue(reader.GetOrdinal("account_no")).ToString();
                         naidno = naidno + ',' + reader.GetValue(reader.GetOrdinal("name_addr_id")).ToString();
                         pretrust = reader.GetValue(reader.GetOrdinal("account_no")).ToString();
                        ir++;
                    }
                    else
                    {
                    ir++;
                    pretrust = reader.GetValue(reader.GetOrdinal("account_no")).ToString();
                    //Verify that we are already authenticated, if not
                    //call the login function to do so
                    if (!loggedIn)
                    {
                        if (!login())
                            return;
                    }

                    try
                    {

                        for (int j = 0; j < cons.Length; j++)
                        {
                            contact = new apex.sObject();
                            int index = 0;
                            System.Xml.XmlElement[] cont = new System.Xml.XmlElement[17];
                            if (accounts != null)
                            {
                                cont = new System.Xml.XmlElement[cont.Length + 1];
                                cont[index++] = GetNewXmlElement("AccountId", accounts[0]);
                            }

                            cont[index++] = GetNewXmlElement("contact__C", naidno);
                            cont[index++] = GetNewXmlElement("Relationship_Type__c", crdesc);
                            //cont[index++] = GetNewXmlElement("Role__c", addy1);
                            cont[index++] = GetNewXmlElement("Trust__c", acctno);
                            contact.Any = cont;
                            contact.type = "Trust_Contact__C";
                            cons[j] = contact;
                        }
                        SaveResult[] sr = binding.create(cons);

//cont[index++] = GetNewXmlElement("contact__C", naidno);
                            //cont[index++] = GetNewXmlElement("Relationship_Type__c", crdesc);
                            //cont[index++] = GetNewXmlElement("Role__c", addy1);
                            cont[index++] = GetNewXmlElement("name", acctno);
                            contact.Any = cont;
                            contact.type = "Test_Object__c";
                            cons[j] = contact;

Test ObjectTrust Contact
Hi,

I'm quite new to SalesForce and I've been trying to build a Python script that allows me to update a specific record like case, account, etc.
I really need help on this as I am stuck right now finding a solution.  Your help and guidance will be very much appreciated.

Thanks in advance...
I have been using the soap API and the following line has been working great.
qr1 = binding.queryAll("select id, external_id__c from contact where external_id__C like '%" + naidno2 + "%'");
I am now trying to do something similar using the REST API and I am getting a 400 error.  If I remove the wild cards then the query runs just fine but in some cases the wild cards are necessary.
 
xhr8.open("GET", "https://na17.salesforce.com/services/data/v34.0/query/?q=select id, name from contact where cheetah_id__c like '%" + ContactCode + "%'");

 
I have 2 triggers which are nearly identical, one sends an email to Leads and the other sends emails to Contacts.  They both work but the HTML Status related list is only populated for the emails sent to Contacts.  When an email is sent to a lead it shows up under activity history but not HTML Status.  It is important to be able to see if/when an email was opened.

I have snippets from both the Lead and Contact triggers so you can see they are nearly identical.  Any thoughts on why HTML Status works for my Contacts but not my Leads?
 
if (combine==true){        
                   	contactlog = mapcontactToUpdate.get(e.id);	
                	mapcontactToUpdate.put(contactlog.id, contactlog);
                    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                    string etidasstring = a.ezwf__Email_Template_ID__c;
                    emailt = e.Lastname; 
                    mail.setSenderDisplayName(UserInfo.getName());
                    mail.setReplyTo(UserInfo.getUserEmail()); 
                    mail.setTargetObjectId(e.id);
                    mail.setTemplateId(etidasstring);
                    mail.setSaveAsActivity(true); 
                	myEmails.add(mail);	
            }
              if (myEmails.size() > 0)
            {
                       Messaging.sendEmail(myEmails);
            }

if (combine==true){        
                   	Leadlog = mapLeadToUpdate.get(e.id);	
                	mapLeadToUpdate.put(Leadlog.id, Leadlog);
                    Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
                    string etidasstring = a.ezwf__Email_Template_ID__c;
                    emailt = e.Lastname; 
                    mail.setSenderDisplayName(UserInfo.getName());
                    mail.setReplyTo(UserInfo.getUserEmail()); 
                    mail.setTargetObjectId(e.id);
                    mail.setTemplateId(etidasstring);
                    mail.setSaveAsActivity(true); 
                	myEmails.add(mail);	
            }
              if (myEmails.size() > 0)
            {
                       Messaging.sendEmail(myEmails);
            }

 
I have a trigger which uses mass email message to send to a list of leads.  It works great when leadids is populated with 5 or 6 IDs but if it is populatd with 7 or more i get the error message stating MASS_MAIL_LIMIT_EXCEEDED, Failed to send email: []

It is my understanding that we can use mass email to send to a list of up to 250 leads/contacts.  Any thoughts on why i am being limited to 6?  Below is a snippet from my code.

Also, when the emails are sent it shows up under Activity History but it does not show up under HTML Email Status so i cannot see if the email was opened by the recipient.
 
if (LeadIds != null && !LeadIds.isEmpty())
            {
                	Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();

                	string etidasstring = a.ezwf__Email_Template_ID__c;
                     
                    mail.setSenderDisplayName(UserInfo.getName());
                    mail.setReplyTo(UserInfo.getUserEmail()); 
                    
                    mail.setTargetObjectIds(LeadIds); 
                    mail.setTemplateId(etidasstring);
                    mail.setSaveAsActivity(true); 
                     
                    Messaging.sendEmail(new Messaging.MassEmailMessage[] {mail});
            }

 
I have a picklist which gives the option to select an object (contact, lead, account, etc).  I have a second and third picklist which allow you to pick a field (depending on the object selected in the previous picklist). 

The object picklist has an action support tag which updates the field picklist when the object picklist is updated, this works great.

 <apex:actionSupport event="onchange" rerender="picklist1" />

What i would like is to have 2 field picklists, both of which are updated depending on the object picklist being changed.  Something like...

 <apex:actionSupport event="onchange" rerender="picklist1; picklist2" />

Any input would be appreciated.  Thank you :)


 
Alright, I have a controller which works without errors but I am attempting to use it as an extension to the custom controller for a VF page.  When I update the VF page to use the standard controller I get the following error.

Visualforce Error
System.NullPointerException: Attempt to de-reference a null object
Class.ezwf.objectController.getObjectFields: line 59, column 1

I have posted the extension and the VF page below.  Any tips would be greaty appreciated.

 
public with sharing class testme {
private final Auto_ab__c ezab;
    public testme(ApexPages.StandardController stdController) {
        this.ezab = (Auto_ab__c)stdController.getRecord();
    }
    
    public Map <String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();

    public String selectedObject {get; set;}
    
    public Auto_ab__c testContact1a;
    
    public String AutoabName {get; set;}
    
    public String TriggerValue {get; set;}
    
    public String abTemplateID {get; set;}
    
    public String selectedField {get; set;}
    
    public String selectedab {get; set;}
    
    public String templatename {get; set;}
    
    public String addobject {get; set;}
    
    public String editid {get; set;}

    public String abid;
    
    
    Public testme()
    {   
        selectedObject = 'account';
    }

    public List<SelectOption> getObjectNames() 
    {
        List<SelectOption> objNames = new List<SelectOption>();
        List<String> entities = new List<String>(schemaMap.keySet());
        entities.sort();
        for(String name : entities)
        {
            objNames.add(new SelectOption(name,name));
        }
        return objNames;
     }
    
    ///////////
    
        
    ///////////

     public List<SelectOption> getObjectFields() 
     {
            Map<String, Schema.SObjectType> schemaMap = Schema.getGlobalDescribe();
            Schema.SObjectType ObjectSchema = schemaMap.get(selectedObject);
            Map<String, Schema.SObjectField> fieldMap = ObjectSchema.getDescribe().fields.getMap();
            List<SelectOption> fieldNames = new List<SelectOption>();
            for (String fieldName: fieldMap.keySet()) 
            {  
                fieldNames.add(new SelectOption(fieldName,fieldName));
              //fieldMap.get(fieldName).getDescribe().getLabel();//It provides to get the object fields label.
            }
            return fieldNames;        
      }
         
    public List<SelectOption> getObjectabs() 
     {
                         List<SelectOption> abNames = new List<SelectOption>();
         for (abTemplate abName: [select id, name from abtemplate]) 
            {  
                abNames.add(new SelectOption(abname.id,abname.name));
              //fieldMap.get(fieldName).getDescribe().getLabel();//It provides to get the object fields label.
            }
            return abNames;
     }
    
    /*
    public string getTemplateName()
    {
        
        
    }
        */

    
    public List<Selectoption> getAllCustomSObjects()
{
    List<Selectoption> sObjectList = new List<Selectoption>();
    for(Schema.SObjectType objTyp : Schema.getGlobalDescribe().Values())
    {
        Schema.DescribeSObjectResult describeSObjectResultObj = objTyp.getDescribe();
        if(describeSObjectResultObj.isCustom())
        {
            String name = objTyp.getDescribe().getName();
            // Exclude all the unwanted Sobjects e.g. History, Share etc..
            if(!name.containsignorecase('history') && !name.containsignorecase('tag')&&
             !name.containsignorecase('share') && !name.containsignorecase('feed'))
            {
                //SobjectList.add(name);
                SobjectList.add(new SelectOption(name,name));
            }
        }
    }
    system.debug('SObjectList****' + SObjectList);
    return SObjectList;
}
public PageReference save() {   
    Contact testContact1a = new Contact(LastName='TestContact',  description = 'TestContact');
    //public String templatename { get {return [SELECT state__c FROM site__c WHERE id = :site LIMIT 1].state__c; } set; }
             string templatename = [select name from abtemplate where id =:Selectedab].name;
             Auto_ab__c newdata = new Auto_ab__c(name=AutoabName, trigger_value_1__c=TriggerValue, Object_1__c=selectedObject,  Trigger_Field_1__c = selectedField, ab_Template_ID__c=Selectedab, ab_Template_name__c=TemplateName );
             insert newdata;
            return Page.Easyab;
    }
    
    public PageReference edit() {   
    Contact testContact1a = new Contact(LastName='TestContact',  description = 'TestContact');
    //public String templatename { get {return [SELECT state__c FROM site__c WHERE id = :site LIMIT 1].state__c; } set; }
             string templatename = [select name from abtemplate where id =:Selectedab].name;
             Auto_ab__c newdata = new Auto_ab__c(id=ApexPages.currentPage().getParameters().get('id'), name=AutoabName, trigger_value_1__c=TriggerValue, Object_1__c=selectedObject,  Trigger_Field_1__c = selectedField, ab_Template_ID__c=Selectedab, ab_Template_name__c=TemplateName );
             update newdata;
            return Page.Easyab;
    }
    
}
 
<apex:page standardcontroller="Auto_ab__c" extensions="objectcontroller">
<apex:form > 
      <apex:pageBlock >
<apex:pageBlockSection columns="2">
    <apex:pageBlockSectionItem >
        <apex:outputlabel value="Name/Description:"/>
                  <apex:inputText value="{!AutoabName}" />
    </apex:pageBlockSectionItem>
                  <apex:pageBlockSectionItem >
                  <apex:outputlabel value="Object Names :"/> 
                      <apex:actionRegion >
                           	<apex:selectList value="{!selectedObject}" size="1">
                            <apex:selectOption itemValue="Contact" itemLabel="Contact"/>
            				<apex:selectOption itemValue="Lead" itemLabel="Lead*" />
                            <apex:actionSupport event="onchange" rerender="myFields"/>
                            </apex:selectList>
                     </apex:actionRegion>                         
              </apex:pageBlockSectionItem>
          </apex:pageBlockSection>

<apex:pageBlockSection columns="2">

    

              <apex:pageBlockSectionItem >
                      <apex:outputlabel value="Field Names :"/>   
                      <apex:outputPanel id="myFields">   
                        <apex:actionRegion >  
                           <apex:selectList value="{!selectedField}" size="1">
                                <apex:selectOptions value="{!ObjectFields}"/>
                            </apex:selectList>
                        </apex:actionRegion>      
                     </apex:outputPanel>
              </apex:pageBlockSectionItem>
              
            <apex:pageBlockSectionItem >
                <apex:outputlabel value="Trigger Value:"/>
                          <apex:inputText value="{!TriggerValue}" />
            </apex:pageBlockSectionItem>
              
          </apex:pageBlockSection>
          
<apex:pageBlockSection columns="2">

    

              <apex:pageBlockSectionItem >
                      <apex:outputlabel value="ab Names :"/>   
                      <apex:outputPanel id="myabs">   
                        <apex:actionRegion >  
                           <apex:selectList value="{!selectedab}" size="1">
                                <apex:selectOptions value="{!objectabs}"/>
                            </apex:selectList>
                        </apex:actionRegion>      
                     </apex:outputPanel>
              </apex:pageBlockSectionItem>

              
          </apex:pageBlockSection>
          
                    <apex:pageBlockButtons >
        <apex:commandButton action="{!save}" value="Save"/>
        <apex:commandButton action="{!edit}" value="Edit"/>
      </apex:pageBlockButtons>
      </apex:pageBlock>

  </apex:form>
</apex:page>

 
I have a C# program what was working great until i modified this query.  The query currently reads...

qr1 = binding.queryAll("select id, external_id__c from contact where external_id__C in '" + naidno2 + "'");

This line of code produces this error message... "Binding variable only allowed in Apex code"

naidno2 is a string which contains unique IDs separated by commas, i.e. "A4568,R4568,D6548,A4568"
 
I have this trigger with the following test and i am only getting 31% coverage.  The concept of test still has me confused, any help would be greatly appreciated.
trigger AcceptanceSigned on Task (after insert, after update) {
    Set<Id> LogIds = new Set<Id>();
    Map<Id,Account> mapacctLogWithId = new Map<Id,Account>();
    Map<Id,Account> mapAccLogToUpdate = new Map<Id,Account>();
    
    for(Task t: trigger.new){
        if(t.WhatId != null && string.valueof(t.WhatId).startsWith('a01')){
            LogIds.add(t.WhatId);
        }
    }
    for(Account a:[SELECT Description, easy_workflow__c FROM Account WHERE ID IN:LogIds]){
        mapacctLogWithId.put(a.Id,a);
    }
    
    for(Task t: trigger.new){
        if(t.WhatId != null && string.valueof(t.WhatId).startsWith('a01') && t.Status == 'Completed' && mapacctLogWithId != null && mapacctLogWithId.get(t.WhatId) != null){
            Account accLog = new Account();
            if(mapAccLogToUpdate != null && mapAccLogToUpdate.get(t.WhatId) != null){
                accLog = mapAccLogToUpdate.get(t.WhatId);
            }
            else if(mapAccLogToUpdate != null && mapAccLogToUpdate.get(t.WhatId) == null){
                accLog = mapacctLogWithId.get(t.WhatId);
            }
            accLog.easy_workflow__c = accLog.easy_workflow__c + ';'+ t.subject;
            //accLog.easy_workflow__c = accLog.easy_workflow__c.replace(t.subject,'');
            if(t.Subject == 'Sign Acceptance Form'){
                accLog.Description = 'Acceptance Form Signed';    
            }
            mapAccLogToUpdate.put(accLog.Id,accLog);
        }
        
                if(t.WhatId != null && string.valueof(t.WhatId).startsWith('a01') && t.Status == 'Open' && mapacctLogWithId != null && mapacctLogWithId.get(t.WhatId) != null){
            Account accLog = new Account();
            if(mapAccLogToUpdate != null && mapAccLogToUpdate.get(t.WhatId) != null){
                accLog = mapAccLogToUpdate.get(t.WhatId);
            }
            else if(mapAccLogToUpdate != null && mapAccLogToUpdate.get(t.WhatId) == null){
                accLog = mapacctLogWithId.get(t.WhatId);
            }
            //accLog.easy_workflow__c = accLog.easy_workflow__c + ';'+ t.subject
                    if(accLog.easy_workflow__c != null && accLog.easy_workflow__c !=''){
            accLog.easy_workflow__c = accLog.easy_workflow__c.replace(t.subject,'');
                    }
            if(t.Subject == 'Sign Acceptance Form'){
                accLog.Description = 'Acceptance Form Signed';    
            }
            mapAccLogToUpdate.put(accLog.Id,accLog);
        }
    
    if(mapAccLogToUpdate != null && mapAccLogToUpdate.values() != null &&mapAccLogToUpdate.values().size() > 0){
        update mapAccLogToUpdate.values();
    }
    } }
@isTest(SeeAllData = true)
public class AcceptanceSignedTest {
         public static testMethod void testAcceptanceSigned(){
             test.startTest();
             Account testLog = new Account(name='Test', description = 'Test');
             insert testLog;
             
             Task testTask = new Task(Subject = 'Sign Acceptance Form', whatId = testLog.ID, Status = 'Completed');
             insert testTask;
             
             Account testLog2 = new Account(name='Test2', description = 'Test2');
             insert testLog2;
             
             Task testTask2 = new Task(Subject = 'Test', whatId = testLog2.ID, Status = 'Completed');
             insert testTask2;
             
             Account testLoga = new Account(name='Test', description = 'Test');
             insert testLoga;
             
             Task testTaska = new Task(Subject = 'Sign Acceptance Form', whatId = testLog.ID, Status = 'Open');
             insert testTaska;
             
             Account testLog2a = new Account(name='Test2', description = 'Test2');
             insert testLog2a;
             
             Task testTask2a = new Task(Subject = 'Test', whatId = testLog2.ID, Status = 'Open');
             insert testTask2a;
             test.stopTest();
        }
}


 
I have the trigger & test below which is giving me 38% coverage.  I am very new to APEX and the testing still has me confused.  Any help on creating a test class for this trigger would be greatly appreciated.
 
trigger AcceptanceSigned on Task (after insert, after update) {
    Set<Id> LogIds = new Set<Id>();
for(Task t: [SELECT Subject,WhatId, Status FROM TASK WHERE ID IN:trigger.new]){
String wId = t.WhatId;
if(wId!=null && wId.startsWith('a01') && !LogIds.contains(t.WhatId) && t.Status == 'Completed' && t.Subject == 'Sign Acceptance Form'){
LogIds.add(t.WhatId);
    for(Account_Log__c a:[SELECT Stage__c, status_list__c FROM Account_Log__c WHERE ID IN:LogIds]){
                 a.Stage__c = 'Acceptance Form Signed';
        update a; 
}
}  
    if(wId!=null && wId.startsWith('a01') && !LogIds.contains(t.WhatId) && t.Status == 'Completed'){
LogIds.add(t.WhatId);
    for(Account_Log__c a:[SELECT Stage__c, Status_List__c FROM Account_Log__c WHERE ID IN:LogIds]){
        		 a.Status_List__c = a.Status_List__c + ';'+ t.subject;
        update a; 
}
}  
}  
}
 
@isTest
public class AcceptanceSignedTest {
         private static testMethod void testAcceptanceSigned(){
             test.startTest(); 
             Account_Log__c testLog = new Account_Log__c(Grantor_and_or_Family_Trustee_etc_1__c='Test');
             testLog.Grantor_and_or_Family_Trustee_etc_2__c = 'Test';
             insert(testLog);
             LIST<Account_Log__c> a = [SELECT ID, Grantor_and_or_Family_Trustee_etc_1__c FROM Account_Log__c WHERE Grantor_and_or_Family_Trustee_etc_1__c = 'Test'];
             Task testTask = new Task(Subject = 'Test', whatId = a[0].ID); 
             insert(testTask); 
             Account_Log__c updatedLog = [SELECT Grantor_and_or_Family_Trustee_etc_1__c FROM Account_Log__c WHERE Grantor_and_or_Family_Trustee_etc_1__c = 'Test'];
             system.AssertEquals('Test',updatedLog.Grantor_and_or_Family_Trustee_etc_1__c);
             test.stopTest(); 
        }
}

 
I have written some code which adds records to an object.  In case case i am trying to add a record to a custom object.  When running this code i get an error message stating that the sObject type 'Trust_Contact__C' is not supported.  As a test a created a new custom object 'Test_Object__C" and ran the same exact code but changed the type to 'Test_Object__C' and i commented out the a few of the fields (second code sample).  What really confuses me is that it worked with the Test Object and not with the Trust Contact object.  I also inserted screenshots from each object in Salesforce.  Any ideas?
 
cmd.CommandText = "SELECT  top(10)   dbo.keat_crossreference.* FROM  dbo.keat_crossreference";
                cmd.CommandType = CommandType.Text;
                cmd.Connection = sqlConnection1;

                sqlConnection1.Open();

                reader = cmd.ExecuteReader();
                var nexty = reader;
                // Data is accessible through the DataReader object here.
                int ir = 0;
                sObject[] cons = new sObject[1];
                apex.sObject contact;
                var pretrust ="pre";
                var buildid = "";
                var pair = "";
                var crdesc = "";
                var acctno = "";
                var naidno = "";
                while (reader.Read())
                {
                    if (reader.GetValue(reader.GetOrdinal("account_no")).ToString()==pretrust)
                    {
                         
                         buildid = buildid +','+ reader.GetValue(reader.GetOrdinal("buildid")).ToString();
                         pair = pair + ',' + reader.GetValue(reader.GetOrdinal("pair")).ToString();
                         crdesc = crdesc + ',' + reader.GetValue(reader.GetOrdinal("cross_ref_type_cd_dsc")).ToString();
                         acctno = acctno + ',' + reader.GetValue(reader.GetOrdinal("account_no")).ToString();
                         naidno = naidno + ',' + reader.GetValue(reader.GetOrdinal("name_addr_id")).ToString();
                         pretrust = reader.GetValue(reader.GetOrdinal("account_no")).ToString();
                        ir++;
                    }
                    else
                    {
                    ir++;
                    pretrust = reader.GetValue(reader.GetOrdinal("account_no")).ToString();
                    //Verify that we are already authenticated, if not
                    //call the login function to do so
                    if (!loggedIn)
                    {
                        if (!login())
                            return;
                    }

                    try
                    {

                        for (int j = 0; j < cons.Length; j++)
                        {
                            contact = new apex.sObject();
                            int index = 0;
                            System.Xml.XmlElement[] cont = new System.Xml.XmlElement[17];
                            if (accounts != null)
                            {
                                cont = new System.Xml.XmlElement[cont.Length + 1];
                                cont[index++] = GetNewXmlElement("AccountId", accounts[0]);
                            }

                            cont[index++] = GetNewXmlElement("contact__C", naidno);
                            cont[index++] = GetNewXmlElement("Relationship_Type__c", crdesc);
                            //cont[index++] = GetNewXmlElement("Role__c", addy1);
                            cont[index++] = GetNewXmlElement("Trust__c", acctno);
                            contact.Any = cont;
                            contact.type = "Trust_Contact__C";
                            cons[j] = contact;
                        }
                        SaveResult[] sr = binding.create(cons);

//cont[index++] = GetNewXmlElement("contact__C", naidno);
                            //cont[index++] = GetNewXmlElement("Relationship_Type__c", crdesc);
                            //cont[index++] = GetNewXmlElement("Role__c", addy1);
                            cont[index++] = GetNewXmlElement("name", acctno);
                            contact.Any = cont;
                            contact.type = "Test_Object__c";
                            cons[j] = contact;

Test ObjectTrust Contact

It would appear if a customer is using Communities or force.com sites there is no way to build scalable custom object URL buttons that work everywhere.

 

Let's say on the Account object you have a custom URL button that opens a Visualforce page with the following text:

 

/apex/findNearby?id={!Account.Id}

In this example we can't make the Content Source of the button Visualforce as this findNearby.page does not use a standard controller or extension.

 

For a normal user inside salesforce.com this works fine but let's say an org has a Community named 'customers'. This is were things start to break. That link should then redirect to:

 

/customers/apex/findNearby?id={!Account.Id}

 

So you might be thinking, no problem, just use the $Site global variable and do the following in the URL button:

 

{!URLFOR($Site.Prefix+'/apex/findNearby?id='+Account.Id)}.

This would normally work but here is the final caveat...this is part of a managed packaged that needs to support Group and Professional editions and in these editions the $Site var does not exists.

 

Unless I am missing something this seems to be a gap in functionality for creating URL button links with Communities.

 

Is there anyway, within a button to detect the correct url or salesforce version and build the appropriate URL?

 

Thanks,

Jason

  • October 30, 2013
  • Like
  • 0