• Thomasm
  • NEWBIE
  • 65 Points
  • Member since 2012


  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 38
    Questions
  • 37
    Replies
I created a visualforce related list on the account to make it easier to find records but need to add a new button to the list.  I need the button to open a new tab and create a record for that related list.  I am not sure where to go but here is what i have

VF Page
<apex:page standardcontroller="Account" extensions="AccountRelatedPages">
<style> .fewerMore { Display: none;} </style>
 <apex:form >
<apex:pageblock id="Safety_Forms" title="Safety Forms">
<apex:commandButton value="New" />
<apex:pageblocktable value="{!AF}" var="a" rendered="{!not(isNull(emp))}">
<apex:column >
<apex:outputlink target="_Blank" value="/{!a.id}">{!a.name}</apex:outputlink>
/apex:column> </apex:pageBlocktable>
</apex:pageblock>
</apex:form>
</apex:page>

Class
public class AccountRelatedPages {

Private list<account_form__C>Af;

Private Account Act;
    Public AccountRelatedPages(ApexPages.StandardController Controller){this.Act=(account)controller.getRecord();} 
 public list<account_form__C>getAF()
 {
 AF=[Select id, Name from account_form__C WHERE account__C=:act.id and RecordTypeId in (SELECT Id FROM RecordType WHERE Name = 'Incident Investigation')];
 return af;
 }

}
I am having issues with a public site not showing fields.  When i hit preview on the visualforce page everything shows up but when i go to the URL i only see the title.  I have checked the guest profile and all the fields have been granted access.  Any ideas
I am working if a trigger to convert multiple leads at once and need help with the test class

the trigger is:

trigger AutoConvert on Lead (after update) {
    list<Lead> LeadsToConvert = new list<Lead>();
    for(Lead myLead: Trigger.new){
        if(!myLead.isConverted)
            LeadsToConvert.add(myLead);
    }
 
    list<Database.LeadConvert> leadConverts = new list<Database.LeadConvert>();
    for(Lead myLead : LeadsToConvert){
        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(myLead.Id);
        lc.convertedStatus = 'Qualified';

        //Database.ConvertLead(lc,true);
        lc.setDoNotCreateOpportunity(true);
        leadConverts.add(lc);
  }
    if(!leadConverts.isEmpty()){
        for(Integer i = 0; i <= leadConverts.size()/100 ; i++){
            list<Database.LeadConvert> tempList = new list<Database.LeadConvert>();
            Integer startIndex = i*100;
            Integer endIndex = ((startIndex+100) < leadConverts.size()) ? startIndex+100: leadConverts.size();
            for(Integer j=startIndex;j<endIndex;j++){
                tempList.add(leadConverts[j]);
            }
            Database.LeadConvertResult[] lcrList = Database.convertLead(tempList, false);
            for(Database.LeadConvertResult lcr : lcrList)
                System.assert(lcr.isSuccess());
        }
    }

}

and the test class is 

@isTest
Private class UnitTest_AutoConvert {

Static TestMethod void AutoConvert(){

    test.StartTest();

   // Create the Lead object
   Lead testLead = new Lead(
  id='00Qa0000012cJlM',
   FirstName='Demo 100800',
   LastName = 'Demo 100800 UnitTest',
   Status='Qualified',
   company='Lacosta',
   street='1211 E I-40 Service Rd',
   city=' Oklahoma City',
   state='OK'
  // zippostal_code= '73149'
   
   //Ready_to_Convert__c = true
   );

   update testLead;
   System.debug('Created and inserted lead');

   Database.LeadConvert lc = new database.LeadConvert();
   lc.setLeadId(testLead.Id);

   LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
   lc.setConvertedStatus(convertStatus.MasterLabel);
   Database.LeadConvertResult lcrList = Database.convertLead(lc);

   // Make sure conversion was successful
   System.assert(lcrList.isSuccess());

   test.stopTest();
   }
   }

i am currently getting the following error
System.DmlException: ConvertLead failed. First exception on row 0; first error: CANNOT_UPDATE_CONVERTED_LEAD, cannot reference converted lead: []
Stack Trace Class.UnitTest_AutoConvert.AutoConvert: line 31, column 1
 
I am looking for some help with a simple if statement and the code coverage

here is the trigger

trigger Case4fromRD on RD_Site_Report__c (after insert, after update) {
List<Service_Call_Log__C>SCL=New list<Service_Call_Log__C>();
    For(RD_Site_Report__C b:trigger.new)
    {
        IF (b.case_topic__C !=null){
           SCL.add(new Service_Call_Log__C(Subject__C='A Case has been created from an RD Site Report',job__C=b.Job__C, description__C=b.case_Topic__C, Web_email__C=b.contact_email__C));
            insert SCL; 
        }
       
    
    }
}

and here is the test class

@isTest
public class Rd_Site_Report_SCL1{

static testMethod void CasefromRD(){

RD_Site_Report__c sRDSR = new RD_Site_Report__c();

sRDSR.Reason__C='Customer Complaint';
sRDSR.Case_Topic__c ='Test';
sRDSR.Job__C='a013000000UHggN';
sRDSR.case_topic__C='Test';
sRDSR.Contact_Email__C='tmonson@cms4.com';

Test.StartTest();

insert sRDSR;

test.stopTest();

}
}
I currently have a visualforce page with a button to create a new record.  The button works fine but when i click on the button in salesforce1 it goes out of the app and tries to open in the browser.  How can i get the link to open in salesforce1

here is the code that i have 

 <apex:pageblockSectionItem datastyle="Width:10%" labelStyle="Width:23%">
      <apex:commandButton value="Transfer Request" action="{!URLFOR('/a10/e?RecordType=012a0000001NWwn&ent=01Ia0000002Kw9e')}" style="height:35px;width:500px; background:Lightblue; font-size:16pt;"/>
  </apex:pageblockSectionItem>
I have a visualforce page that used a custom controller to pull a list from an object and offers inline editing.  I was trying to do a quicksave button like with standard controller but i am unable to.  How can add a quicksave to a custom controller

<apex:page controller="Scllist1">
<apex:form >
 <apex:pageblock title="Open Service Call Logs">
 <apex:pageblocksection >
 <apex:pageblockTable value="{!acts}" var="s">
 <apex:column value="{!s.name}"/>
 <apex:column headerValue="Status">
 <apex:inputfield value="{!s.Status__c}"/>
 </apex:column>
 </apex:pageblockTable>
 </apex:pageblocksection>
 </apex:pageblock> 
 </apex:form>
</apex:page>

here is the controller

public class Scllist1 {
    List<Service_call_log__C> acts =[Select Name, subject__c, status__C From Service_call_log__c where status__C<>'Closed'];
    
    public List<Service_Call_log__C> getacts() 
    {
    return acts;
     }
}
I currently have a visualforce page that is used to display the Job information (same as an account).  I am using tabs to break up the data and an extension to help me sort the data.  Currenlty i have 3 tabs one detail tab and the other 2 are set to show the exact same thing.  the problem i am having is only one tab pulls the data and the other says it keeps trying to load.  

Here is the page

<apex:page standardController="Jobs__c" extensions="sclSort4" >
<apex:pageMessages id="msgs"/>
    <apex:tabPanel switchType="client" selectedTab="Detailed View" id="theTabPanel">
        <apex:tab label="Detailed View" name="Detailed View">
        <apex:form >
            <apex:detail title="false" relatedList="false"/>
        </apex:form>
        </apex:tab>       
        
        <apex:tab label="Open Pages" name="Open Service Call Logs2">
        <apex:form >
         <apex:actionFunction name="loadPgsJS" action="{!loadpgs}" rerender="pgsPanel, pgsJS, msgs"/>
        <apex:pageBlock >
        <apex:outputPanel id="pgsPanel">
      <apex:outputPanel rendered="{!pgsNeeded}">    
      
          <div id="spinner">
            <p align="center" style='{font-family:"Arial", Helvetica, sans-serif; font-size:20px;}'><apex:image value="/img/loading.gif"/></p>
          </div>       
      </apex:outputPanel>
      <apex:outputPanel rendered="{!NOT(pgsNeeded)}">
        <apex:pageBlockSection title="Open Service Call Logs" columns="1">        
          <apex:pageBlockTable value="{!pgs}" var="pg" rendered="{!pgsFound}">
            <apex:column headerValue="{!$ObjectType.Opportunity.fields.Name.label}">
              <apex:outputLink value="/{!pg.id}">{!pg.Name}</apex:outputLink>
            </apex:column>
    
          </apex:pageBlockTable>
          <apex:outputText value="No opportunities found" rendered="{!NOT(pgsFound)}"/>
        </apex:pageBlockSection>
      </apex:outputPanel>
    </apex:outputPanel>
        </apex:pageBlock>          
        
        <apex:outputPanel id="pgsJS">
    <apex:outputPanel rendered="{!pgsNeeded}">
   <script>
     loadPgsJS();
   </script>
   </apex:outputPanel>
 </apex:outputPanel>      
   </apex:form>        
         </apex:tab>         
        <apex:tab label="Open Pages" name="Open Service Call Logs23">
        <apex:form >
         <apex:actionFunction name="loadPgsJS" action="{!loadpgs}" rerender="pgsPanel, pgsJS, msgs"/>
       <apex:pageBlock >
        <apex:outputPanel id="pgsPanel">
      <apex:outputPanel rendered="{!pgsNeeded}">     
          <div id="spinner">
            <p align="center" style='{font-family:"Arial", Helvetica, sans-serif; font-size:20px;}'><apex:image value="/img/loading.gif"/></p>
          </div>       
      </apex:outputPanel>
      <apex:outputPanel rendered="{!NOT(pgsNeeded)}">
        <apex:pageBlockSection title="Open Service Call Logs" columns="1">
        <apex:pageBlockTable value="{!pgs}" var="pg" rendered="{!pgsFound}">
            <apex:column headerValue="{!$ObjectType.Opportunity.fields.Name.label}">
              <apex:outputLink value="/{!pg.id}">{!pg.Name}</apex:outputLink>
            </apex:column>          
         </apex:pageBlockTable>
          <apex:outputText value="No opportunities found" rendered="{!NOT(pgsFound)}"/>
        </apex:pageBlockSection>
      </apex:outputPanel>
    </apex:outputPanel>
        </apex:pageBlock>
        <apex:outputPanel id="pgsJS">
    <apex:outputPanel rendered="{!pgsNeeded}">
   <script>
     loadPgsJS();
   </script>
   </apex:outputPanel>
 </apex:outputPanel>
   </apex:form>
         </apex:tab>
    </apex:tabPanel>
</apex:page>



and here is the extension

public with sharing class sclSort4 {
    private ApexPages.StandardController stdCtrl;
        
    public List<service_Call_log__C> pgs {get; set;}
    
    public Boolean pgsNeeded {get; set;}
    
    public Boolean pgsFound {get; set;}
    
   
    public sclSort4(ApexPages.StandardController std)
    {
        stdCtrl=std;
        pgsNeeded=true;
        pgsFound=false;
    }
    
 
    public PageReference loadpgs()
    {
        pgs=[select id, Name from service_call_log__C where Job__C=:stdCtrl.getId() ];
        pgsNeeded=false;
        pgsFound=(pgs.size()>0);
        
        return null;
    }
}
I currently have a page with a command button that creates a new record.  I would like to predefine the recordtype to the user goes directly to the page 

Here is what i currently have

<apex:commandButton value="Salary Time Off Request" action="{!URLFOR($Action.Forms__c.New)}"/>
I have a custom object that is very similar to the account object.  I have mulitple related objects on this object and i am starting to create a visualforce page to display this information on different tabs.  On the second tab i want to display the related service_call_log__C but i want to filter the information to only show one with the status that equals open.   I am not sure if this is the best way but i was trying to use the enhance list but it never load any data, just keeps saying loading.  I am looking for some help to determine is this the best way.  If not can you direct me to a better solution and if so why does it never load

here is what i have so far

<apex:page standardController="Jobs__c" >
    <apex:tabPanel switchType="Client">
        
<apex:tab Label="Detailed View">
    <APEX:detail relatedList="False" />         
</apex:tab>
           

 
            <apex:tab label="Open Service Call Logs" name="Open Service Call Logs">
                
     
      <apex:enhancedList type="Service_Call_Log__c" height="730" rowsPerPage="25" customizable="false" listid="00B1300000A4hwB" />
    </apex:tab> 
        

        
</apex:tabPanel>

</apex:page>
  • September 30, 2015
  • Like
  • 0
I am using the select list to use different views.  It is supposed to refresh when i change the view but currently nothing happends

here is what i have so far

<apex:page standardController="Jobs__c" recordSetVar="jbs" sidebar="false">

    <apex:form >
     <apex:pageBlock title="Current Jobs">
             <apex:SelectList value="{!filterID}" size="1">
            
            <apex:actionSupport event="onchange" reRender="List"/>
            <apex:selectOptions value="{!listviewoptions}"/>
        </apex:SelectList>

<apex:pageBlockSection >
         <apex:pageBlockTable Value="{!jbs}" var="a" id="List">
             
             <apex:column >
        <apex:outputlink value="/{!a.id}">{!a.name} </apex:outputlink>
            </apex:column>

             
             <apex:column headerValue="Active" >
                 <apex:inputField value="{!a.Active__c}"/>
             </apex:column>
             <apex:Column value="{!a.Job_Number__c}"/>
     </apex:pageBlockTable>
     </apex:pageBlockSection>
    </apex:pageBlock>
    </apex:form>
    
   
</apex:page>
  • September 29, 2015
  • Like
  • 0
I am looking to create a visualforce page that will show all the record of a custom object and when you click on the name for the record to ope up.  So far i everything is displaying correctly but when i click on the record name nothing happens. 

Here is my code

<apex:page standardController="Jobs__c" recordSetVar="jbs" sidebar="false">
<apex:panelGrid columns="1">
    <apex:form >
     <apex:pageBlock title="Current Accounts">

         <apex:pageBlockTable Value="{!jbs}" var="a">
             <apex:column >
                 <apex:commandLink value="{!a.name}" reRender="Out">
                 <apex:param name="ID" value="{!a.ID}"/>
                 </apex:commandLink>
             </apex:column>
             <apex:column value="{!a.name}"/>
             <apex:column headerValue="Active" >
                 <apex:inputField value="{!a.Active__c}"/>
             </apex:column>
             <apex:Column value="{!a.Job_Number__c}"/>
     </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:form>
    <apex:outputPanel id="out">
    <apex:Detail subject="{!$CurrentPage.parameters.id}" relatedlist="false"/>
    </apex:outputPanel>
    </apex:panelGrid>
</apex:page>
  • September 28, 2015
  • Like
  • 0
I am looking for some help on a trigger to update a field.  I have 3 custom objects (job, Employee, and Employee form). the job is the master to the employee and the employee is the master to the employee form.  I have a number field called hats on the job object and when an employee form is created i want to use the quantity field to update the hat field.

So far i have the following but i am getting the error "Initial term of field of expression must be a concrete object".


trigger updateHats on Employee_Forms__c (before insert) {
   set<id> jobids=new set<id>();  
   map<id,jobs__c> jobsmap=new map<id,jobs__c>([select id, hats__C from jobs__c where id=:jobids]);
   //List<Jobs__C>Jobs=new list<jobs__c>();
    For(employee_forms__C b:Trigger.new)
        if(b.Uniform_Type__C=='Hat')
    {
        jobsmap.hats__C= jobsmap.hats__C - b.Quantity__C;
    }
        }


 
 
 
 
 
on the employee object I have

label: Job      API Name: Job__C  Data Type: Master-Detail(Job)

and the employee_Forms__C i have

Label: Employee    API Name:  Employee__C  Data Type:  Master-Detail(Employee)


I think its because the job and the employee form object are not directly related but i am not sure and if i was sure i am not sure how to go about fixing it.  

Any help i would appreciate 
 
I am looking for some help on a trigger to update a field.  I have 3 custom objects (job, Employee, and Employee form). the job is the master to the employee and the employee is the master to the employee form.  I have a number field called hats on the job object and when a employee form is created i want to use the quantity field to update the hat field.

So far i have the following but i am getting the error "Initial term of field of expression must be a concrete object".


trigger updateHats on Employee_Forms__c (before insert) {
   set<id> jobids=new set<id>();  
   map<id,jobs__c> jobsmap=new map<id,jobs__c>([select id, hats__C from jobs__c where id=:jobids]);
   //List<Jobs__C>Jobs=new list<jobs__c>();
    For(employee_forms__C b:Trigger.new)
        if(b.Uniform_Type__C=='Hat')
    {
        jobsmap.hats__C= jobsmap.hats__C - b.Quantity__C;
    }
        }


I think its because the job and the employee form object are not directly related but i am not sure and if i was sure i am not sure how to go about fixing it.  

Any help i would appreciate 
I have a customer field called Subject that i would like to have the informtion change from  TT-ABS EE38877 Jessica Martin is Absent. 0 Present. JB1356 Evonik Labs PO146 T&m

to only show the name Jessica Martin

the name changes but the format is always the same.  Any idea's where to begin

I have a page the pulls in to static resouces one is an html head and the other is a pdf.  Both are showing up but there is a huge gap inbetween them.

Please look at what i have and make a suggestions

 

<apex:page sidebar="false" showheader="false">
<apex:form >

<apex:iframe src="{!URLFOR($Resource.KCLoudonMenu)}"/>
<br/>
<apex:iframe src="{!URLFOR($Resource.mypdfpage)}"/>
 
  </apex:form>
</apex:page>

I am trying to get my class to pass but i keep getting an error when i run it.  there error is
System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Invalid to address : null: []

 here is the test class

@isTest
public Class TestEamilAttchment{
   Static testMethod Void TestinBoundEmail()
       {
   //create a new email and envelope ojbect
   messaging.InboundEmail email = new Messaging.InboundEmail();
   Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
   
   //setup the data for the email
   email.subject='Create Service Call Log';
   env.fromAddress='Tmonson@cms4.com';
   email.plainTextBody='Email body\n2332345354454\nTitle';
   email.FromName ='Thomas Monson';
   
        Service_Call_Log__C sService_Call_Log = new Service_Call_Log__C();   
   sService_call_log.Contact__C='00330000012mk3O';
 
   
   //add an Binary attachment
   
   Messaging.InboundEmail.BinaryAttachment attachment = new Messaging.InboundEmail.BinaryAttachment();
   attachment.body = blob.valueOf('My attachmeent text');
   attachment.fileName = 'textfileone.txt';
   attachment.mimeTypeSubType='Text/Plain';
   email.binaryAttachments=new Messaging.inboundEmail.BinaryAttachment[]{attachment};

   
   
   //add an Text attachmet
   
   Messaging.InboundEmail.TextAttachment attachmenttext = new Messaging.InboundEmail.TextAttachment();
   attachmenttext.body = 'my attachment text';
   attachmenttext.fileName = 'textfiletwo3.txt';
   attachmenttext.mimeTypeSubType='texttwo/plain';
   email.textAttachments = new Messaging.inboundEmail.TextAttachment[]{attachmenttext};  
      //call the email serivce class and text it with the data in the textMethod
   
  EmailToServiceCallLog testInbound= new EmailToServiceCallLog ();
    testInbound.handleInboundEmail(email,env);          
      }
      }

i am trying to use a visualforce page to display the contents of a document, but when the page loads i get the following error

common.apex.runtime.impl.ExecutionException: BLOB is not a valid UTF-8 string

<apex:page renderAs="pdf" controller="basicWeightPDF" contentType="HTML" >
<html>
<body>
{!dipslaytable}
</body>
</html>
</apex:page>

public class basicWeightPDF{
public string dipslaytable{get;set;}
public basicWeightpdf()
{
document d=[Select id, body from document where id='015190000000W33'];
Blob bodyOfAttachment = EncodingUtil.base64Decode('JVBERi0xLjIgCiXi4');
string strOrgId=UserInfo.getOrganizationID();
dipslaytable=d.body.tostring();
}
}

i am trying to get a custom object and its related items to show in a table in a visualforce page.  Currently i have the first object showing up but i am not sure how to pull in the related list

 

here is the controller

global with sharing class poistionController {
private Map<string,set<String>> employeeMap=new Map<string,set<String>>();

     public Employees__c pos{get;set;}

     public poistionController() {
        list<Training__C>trainList=[Select name from Training__C where employee__C=:employees__C.Name__c];
         pos = [select ID, Name, Active__C from Employees__c where Active__C= true];

      }

}

 

and here is the page

<apex:page controller="poistionController" showHeader="false">
<apex:relatedList list="Training__C"/>
  
      <apex:pageblock title="test">
      </apex:pageblock>
     
      <apex:dataTable value="{!pos}" var="Employee">
     
     
         <apex:column value="{!pos.name}">
         </apex:column>
        
         <apex:column value="{!pos.id}">
         </apex:column>
         </apex:dataTable>
 

 


</apex:page>

I have a trigger to send an email based off a custom object.   The trigger works and the email sends but in Gmail the images from the template do not show and in outlook nothing shows.  I have used this template in workflow rules and it works fine but will not work correctly in from my frigger.  Here is my code

trigger EmailNotify on Service_Call_Log__c (after insert) {
    for(service_call_log__C b: trigger.new){                          
              
                  EmailTemplate template = [SELECT Id, Subject, HtmlValue, Body FROM EmailTemplate WHERE Name = 'Case Created Service Call Log'];           
            
               String subject = template.Subject;
subject = subject.replace('{!Case.Account}', 'Your Case has been created');

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String htmlBody = template.HtmlValue;
htmlBody = htmlBody.replace('{!Service_Call_Log__c.Subject__c}', b.subject__C);
htmlBody = htmlBody.replace('{!Service_Call_Log__c.Description__c}', b.Description__c);
mail.setSubject(subject);
mail.setHtmlBody(htmlBody);
mail.setToAddresses(new String[] {b.web_email__C});             
               mail.setSenderDisplayName('SFDC Developer');
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
                      
    }
}
I have a trigger that is sent everytime a custom object record is created usind email services.   It works like an auto response so the person does not have to be a contact.  It currently works and brings in the merge field from the template but the graphics are not there and nothing show in outlook.

here is my code
trigger EmailNotify on Service_Call_Log__c (after insert) {
    for(service_call_log__C b: trigger.new){                           
               
                  EmailTemplate template = [SELECT Id, Subject, HtmlValue, Body FROM EmailTemplate WHERE Name = 'Case Created Service Call Log'];
//Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
  //           mail.setTemplateId(template.id);
               
               
               String subject = template.Subject;
subject = subject.replace('{!Case.Account}', 'Your Case has been created');


String htmlBody = template.HtmlValue;
htmlBody = htmlBody.replace('{!Service_Call_Log__c.Subject__c}', b.subject__C);
htmlBody = htmlBody.replace('{!Service_Call_Log__c.Description__c}', b.Description__c);

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setSubject(subject);
mail.setHtmlBody(htmlBody);
 mail.setToAddresses(new String[] {b.web_email__C});
               
               mail.setSenderDisplayName('SFDC Developer');
                Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
                       
    }
} 

I am only able to get 26% code coverage but not sure why 
@isTest
public Class TestEamilAttchment{
   Static testMethod Void TestinBoundEmail()
       {
   //create a new email and envelope ojbect
   messaging.InboundEmail email = new Messaging.InboundEmail();
   Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
  
   //setup the data for the email
   email.subject='Create Service Call Log';
   env.fromAddress='Tmonson@cms4.com' (mailto:env.fromAddress='Tmonson@cms4.com');
   email.plainTextBody='Email body\n2332345354454\nTitle';
   email.FromName ='Thomas Monson';
  
        Service_Call_Log__C sService_Call_Log = new Service_Call_Log__C();  
   sService_call_log.Contact__C='00330000012mk3O';
 
  
   //add an Binary attachment
  
   Messaging.InboundEmail.BinaryAttachment attachment = new Messaging.InboundEmail.BinaryAttachment();
   attachment.body = blob.valueOf('My attachmeent text');
   attachment.fileName = 'textfileone.txt';
   attachment.mimeTypeSubType='Text/Plain';
   email.binaryAttachments=new Messaging.inboundEmail.BinaryAttachment[]{attachment};

  
  
   //add an Text attachmet
  
   Messaging.InboundEmail.TextAttachment attachmenttext = new Messaging.InboundEmail.TextAttachment();
   attachmenttext.body = 'my attachment text';
   attachmenttext.fileName = 'textfiletwo3.txt';
   attachmenttext.mimeTypeSubType='texttwo/plain';
   email.textAttachments = new Messaging.inboundEmail.TextAttachment[]{attachmenttext};
  
   //call the email serivce class and text it with the data in the textMethod
  
  EmailToServiceCallLog testInbound= new EmailToServiceCallLog ();
   testInbound.handleInboundEmail(email,env);
  
  
   }
  
   }


global class EmailToServiceCallLog implements Messaging.InboundEmailHandler {
 
        global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
            Messaging.InboundEnvelope envelope) {
            
            Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
           
     
           
            Service_Call_Log__C sService_Call_Log = new Service_Call_Log__C();  
            try   
            {
            Contact vCon=[SELECT ID, Name, Phone, Email FROM Contact WHERE email = :email.fromAddress LIMIT 1];
           
            sService_Call_Log.Contact__C= vCon.id;
            sService_Call_Log.Contact_Phone_Number__C=vCon.Phone;
            sService_Call_Log.Job__C = 'a013000000UHggN';
            sService_Call_Log.Subject__C = email.subject;
            sService_Call_Log.description__C= email.plainTextBody;
            sService_Call_Log.Web_Email__C=email.FromAddress;
            sService_Call_Log.Web_name__C=email.FromName;
            insert sService_Call_log;
           
             if (email.textAttachments != null)
            {
            for(Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments)
            {
            Attachment attachment = new Attachment();

            attachment.Name = tAttachment.fileName;
            attachment.Body = Blob.valueOf(tAttachment.body);
            attachment.ParentId = sService_Call_log.Id;
            insert attachment;
            }
           
            }

            //Save any Binary Attachment
           
            if (email.binaryAttachments != null)
            {
            for(Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) {
            Attachment attachment = new Attachment();

            attachment.Name = bAttachment.fileName;
            attachment.Body = bAttachment.body;
            attachment.ParentId = sService_Call_log.ID;
            insert attachment;
            }
           }
       
            }
            Catch(QueryException e){
            system.debug('Query Issue: '+e);
            }
           
       

        result.success = true;
        return result;
            
   }
}


 I have setup an email service and have the follow class that when an email is sent it create a record in the custom object ticket but i want it to pull any attachments and save them in the attachment section for that record.  I do not geting errors but no attachments are being saved

global class EmailToTicket implements Messaging.InboundEmailHandler {

        global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
            Messaging.InboundEnvelope envelope) {
            
            Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
           
     
           
            Ticket__C sTicket = new Ticket__C();       
            {
            sTicket.Job__C = 'a013000000UHggN';
            sTicket.Subject__C = email.subject;
            sTicket.description__C= email.plainTextBody;
            sTicket.Web_Email__C=email.FromAddress;
            insert sticket;
           
         if (email.textAttachments != null)
            {
            for(Messaging.Inboundemail.TextAttachment tAttachment : email.textAttachments)
            {
            Attachment attachment = new Attachment();

            attachment.Name = tAttachment.fileName;
            attachment.Body = Blob.valueOf(tAttachment.body);
            attachment.ParentId = sTicket.Id;
            insert attachment;
            }
           
            }

            //Save any Binary Attachment
           
            if (email.binaryAttachments != null)
            {
            for(Messaging.Inboundemail.BinaryAttachment bAttachment : email.binaryAttachments) {
            Attachment attachment = new Attachment();

            attachment.Name = bAttachment.fileName;
            attachment.Body = bAttachment.body;
            attachment.ParentId = sTicket.Id;
            insert attachment;
            }
           }
        }

        result.success = true;
        return result;
            
   }
}
I am having issues with a public site not showing fields.  When i hit preview on the visualforce page everything shows up but when i go to the URL i only see the title.  I have checked the guest profile and all the fields have been granted access.  Any ideas
I am working if a trigger to convert multiple leads at once and need help with the test class

the trigger is:

trigger AutoConvert on Lead (after update) {
    list<Lead> LeadsToConvert = new list<Lead>();
    for(Lead myLead: Trigger.new){
        if(!myLead.isConverted)
            LeadsToConvert.add(myLead);
    }
 
    list<Database.LeadConvert> leadConverts = new list<Database.LeadConvert>();
    for(Lead myLead : LeadsToConvert){
        Database.LeadConvert lc = new database.LeadConvert();
        lc.setLeadId(myLead.Id);
        lc.convertedStatus = 'Qualified';

        //Database.ConvertLead(lc,true);
        lc.setDoNotCreateOpportunity(true);
        leadConverts.add(lc);
  }
    if(!leadConverts.isEmpty()){
        for(Integer i = 0; i <= leadConverts.size()/100 ; i++){
            list<Database.LeadConvert> tempList = new list<Database.LeadConvert>();
            Integer startIndex = i*100;
            Integer endIndex = ((startIndex+100) < leadConverts.size()) ? startIndex+100: leadConverts.size();
            for(Integer j=startIndex;j<endIndex;j++){
                tempList.add(leadConverts[j]);
            }
            Database.LeadConvertResult[] lcrList = Database.convertLead(tempList, false);
            for(Database.LeadConvertResult lcr : lcrList)
                System.assert(lcr.isSuccess());
        }
    }

}

and the test class is 

@isTest
Private class UnitTest_AutoConvert {

Static TestMethod void AutoConvert(){

    test.StartTest();

   // Create the Lead object
   Lead testLead = new Lead(
  id='00Qa0000012cJlM',
   FirstName='Demo 100800',
   LastName = 'Demo 100800 UnitTest',
   Status='Qualified',
   company='Lacosta',
   street='1211 E I-40 Service Rd',
   city=' Oklahoma City',
   state='OK'
  // zippostal_code= '73149'
   
   //Ready_to_Convert__c = true
   );

   update testLead;
   System.debug('Created and inserted lead');

   Database.LeadConvert lc = new database.LeadConvert();
   lc.setLeadId(testLead.Id);

   LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
   lc.setConvertedStatus(convertStatus.MasterLabel);
   Database.LeadConvertResult lcrList = Database.convertLead(lc);

   // Make sure conversion was successful
   System.assert(lcrList.isSuccess());

   test.stopTest();
   }
   }

i am currently getting the following error
System.DmlException: ConvertLead failed. First exception on row 0; first error: CANNOT_UPDATE_CONVERTED_LEAD, cannot reference converted lead: []
Stack Trace Class.UnitTest_AutoConvert.AutoConvert: line 31, column 1
 
I am looking for some help with a simple if statement and the code coverage

here is the trigger

trigger Case4fromRD on RD_Site_Report__c (after insert, after update) {
List<Service_Call_Log__C>SCL=New list<Service_Call_Log__C>();
    For(RD_Site_Report__C b:trigger.new)
    {
        IF (b.case_topic__C !=null){
           SCL.add(new Service_Call_Log__C(Subject__C='A Case has been created from an RD Site Report',job__C=b.Job__C, description__C=b.case_Topic__C, Web_email__C=b.contact_email__C));
            insert SCL; 
        }
       
    
    }
}

and here is the test class

@isTest
public class Rd_Site_Report_SCL1{

static testMethod void CasefromRD(){

RD_Site_Report__c sRDSR = new RD_Site_Report__c();

sRDSR.Reason__C='Customer Complaint';
sRDSR.Case_Topic__c ='Test';
sRDSR.Job__C='a013000000UHggN';
sRDSR.case_topic__C='Test';
sRDSR.Contact_Email__C='tmonson@cms4.com';

Test.StartTest();

insert sRDSR;

test.stopTest();

}
}
I have a visualforce page that used a custom controller to pull a list from an object and offers inline editing.  I was trying to do a quicksave button like with standard controller but i am unable to.  How can add a quicksave to a custom controller

<apex:page controller="Scllist1">
<apex:form >
 <apex:pageblock title="Open Service Call Logs">
 <apex:pageblocksection >
 <apex:pageblockTable value="{!acts}" var="s">
 <apex:column value="{!s.name}"/>
 <apex:column headerValue="Status">
 <apex:inputfield value="{!s.Status__c}"/>
 </apex:column>
 </apex:pageblockTable>
 </apex:pageblocksection>
 </apex:pageblock> 
 </apex:form>
</apex:page>

here is the controller

public class Scllist1 {
    List<Service_call_log__C> acts =[Select Name, subject__c, status__C From Service_call_log__c where status__C<>'Closed'];
    
    public List<Service_Call_log__C> getacts() 
    {
    return acts;
     }
}
I currently have a page with a command button that creates a new record.  I would like to predefine the recordtype to the user goes directly to the page 

Here is what i currently have

<apex:commandButton value="Salary Time Off Request" action="{!URLFOR($Action.Forms__c.New)}"/>
I am looking to create a visualforce page that will show all the record of a custom object and when you click on the name for the record to ope up.  So far i everything is displaying correctly but when i click on the record name nothing happens. 

Here is my code

<apex:page standardController="Jobs__c" recordSetVar="jbs" sidebar="false">
<apex:panelGrid columns="1">
    <apex:form >
     <apex:pageBlock title="Current Accounts">

         <apex:pageBlockTable Value="{!jbs}" var="a">
             <apex:column >
                 <apex:commandLink value="{!a.name}" reRender="Out">
                 <apex:param name="ID" value="{!a.ID}"/>
                 </apex:commandLink>
             </apex:column>
             <apex:column value="{!a.name}"/>
             <apex:column headerValue="Active" >
                 <apex:inputField value="{!a.Active__c}"/>
             </apex:column>
             <apex:Column value="{!a.Job_Number__c}"/>
     </apex:pageBlockTable>
    </apex:pageBlock>
    </apex:form>
    <apex:outputPanel id="out">
    <apex:Detail subject="{!$CurrentPage.parameters.id}" relatedlist="false"/>
    </apex:outputPanel>
    </apex:panelGrid>
</apex:page>
  • September 28, 2015
  • Like
  • 0
I am looking for some help on a trigger to update a field.  I have 3 custom objects (job, Employee, and Employee form). the job is the master to the employee and the employee is the master to the employee form.  I have a number field called hats on the job object and when a employee form is created i want to use the quantity field to update the hat field.

So far i have the following but i am getting the error "Initial term of field of expression must be a concrete object".


trigger updateHats on Employee_Forms__c (before insert) {
   set<id> jobids=new set<id>();  
   map<id,jobs__c> jobsmap=new map<id,jobs__c>([select id, hats__C from jobs__c where id=:jobids]);
   //List<Jobs__C>Jobs=new list<jobs__c>();
    For(employee_forms__C b:Trigger.new)
        if(b.Uniform_Type__C=='Hat')
    {
        jobsmap.hats__C= jobsmap.hats__C - b.Quantity__C;
    }
        }


I think its because the job and the employee form object are not directly related but i am not sure and if i was sure i am not sure how to go about fixing it.  

Any help i would appreciate 
I have a customer field called Subject that i would like to have the informtion change from  TT-ABS EE38877 Jessica Martin is Absent. 0 Present. JB1356 Evonik Labs PO146 T&m

to only show the name Jessica Martin

the name changes but the format is always the same.  Any idea's where to begin
I am trying to get my class to pass but i keep getting an error when i run it.  there error is
System.EmailException: SendEmail failed. First exception on row 0; first error: INVALID_EMAIL_ADDRESS, Invalid to address : null: []

 here is the test class

@isTest
public Class TestEamilAttchment{
   Static testMethod Void TestinBoundEmail()
       {
   //create a new email and envelope ojbect
   messaging.InboundEmail email = new Messaging.InboundEmail();
   Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();
   
   //setup the data for the email
   email.subject='Create Service Call Log';
   env.fromAddress='Tmonson@cms4.com';
   email.plainTextBody='Email body\n2332345354454\nTitle';
   email.FromName ='Thomas Monson';
   
        Service_Call_Log__C sService_Call_Log = new Service_Call_Log__C();   
   sService_call_log.Contact__C='00330000012mk3O';
 
   
   //add an Binary attachment
   
   Messaging.InboundEmail.BinaryAttachment attachment = new Messaging.InboundEmail.BinaryAttachment();
   attachment.body = blob.valueOf('My attachmeent text');
   attachment.fileName = 'textfileone.txt';
   attachment.mimeTypeSubType='Text/Plain';
   email.binaryAttachments=new Messaging.inboundEmail.BinaryAttachment[]{attachment};

   
   
   //add an Text attachmet
   
   Messaging.InboundEmail.TextAttachment attachmenttext = new Messaging.InboundEmail.TextAttachment();
   attachmenttext.body = 'my attachment text';
   attachmenttext.fileName = 'textfiletwo3.txt';
   attachmenttext.mimeTypeSubType='texttwo/plain';
   email.textAttachments = new Messaging.inboundEmail.TextAttachment[]{attachmenttext};  
      //call the email serivce class and text it with the data in the textMethod
   
  EmailToServiceCallLog testInbound= new EmailToServiceCallLog ();
    testInbound.handleInboundEmail(email,env);          
      }
      }

i am trying to use a visualforce page to display the contents of a document, but when the page loads i get the following error

common.apex.runtime.impl.ExecutionException: BLOB is not a valid UTF-8 string

<apex:page renderAs="pdf" controller="basicWeightPDF" contentType="HTML" >
<html>
<body>
{!dipslaytable}
</body>
</html>
</apex:page>

public class basicWeightPDF{
public string dipslaytable{get;set;}
public basicWeightpdf()
{
document d=[Select id, body from document where id='015190000000W33'];
Blob bodyOfAttachment = EncodingUtil.base64Decode('JVBERi0xLjIgCiXi4');
string strOrgId=UserInfo.getOrganizationID();
dipslaytable=d.body.tostring();
}
}