• Zach Gavin Delacroix
  • NEWBIE
  • 60 Points
  • Member since 2015

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 14
    Replies
Hello, Please help me get around an issue with Lightning.

When quering Opportunity, list.size() returns different value in Classic and Lighting. In Classic, it return right number and incorrect in Lightning.

This is how you can test it.

•Add the Trigger under Opportunity
trigger OpportunityTrigger on Opportunity (after insert) {
list<opportunitycontactrole> ocrList = [select id from opportunitycontactrole where opportunityid in : trigger.new];
system.debug(ocrList.size());
}
•Open Developer Console so you can see the Log Result.
•Add Opportunity from Contact's Opportunity Related List (In Classing Mode) and Check the Log.. The Result should be 1 in Classic which is Expected Result.
•Add Opportunity from Contact's Opportunity Related List (in Lightning Mode) and Check the Log. This part is where the Bug is as it returns 0 result..


NOTE: I've tried @Future call but still not working, I've tried to put it on Batch Apex and not working as well. You can notice that if you place the Code on Update and Update the Opportunity, you will see correct result but I need this on Insert. When you do Update after the record is inserted, then returns incorrect value again.

I need to get around this because I need to check if there are existing contact roles first before I insert a new one.

Thank you
 
Hello,

I have an issue with a trigger now working in Lightning but works as expected in Classic.

I have a simple trigger which validates whether there's a contact role already in an Opportunity or not. If none, then will create one.

Example I have:
list<OpportunityContactRole> ocr = [select id from OpportunityContactRole where id in : oppList];
if there are 2 Contact Roles on the Opportunity the ocr.size() should return 2.. But on lightning, this always return 1..

The purpose of my trigger is when the Opportunity is created from the Opportunity Tab and account is selected, it will automatically create an Opportunity Contact Role based on the Contact on the Account.

However, when we do this under Contact, this automatically create 1 Contact Role (Standard SF function) and another 1 contact role from my trigger.

To avoid that, I figured I needed to do a validation before I create the Contact Role.

Here's my trigger.
 
public class SG_OpportunityTriggerHandler{
    
    //This will create Opportunity Contact Role
    public void NEW_OCR(list<Opportunity> OppList){
        //THIS PART DOES NOT WORK IN LIGHTNING
        map<id,OpportunityContactRole> ocrMap = new map<id,OpportunityContactRole>();
        for(OpportunityContactRole ocr : [select id,opportunityId,contactId  from OpportunityContactRole where opportunityId in : OppList]){
            ocrMap.put(ocr.opportunityId,ocr);
        }
        
        list<OpportunityContactRole> newOCR = new list<OpportunityContactRole>();
        
        for(opportunity opp : [select id,account.Contact__c,account.Person_Account__c from opportunity where id in: OppList]){
            if(opp.account.Contact__c != null && opp.account.Person_Account__c == true){
                if(!ocrMap.containsKey(opp.id)){
                    OpportunityContactRole ocr = new OpportunityContactRole();
                    ocr.contactId = opp.account.Contact__c;
                    ocr.opportunityId = opp.id;
                    ocr.IsPrimary = true;
                    newOCR.add(ocr);
                }
            }
        }
        
        database.insert(newOCR);
    }

}

 
Hello,

Can anyone please give me idea how to dynamically get value from addCustomDetail in LiveAgent.

This code is not working..
liveagent.addCustomDetail("First_Name",document.getElementById("FirstName").value);

and here's the whole Code.
 
<script type='text/javascript' src='https://c.la1-c1cs-ukb.salesforceliveagent.com/content/g/js/41.0/deployment.js'></script>

<script type='text/javascript'>
 
//Custom Details
  liveagent.addCustomDetail("Customer_Name",document.getElementById("prechat_field_name").value);
  //CASE
  liveagent.addCustomDetail("Case_Status", "New");
  liveagent.addCustomDetail("Case_Origin", "Chat");
  liveagent.addCustomDetail("Case_Record Type", "01228000000isic");
  liveagent.addCustomDetail("Case_Product", "House and Land");
  liveagent.findOrCreate("Case")
    .map("Subject","Case_Origin",false,false,true)
    .map("Status","Case_Status",false,false,true)
  	.map("Product__c","Case_Product",false,false,true)
  	.map("RecordTypeId","Case_Record",false,false,true)
    .saveToTranscript("CaseId")
    .showOnCreate();
  
  
//End of Custom Details
liveagent.init('https://d.la1-c1cs-ukb.salesforceliveagent.com/chat', '5725D000000000f', '00D5D0000000TZM');
</script>
I hope you can help me here.. Thank you!


 
Hello,

I would like to know if there is a way for me to populate an address on Contact based on the Postal Code.

For example, if a new Contact is created and if the Postal Code is populated then it will autopopulate the Mailing City, Mailing State/Province and Country. I would like to have an Idea how to achive this through Apex Class. This should not be in VisualForce page as I need it to be populated just after the Contact is inserted.

The idea here is we have a Website (Kind of Web-to-Lead) which only have fields First Name, Last Name, Phone, Post Code and when we create the lead from the Website, it should autopopulate the Address details based on the Postal Code.

It would be great to have a sample and simple code to understand.

Thanks you in advance.

Hello guys,

I need help on the Google Map Marker to be available in my Visualforce Email Template.
Basically, the code below works fine in a visualforce page and I want to do similar to a Visualforce Email Template.

<script src="https://maps.googleapis.com/maps/api/js?&sensor=false">
  </script>

  <script>
      function showMap(){
      var latlng = new google.maps.LatLng(15.477830, 120.589827);
      var myOptions = {
          zoom: 8,
          center : latlng,
         mapTypeId:google.maps.MapTypeId.ROADMAP
      };
      var myMap = new google.maps.Map(document.getElementById('theMap'),myOptions);
      
      var marker = new google.maps.Marker({position:latlng,map:myMap});
     }
     window.onload = showMap;
  </script>

  <div id="theMap" style="width:300px;height:300px"> </div>

When the code is applied in a Visualforce Email Template, it returns me an entirely blank page. I have it directly coded in the Visualforce Email template (rendering html) and tried using a custom component as well but no luck.

I'm able to place the Map using the link below (Directly in my Visualforce Template) but no Marker of course.
 
<img src="https://maps.googleapis.com/maps/api/staticmap?center={!RelatedTo.job__r.Address__c}&zoom=14&size=300x400&sensor=false" ></img>

can anyone help me on this. Thanks a lot in advance :)

Zach
Hello,

I'd like some idea on how to pass the Value from one page (child) to another (parent).

I have main page which contains 1 text field (or could be lookup field) and a button that will call my 2nd page.
The Main page look something like below.

User-added image
Then that button will call the second page which looks like this one.
User-added image
What I want is that when I click one of these values, Either contact or contact roles, the value will be passed to the input field that I have in the Main Page.

Basiclly, the story is that I would like to create a custom lookup field that will allow me to select the Contact and the Contact Roles in the Account. The standard lookup contact does not allow me to look on the Contact Roles so this is what I thought a solution.

I hope you can help me guys :)

Thanks a lot!

Zach
 
Hello Guys,

I'd like to ask for help on how to resolve this particular issue. I don't get syntax Error but when I execute the trigger, it returns me this Error.

Error:Apex trigger SkedCreateTasksTrigger caused an unexpected exception, contact your administrator: SkedCreateTasksTrigger: execution of BeforeUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Name ID: id value of incorrect type: 00528000002rYgOAAU: [WhoId]: Trigger.SkedCreateTasksTrigger: line 30, column 1


Story:
        I have VA Task and a Standard Salesforce Task (Activity) Related List under My JOB object.

        Basically, when I update the Job Status to Complete, I'd like to have a copy of VA Task as a Standard Salesforce Task for each VA Task.

CODE:
trigger SkedCreateTasksTrigger on sked__Job__c (before Update) {
    
    set<id> jobId = new set<id>();
    
    for(sked__Job__c job: trigger.new){
        if(job.sked__Job_Status__c == 'Complete'){
            jobId.add(job.id);
        }
    }
    
    list<Task> newTasks = new list<Task>();
    
    for(VA_Task__c vaTask : [select Job__c, Comments__c,Priority__c,Status__c,Subject__c,Assigned_To__r.id from VA_Task__c where job__c In: jobId]){
        
        Task t = new Task();
        t.WhoId = vaTask.Assigned_To__r.id;
        t.WhatId = vaTask.Job__c;
        t.priority = vaTask.Priority__c;
        t.Status = 'Not Started';
        t.Subject = vaTask.Subject__c;
        t.Description = vaTask.Comments__c;
        
        newTasks.add(t);
    }
    
    for(integer i=0;i<newTasks.size();i++){
        system.debug(newTasks[i].whoId);
    }
    
    insert newTasks;
}

How Can I fix the Error?

Thanks,

Zach
Hello Experts,

I'd like an advise on how to use custom controller in Visualforce Email Template.

Basically, I would create a Controller like this.
 
public class HourlyJobReport{
    
    public List<job__c> JobList{get;set;}
    
    public HourlyJobReport() {
        
        JobList = new List<Job__c>();
        JobList = [select name, status__c, duration__c, start__c from job__c where status__c = 'Dispatch' and Duration__c > 60];
    }
    
}

Then would reference the code to the Component like this.
 
<apex:component controller="HourlyJobReport" access="global">

    <apex:dataTable value="{!JobList}" var="job">
             <column value="{!job.name}"/>
    </apex:dataTable>


</apex:component>

Then use the component in the Template like this.
 
<c:nameOfTheComponent>

This approach works great. But I'd like to have the Repeat tag in my visualforce Template Intead of using it in the Component. One reason is that when I do styling from the Component, the Style does not work when the Visualforce Email Template is Sent through email.

in the Preview of the VisualForce Page, it looks like this one below. (Note, I'm using style here from the Component that I have created for the custom controller)

User-added image

But when it's sent to my email, it will look like just a plain text. Something like below.

User-added image

Does anyway here encountered issues like this or have solution for this one?

Thanks a lot :)

-Zach
Hi Experts,

I need help on fixing issue on my PDF rendered page.

The normal view works just fine. But when I set the page to render as PDF, then I'm having issue with the output.

Here's how it looks like, the on on the Left is Normal View of VisualForce and Right is the one Rendered as PDF which is having issue as you see.

User-added image


Here's the code..
 
<apex:page controller="accountController2" sidebar="false">
  
  <apex:variable value="{!0}" var="counter"/>
    <table style="Border:Solid 1px">
        <tr>
          <td style="Border:Solid 1px;background-color:green">
              Column 1
          </td>
          <td style="Border:Solid 1px;background-color:green">
              Column 2
          </td>
      </tr>
    <apex:repeat value="{!acc}" var="record">
        <apex:outputPanel rendered="{!mod(counter,2)=0}"> <!---->
            <apex:outputText escape="false" value="<tr>"/>
                <td style="Border:Solid 1px">{!record.name}</td>
        </apex:outputPanel>
        <apex:outputPanel rendered="{!mod(counter,2)=1}"> <!---->
                <td style="Border:Solid 1px">{!record.name}</td>
            <apex:outputText escape="false" value="</tr>"/>
        </apex:outputPanel>
        <apex:variable value="{!counter+1}" var="counter"/>
    </apex:repeat>
        <td>
        
        </td>
    </table>
</apex:page>
Then My controller..
 
public class accountController2 {
    
    public list<account> acc{get;set;}
   
   public accountController2 (){
       
       acc = new list<account> ();
       
       acc = [select name from account limit 10];
   
   }
}

Just make the Page renderAs PDF then you'll see the difference..

Thanks a lot!

-Zach
 
Hello,

I created visualforce that converts the page to PDF..

I have 2 pages, both are using the Same controller (where my image URL is located) and both have the same code except the second 1 is rendered as PDF. The 1st page serves as a Preview before converting it to PDF format.


The PDF format image shows like this one below.

User-added image

Below is how I call the URL from the Controller (which the same way I call it from the preview and it's working)

I have this one from the Controller : imageURL = '/servlet/servlet.ImageServer?id=01555000000fdlO&oid=00D5500000066Iu&lastMod=1445545410000';

Then I call it from the PDF Rendered VF like this.
 
<table style="border: 1px solid white;" width="100%">
                     <tr>
                        <td style="border-color:white" width="80px" >
                            <apex:image url="{!imageURL}" />
                        </td>
                        <td style="border-color:white; text-align:left;" width="70%">
                            <font face="calibri" color="black" size="10"><h2>Traffic Control Form</h2></font>
                        </td>
                    </tr>
                </table>

Not sure where else to look so I decided to ask.

Thank you!

-Zach

 
Hi Experts!

I'm trying to convert list of Account's created date to a specific timeZone. Like PST.

I'm able to convert a single record like below.
 
public class accountTimeZone {
    public account acc{get;set;}
    public String LocalDate{get;set;}
   
    public accountTimeZone(){
        acc = [select createdDate from Account where id = '0019000001JCS1x'];
        LocalDate = acc.createdDate.format('MMMM dd, yyyy hh:mm a','America/New_York');
        System.debug(LocalDate);
    }
}

But how will I go about converting a list of Create Dates like.
 
public class accountTimeZone {

public list<account> AccountDate {get;set;}
public list<DateTime> convertedDate{get;set;}

public accountTimeZone(){

        AccountDate = [select createdDate from account limit 5];
        
    }
}

I'd like to convert these dates then call them in my visualforce page apex table.

Thank you in advance!

-Zach
Hi Experts,

I'm trying to alternately populate the columns in my visualforce page with the Account Records. I'm not sure how to do it though.

Here's my page which returns a simple Table with Rows and Columns.
<apex:page controller="accountController">
  
  <table style="Border:Solid 1px">
      <tr>
          <td style="Border:Solid 1px;background-color:green">
              Column 1
          </td>
          <td style="Border:Solid 1px;background-color:green">
              Column 2
          </td>
          <td style="Border:Solid 1px;background-color:green">
              index
          </td>
      </tr>
      <apex:repeat value="{!wAcc}" var="a">
      <tr>
          <td style="Border:Solid 1px">
              <apex:outputText value="{!a.name}"/>
          </td>
          <td style="Border:Solid 1px">

          </td>
          <td style="Border:Solid 1px">

          </td>
      </tr>
      </apex:repeat>
  </table>
</apex:page>

I have the controller named "accountController" which simply contains a list of Accounts.

When I call this in visualforce, it will only return the table below. What I would like to do is to have the first record in the list to go to the 1st column of first row, then the second record go to the second column of first row, then 3rd record goes to the 1st column in the second row and so on. How do I go about it?

User-added image

Thanks in advance :)







 

Hello Experts,

I'm new to visualforce page and trying to explore things by doing some tests. I'd like to ask for your help on how to I'll be able to edit records from a pageBlockTable in visualforce.

Here's how my page look like to start with.

Add Account Tab : Where I can save account (Shows accounts that are saved below)
User-added image

Account Details Tab: This shows all accounts I created (This is where my question is)

User-added image
 

Right now, I have the Edit and Delete commandLink but doesn't do anything yet. I don't know where to start here.

What I'd like to do is to be able to edit or delete the Account from those commandLinks.

Can I please have the Idea how to achieve that?

Thanks a in advance!

--MY CODES HERE--

=====Page=======
 

<apex:page controller="TheController" sidebar="false">
  <apex:form >
      <apex:pageBlock >
          <apex:tabPanel >
       
              <apex:tab label="Add Account">
                  <apex:pageBlock title="Input Account Details"> <br/>
                      <b>&nbsp;&nbsp;Account Name </b>
                      <br/>*&nbsp;<apex:inputText value="{!newAccount.name}"/>
                      <br/><apex:messages />
                      <p/><br/><b>&nbsp;&nbsp;Industry </b>
                      <br/>&nbsp;&nbsp;<apex:inputField value="{!newAccount.Industry}"/>
                      <p/><br/><b>&nbsp;&nbsp;Type</b><br/>
                      &nbsp;&nbsp;<apex:inputField value="{!newAccount.Type}"/>
                      <p/><br/><b>&nbsp;&nbsp;Phone </b><br/>
                      &nbsp;&nbsp;<apex:inputField value="{!newAccount.Phone}"/>
                      <p/>
                      <apex:commandButton value="Add Account" action="{!addAccount}" reRender="myPage"/>
                      
                  </apex:pageBlock>
                      
                  <apex:pageBlock title="Added Accounts" id="myPage">
                      <apex:pageBlockTable value="{!AddedAccountsList}" var="addedAccounts">
                          <apex:column value="{!addedAccounts.name}"/>
                          <apex:column value="{!addedAccounts.Industry}"/>
                          <apex:column value="{!addedAccounts.Type}"/>
                          <apex:column value="{!addedAccounts.Phone}"/>
                      </apex:pageBlockTable>
                  </apex:pageBlock>
              </apex:tab>
              
              <apex:tab label="Account Details">
                  <apex:pageBlockSection columns="1" >
                      <apex:pageBlockTable value="{!ViewAccounts}" var="acc" >
                          <apex:column ><apex:commandLink action="{!EditAccount}" value="Edit"/></apex:column>
                          <apex:column ><apex:commandLink action="{!DeleteAccount}" value="Delete"/></apex:column>
                          <apex:column value="{!acc.name}" />
                          <apex:column value="{!acc.Industry}"/>
                          <apex:column value="{!acc.Type}"/>
                          <apex:column value="{!acc.Phone}"/>
                      </apex:pageBlockTable>
                  </apex:pageBlockSection>
              </apex:tab>
              
          </apex:tabPanel>
      </apex:pageBlock>
  </apex:form>
</apex:page>
 


=====Controller=======

public class TheController {

    public Account newAccount{get;set;}
    list<Account> addedAccounts;
    
    public TheController(){
        newAccount = new Account();
        addedAccounts = new list<Account>();
    }

    public List<Account> getViewAccounts(){
        List<account> lstAccount = [select id, name, industry, type, phone from account where createdById =:userinfo.getuserId() order By CreatedDate desc];
        return lstAccount;
    }
    
    public void addAccount(){
            
             try {
                 addedAccounts.add(newAccount.clone());
                 insert newAccount.clone();
             } catch (Exception e) {
                 ApexPages.addMessages(e);
             }
             
    }
    
    public List<account> getAddedAccountsList(){
        return addedAccounts;
    }
    
    public void EditAccount(){
    
    }
    public void DeleteAccount(){
    }
}
Hi Experts,

I'm trying to learn VisualForce and it seems that I'm stuck with using Collection.

I have <apex:inputField> and <apex:commandButton>, what I want to do is add the value I type in the inputField when I click the commandButton.

Can anyone please give me an Idea of the correct syntax?

Here's the code I created so far that is not working as expected.
<apex:page controller="MultiAccountInsertController" sidebar="false">
  
  <apex:pageBlock title="Enter Account Name">
      <apex:form >
          <apex:inputText value="{!acc.name}"/>
          <apex:commandButton value="Add Account" action="{!addAccount}"/>
      </apex:form>
  </apex:pageBlock>  
  
  <apex:pageBlock title="List of Accounts to Save">
  	To be continued...
  </apex:pageBlock>
</apex:page>
CLASS
 
public class MultiAccountInsertController {
    
    Public account acc{get;set;}
    List<account> AccountList; 

    public MultiAccountInsertController(){
        acc = new account();
        AccountList = new List<account>();
    }
    public void addAccount(){
		AccountList.add(acc);
        
        //Check value of the AccountList in Debug
        for(integer i=0;i<AccountList.size();i++){
           system.debug(AccountList[i].name); 
        }
    }
    public List<account> getViewAccounts(){
        return AccountList;
    }
}

When I run Click the button, the result goes like below.

09:41:52:039 USER_DEBUG [13]|DEBUG|A
09:41:52:039 USER_DEBUG [13]|DEBUG|B

The result I want should look like below because I typed "A" first then pressed the button, then Typed B then pressed the button. So Everytime I type value in the Text Field, I want to add it as a value in my List.

09:41:52:039 USER_DEBUG [13]|DEBUG|A
09:41:52:039 USER_DEBUG [13]|DEBUG|B

NOTE: I'm using Account for testing, when I have this working, I'll try to work on inserting the Records from the List of Accounts (But don't answer this part coz I want to figure it our my self first :D )

Thanks for the help!
Hello,

Can anyone please give me idea how to dynamically get value from addCustomDetail in LiveAgent.

This code is not working..
liveagent.addCustomDetail("First_Name",document.getElementById("FirstName").value);

and here's the whole Code.
 
<script type='text/javascript' src='https://c.la1-c1cs-ukb.salesforceliveagent.com/content/g/js/41.0/deployment.js'></script>

<script type='text/javascript'>
 
//Custom Details
  liveagent.addCustomDetail("Customer_Name",document.getElementById("prechat_field_name").value);
  //CASE
  liveagent.addCustomDetail("Case_Status", "New");
  liveagent.addCustomDetail("Case_Origin", "Chat");
  liveagent.addCustomDetail("Case_Record Type", "01228000000isic");
  liveagent.addCustomDetail("Case_Product", "House and Land");
  liveagent.findOrCreate("Case")
    .map("Subject","Case_Origin",false,false,true)
    .map("Status","Case_Status",false,false,true)
  	.map("Product__c","Case_Product",false,false,true)
  	.map("RecordTypeId","Case_Record",false,false,true)
    .saveToTranscript("CaseId")
    .showOnCreate();
  
  
//End of Custom Details
liveagent.init('https://d.la1-c1cs-ukb.salesforceliveagent.com/chat', '5725D000000000f', '00D5D0000000TZM');
</script>
I hope you can help me here.. Thank you!


 
Hello, Please help me get around an issue with Lightning.

When quering Opportunity, list.size() returns different value in Classic and Lighting. In Classic, it return right number and incorrect in Lightning.

This is how you can test it.

•Add the Trigger under Opportunity
trigger OpportunityTrigger on Opportunity (after insert) {
list<opportunitycontactrole> ocrList = [select id from opportunitycontactrole where opportunityid in : trigger.new];
system.debug(ocrList.size());
}
•Open Developer Console so you can see the Log Result.
•Add Opportunity from Contact's Opportunity Related List (In Classing Mode) and Check the Log.. The Result should be 1 in Classic which is Expected Result.
•Add Opportunity from Contact's Opportunity Related List (in Lightning Mode) and Check the Log. This part is where the Bug is as it returns 0 result..


NOTE: I've tried @Future call but still not working, I've tried to put it on Batch Apex and not working as well. You can notice that if you place the Code on Update and Update the Opportunity, you will see correct result but I need this on Insert. When you do Update after the record is inserted, then returns incorrect value again.

I need to get around this because I need to check if there are existing contact roles first before I insert a new one.

Thank you
 
Hello,

I have an issue with a trigger now working in Lightning but works as expected in Classic.

I have a simple trigger which validates whether there's a contact role already in an Opportunity or not. If none, then will create one.

Example I have:
list<OpportunityContactRole> ocr = [select id from OpportunityContactRole where id in : oppList];
if there are 2 Contact Roles on the Opportunity the ocr.size() should return 2.. But on lightning, this always return 1..

The purpose of my trigger is when the Opportunity is created from the Opportunity Tab and account is selected, it will automatically create an Opportunity Contact Role based on the Contact on the Account.

However, when we do this under Contact, this automatically create 1 Contact Role (Standard SF function) and another 1 contact role from my trigger.

To avoid that, I figured I needed to do a validation before I create the Contact Role.

Here's my trigger.
 
public class SG_OpportunityTriggerHandler{
    
    //This will create Opportunity Contact Role
    public void NEW_OCR(list<Opportunity> OppList){
        //THIS PART DOES NOT WORK IN LIGHTNING
        map<id,OpportunityContactRole> ocrMap = new map<id,OpportunityContactRole>();
        for(OpportunityContactRole ocr : [select id,opportunityId,contactId  from OpportunityContactRole where opportunityId in : OppList]){
            ocrMap.put(ocr.opportunityId,ocr);
        }
        
        list<OpportunityContactRole> newOCR = new list<OpportunityContactRole>();
        
        for(opportunity opp : [select id,account.Contact__c,account.Person_Account__c from opportunity where id in: OppList]){
            if(opp.account.Contact__c != null && opp.account.Person_Account__c == true){
                if(!ocrMap.containsKey(opp.id)){
                    OpportunityContactRole ocr = new OpportunityContactRole();
                    ocr.contactId = opp.account.Contact__c;
                    ocr.opportunityId = opp.id;
                    ocr.IsPrimary = true;
                    newOCR.add(ocr);
                }
            }
        }
        
        database.insert(newOCR);
    }

}

 
Hello Guys,

I'd like to ask for help on how to resolve this particular issue. I don't get syntax Error but when I execute the trigger, it returns me this Error.

Error:Apex trigger SkedCreateTasksTrigger caused an unexpected exception, contact your administrator: SkedCreateTasksTrigger: execution of BeforeUpdate caused by: System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, Name ID: id value of incorrect type: 00528000002rYgOAAU: [WhoId]: Trigger.SkedCreateTasksTrigger: line 30, column 1


Story:
        I have VA Task and a Standard Salesforce Task (Activity) Related List under My JOB object.

        Basically, when I update the Job Status to Complete, I'd like to have a copy of VA Task as a Standard Salesforce Task for each VA Task.

CODE:
trigger SkedCreateTasksTrigger on sked__Job__c (before Update) {
    
    set<id> jobId = new set<id>();
    
    for(sked__Job__c job: trigger.new){
        if(job.sked__Job_Status__c == 'Complete'){
            jobId.add(job.id);
        }
    }
    
    list<Task> newTasks = new list<Task>();
    
    for(VA_Task__c vaTask : [select Job__c, Comments__c,Priority__c,Status__c,Subject__c,Assigned_To__r.id from VA_Task__c where job__c In: jobId]){
        
        Task t = new Task();
        t.WhoId = vaTask.Assigned_To__r.id;
        t.WhatId = vaTask.Job__c;
        t.priority = vaTask.Priority__c;
        t.Status = 'Not Started';
        t.Subject = vaTask.Subject__c;
        t.Description = vaTask.Comments__c;
        
        newTasks.add(t);
    }
    
    for(integer i=0;i<newTasks.size();i++){
        system.debug(newTasks[i].whoId);
    }
    
    insert newTasks;
}

How Can I fix the Error?

Thanks,

Zach
Hello Experts,

I'd like an advise on how to use custom controller in Visualforce Email Template.

Basically, I would create a Controller like this.
 
public class HourlyJobReport{
    
    public List<job__c> JobList{get;set;}
    
    public HourlyJobReport() {
        
        JobList = new List<Job__c>();
        JobList = [select name, status__c, duration__c, start__c from job__c where status__c = 'Dispatch' and Duration__c > 60];
    }
    
}

Then would reference the code to the Component like this.
 
<apex:component controller="HourlyJobReport" access="global">

    <apex:dataTable value="{!JobList}" var="job">
             <column value="{!job.name}"/>
    </apex:dataTable>


</apex:component>

Then use the component in the Template like this.
 
<c:nameOfTheComponent>

This approach works great. But I'd like to have the Repeat tag in my visualforce Template Intead of using it in the Component. One reason is that when I do styling from the Component, the Style does not work when the Visualforce Email Template is Sent through email.

in the Preview of the VisualForce Page, it looks like this one below. (Note, I'm using style here from the Component that I have created for the custom controller)

User-added image

But when it's sent to my email, it will look like just a plain text. Something like below.

User-added image

Does anyway here encountered issues like this or have solution for this one?

Thanks a lot :)

-Zach
Hello,

I created visualforce that converts the page to PDF..

I have 2 pages, both are using the Same controller (where my image URL is located) and both have the same code except the second 1 is rendered as PDF. The 1st page serves as a Preview before converting it to PDF format.


The PDF format image shows like this one below.

User-added image

Below is how I call the URL from the Controller (which the same way I call it from the preview and it's working)

I have this one from the Controller : imageURL = '/servlet/servlet.ImageServer?id=01555000000fdlO&oid=00D5500000066Iu&lastMod=1445545410000';

Then I call it from the PDF Rendered VF like this.
 
<table style="border: 1px solid white;" width="100%">
                     <tr>
                        <td style="border-color:white" width="80px" >
                            <apex:image url="{!imageURL}" />
                        </td>
                        <td style="border-color:white; text-align:left;" width="70%">
                            <font face="calibri" color="black" size="10"><h2>Traffic Control Form</h2></font>
                        </td>
                    </tr>
                </table>

Not sure where else to look so I decided to ask.

Thank you!

-Zach

 
Hi Experts!

I'm trying to convert list of Account's created date to a specific timeZone. Like PST.

I'm able to convert a single record like below.
 
public class accountTimeZone {
    public account acc{get;set;}
    public String LocalDate{get;set;}
   
    public accountTimeZone(){
        acc = [select createdDate from Account where id = '0019000001JCS1x'];
        LocalDate = acc.createdDate.format('MMMM dd, yyyy hh:mm a','America/New_York');
        System.debug(LocalDate);
    }
}

But how will I go about converting a list of Create Dates like.
 
public class accountTimeZone {

public list<account> AccountDate {get;set;}
public list<DateTime> convertedDate{get;set;}

public accountTimeZone(){

        AccountDate = [select createdDate from account limit 5];
        
    }
}

I'd like to convert these dates then call them in my visualforce page apex table.

Thank you in advance!

-Zach
Hi Experts,

I'm trying to alternately populate the columns in my visualforce page with the Account Records. I'm not sure how to do it though.

Here's my page which returns a simple Table with Rows and Columns.
<apex:page controller="accountController">
  
  <table style="Border:Solid 1px">
      <tr>
          <td style="Border:Solid 1px;background-color:green">
              Column 1
          </td>
          <td style="Border:Solid 1px;background-color:green">
              Column 2
          </td>
          <td style="Border:Solid 1px;background-color:green">
              index
          </td>
      </tr>
      <apex:repeat value="{!wAcc}" var="a">
      <tr>
          <td style="Border:Solid 1px">
              <apex:outputText value="{!a.name}"/>
          </td>
          <td style="Border:Solid 1px">

          </td>
          <td style="Border:Solid 1px">

          </td>
      </tr>
      </apex:repeat>
  </table>
</apex:page>

I have the controller named "accountController" which simply contains a list of Accounts.

When I call this in visualforce, it will only return the table below. What I would like to do is to have the first record in the list to go to the 1st column of first row, then the second record go to the second column of first row, then 3rd record goes to the 1st column in the second row and so on. How do I go about it?

User-added image

Thanks in advance :)







 
Hi Experts,

I'm trying to learn VisualForce and it seems that I'm stuck with using Collection.

I have <apex:inputField> and <apex:commandButton>, what I want to do is add the value I type in the inputField when I click the commandButton.

Can anyone please give me an Idea of the correct syntax?

Here's the code I created so far that is not working as expected.
<apex:page controller="MultiAccountInsertController" sidebar="false">
  
  <apex:pageBlock title="Enter Account Name">
      <apex:form >
          <apex:inputText value="{!acc.name}"/>
          <apex:commandButton value="Add Account" action="{!addAccount}"/>
      </apex:form>
  </apex:pageBlock>  
  
  <apex:pageBlock title="List of Accounts to Save">
  	To be continued...
  </apex:pageBlock>
</apex:page>
CLASS
 
public class MultiAccountInsertController {
    
    Public account acc{get;set;}
    List<account> AccountList; 

    public MultiAccountInsertController(){
        acc = new account();
        AccountList = new List<account>();
    }
    public void addAccount(){
		AccountList.add(acc);
        
        //Check value of the AccountList in Debug
        for(integer i=0;i<AccountList.size();i++){
           system.debug(AccountList[i].name); 
        }
    }
    public List<account> getViewAccounts(){
        return AccountList;
    }
}

When I run Click the button, the result goes like below.

09:41:52:039 USER_DEBUG [13]|DEBUG|A
09:41:52:039 USER_DEBUG [13]|DEBUG|B

The result I want should look like below because I typed "A" first then pressed the button, then Typed B then pressed the button. So Everytime I type value in the Text Field, I want to add it as a value in my List.

09:41:52:039 USER_DEBUG [13]|DEBUG|A
09:41:52:039 USER_DEBUG [13]|DEBUG|B

NOTE: I'm using Account for testing, when I have this working, I'll try to work on inserting the Records from the List of Accounts (But don't answer this part coz I want to figure it our my self first :D )

Thanks for the help!