• fourfourfun
  • NEWBIE
  • 70 Points
  • Member since 2013

  • Chatter
    Feed
  • 2
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 21
    Questions
  • 43
    Replies
Hi,

I'm looking to display a table in the home page for one subset of users, I'd like it to display a list of activities (these are stored in a custom object) they did last week. 

Does anyone have a nice guide or a blog which might point me in the right direction to help me make this? I'm assuming it would be rather straightforward. Doesn't necessarily have to be a table of results, if anyone has any other ideas with a bit of flair, I'm more than open to some solutions.

Trying to do a simple swap to replace an SOQL statement in my Apex with something that is generated from a string.

Here is what I'm looking at:

String AccountSOQLString = 'Select ownerid from account where ownerid=:search.ownerid'
//		List<Account> ownerAccs = Database.query(AccountSOQLString);

The above does not work.

		List<Account> ownerAccs = [Select ownerid from account where ownerid=:search.ownerid];

This does work.

The aim is to eventually have the string built up with a series of IF statements (which in itself is another sticking point it seems).

I'll start with the current sticking point though, any help?


Trying to alter some SOQL in my environment to filter on Account Owner rather than Contact Owner. Now I'm used to SQL and find SOQL maddening as I am not fully to grips with the syntax to do things I would find matter of fact in SQL. Here is what I have:

allcontacts=[select id, firstname, lastname, speciality__c, account.name, pcm_contact_type__c, account.ownerid, account.shippingpostalcode, account.target_account__c 
                           from contact 
                           where
                           Id not in (select contact__c from PCM_Activity_Attendee__c where PCM_Activity__c=:stdCtrl.getId())
                           and firstname like :'%' + search.firstname + '%'
                           and lastname like :'%' + search.lastname + '%'
                           and (pcm_contact_type__c like :search.pcm_contact_type__c+ '%' )
                           and account.name like :'%' + search.department + '%'           
                           and account.shippingpostalcode like :'%' + search.MailingPostalCode + '%'
                           and account.ownerid not in (select account.ownerid from account where account.ownerid=:search.profession__c)
                           and Account.RecordTypeId = '01230000000Y77V'
                           order by account.name asc, lastname, firstname
                           limit 50];
It is the bolded line that is the issue. 

If anyone can point out the logic to me so I can learn from this, that would be great!

Is there a way of doing this? I've got a controller that has some features that are taking AGES to run now. Would be nice to see how / why it is getting hung up.

Got some stuff where buttons add/delete contacts to a record but for some reason they are taking ages to do so.
Just curious. I just slapped in a clause in validation to bypass all the rules, essentialy to let bulk data updates by system admins to change records whether or not there are rules there.

How would this apply for Apex triggers? What would they run as? The code creator? I'd love to put a piece of code into Salesforce but I don't want to get spammed by errors when I do bulk updates that trigger it.
I would LOVE to pilfer the knowledge spelt out in this thread below:

https://developer.salesforce.com/forums/ForumsMain?id=906F000000093fwIAA

but the last known state was the OP posting "oh I found a way to fix it" without actually stating what it was. Anyone reckon they can help pick up the loose end for me.

Essentially, this is his code:

trigger Changeownertrigger on Account (after insert,after update) {
      Set<Id> accountIds = new Set<Id>();
      Map<Id, String> oldOwnerIds = new Map<Id, String>();
      Map<Id, String> newOwnerIds = new Map<Id, String>();
      Contact[] contactUpdates = new Contact[0];
      for (Account a : Trigger.new)
      {
         if (a.OwnerId != Trigger.oldMap.get(a.Id).OwnerId)
         {
            oldOwnerIds.put(a.Id, Trigger.oldMap.get(a.Id).OwnerId);
            newOwnerIds.put(a.Id, a.OwnerId);
            accountIds.add(a.Id);
         }
      }
        if (!accountIds.isEmpty()) {
         for (Account acc : [SELECT Id, (SELECT Id, OwnerId FROM Contacts) FROM Account WHERE Id in :accountIds])
            {
            String newOwnerId = newOwnerIds.get(act.Id);
            String oldOwnerId = oldOwnerIds.get(act.Id);
            for (Contact c : acc.Contacts)
            {
               if (c.OwnerId == oldOwnerId)
               {
               Contact updatedContact = new Contact(Id = c.Id, OwnerId = newOwnerId);
               contactUpdates.add(updatedContact);
               }
            }
            }
       }
            update contactUpdates;
}
With a final comment of:

I was able to figure out the solution.My trigger was skipping the if condition.

If(c.owner.Id ==oldOwnerid)

Soo changed that ...It works fine now...
Apologies for asking something that is probably simple but I'm yet to plod off on my Apex courses!
Seen a few people post about Saved Locally But Not To Server but nothing that has helped me resolve this issue.

I am trying to save to production some edits to a VF page. Forcing a save, changing the build options, syncronise has greyed out options. Nothing lets me save.

Is it impossible to save VF pages to production? I would have assumed that it would be the case with Apex but not these.
Trying to poll some opinion here. Got a standard VF page that I am quickly trying to uplift to be decent on Salesforce1. This document looks promising:

http://www.salesforce.com/us/developer/docs/salesforce1/Content/vf_dev_best_practices_approaches_mixed.htm

Now. It goes to great lengths to say what not to use in terms of pageBlock and pageBlockSection (which I have in my code that was inhereted), but what on earth are you meant to use in its stead? <div> etc?

For someone who isn't really an HTML head, it would be nice to have a little leg up.

Hi,

 

Got two objects. When saving on one, a trigger creates a bunch on the other referecing back with a lookup. When I delete from the former, I want it to delete everything that it created when saving.

 

This is what I have so far:

 

trigger CleanRelatedPCMActivities on Week__c (before delete) 

{
set<id> setActIds = Trigger.newmap.keySet();
 
//query for related Activities
 
list<PCM_Time_Record__c> ActivityRecords = [select Id from PCM_Time_Record__c where Weekly_Time__c in:setActIds];
if(ActivityRecords.size() > 0)
delete ActivityRecords;
}

Theory sounds good. Before deleting, set the ID of what you are deleting. Then query in the other object to find what it is related to, deleting whatever is found.

 

This is giving me this error though:

 

execution of BeforeDelete caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.CleanRelatedPCMActivities: line 4, column 1"

 

Anyone got a pointer on where I may have gone wrong?

Got a Q about Salesforce 1 - one of the things I really want to roll out to the users is a streamlined mobile version of their processes. One of these involves a Visualforce page that was developed for us.

Navigating to this on the mobile displays the page more in line with desktop Salesforce (i.e not really designed for form factor, no nice calendar pop up, very much not for mobile). How can I get in and start changing things to look different on mobile?

Hi,

 

Am in the unenviable position of trying to edit someone elses code. They have made a Save and Exit controller that saves on a Visualforce page and exits to the custom object list screen.

 

What I want to do is create a couple of variants.

 

1) Save & New

2) Save and display saved record

 

This is what I have so far

 

public pagereference mySave()
    {
        pcmAct = (PCM_Time_Record__c)stdCtrl.getRecord();
        if(pcmAct.type__c == '121 Call')
        {
            for(PCM_Activity_Attendee__c a:attendees)
            {
                a.one_to_one__c = true;
            }
            
        }
        update attendees;
        pagereference savepage = stdCtrl.save();
        return savepage;
    
    }

 What can I do to amend this?

Hi,

 

I'm considering moving from Talend to SSIS. Talend is obviously free to use, but the rest of the company uses SSIS, so it would be great to move across to that.

 

Has anyone got any experience of the various SSIS third party vendors out there?

 

I noted they can vary wildly in price, from cheap to very expensive solutions.

 

Essentially, all I would be doing is pulling from text file or SQL source, mapping (and in some instances, using the result of a map to do some further mapping) and then insert/upsert/update to salesforce. Plus maybe looking at going from Salesforce to SQL.

 

I found this:

 

http://www.devart.com/dotconnect/salesforce/ssis.html

 

but my limited knowledge of SSIS isn't telling me if this will cover my needs. So going to you, the experts, for a bit of advice!

 

Thanks,

Hi, 

 

I have an established piece of code. What it is doing is writing, on save, from one record (week__c) in an object, and creating/updating a series of records in another one (PCM_Time_Record__c).

 

The only bugbear is that it is writing the other records as whoever is triggering the Apex. I need it to assign the written records as the owner of the source.

 

The code looks like this:

 

 List<PCM_Time_Record__c> insertBlocks = new List<PCM_Time_Record__c>
     {new PCM_Time_Record__c(Time_Block_Name__c='Monday AM1', Type__c=week.Monday_AM1__c,      Date__c=week.Week_Commencing__c, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),

 

As you can see, it is doing a simple create.

 

 

I assumed it was as simple as adding another clause to the bracket that said OwnerID = week__c.OwnerID, but that is throwing up an "Expect ID error".

 

 

 

Here is the full trigger in case anyone needs it:

 

 

trigger createTimeBlocks on Week__c (after insert, after update) {
   
    //hours in the day, split into quarters
    decimal hours = 7.5/4;
    String recordTypeId = [Select Id from RecordType where Name = 'Time Block' and SobjectType = 'PCM_Time_Record__c' limit 1].id;
    PCM_Time_Record__c timeBlock;
        
    for (Week__c week : Trigger.new)
    {
     //For each week record being saved
     if(Trigger.isUpdate)
     {
        //If the Week record has been saved previously, then check for existing timeBlocks. These should also exist.
        List<PCM_Time_Record__c> timeBlocks = [select id from PCM_Time_Record__c where Weekly_Time__c = :week.Id];
        if(!timeBlocks.isEmpty())
        {
            delete timeBlocks;
        }   

     }
     //Create timeblocks.
     List<PCM_Time_Record__c> insertBlocks = new List<PCM_Time_Record__c>
        {new PCM_Time_Record__c(Time_Block_Name__c='Monday AM1', Type__c=week.Monday_AM1__c, Date__c=week.Week_Commencing__c, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Monday AM2', Type__c=week.Monday_AM2__c, Date__c=week.Week_Commencing__c, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Monday PM1', Type__c=week.Monday_AM2__c, Date__c=week.Week_Commencing__c, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Monday PM2', Type__c=week.Monday_AM2__c, Date__c=week.Week_Commencing__c, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Tuesday AM1', Type__c=week.Tuesday_AM1__c, Date__c=week.Week_Commencing__c+1, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Tuesday AM2', Type__c=week.Tuesday_AM2__c, Date__c=week.Week_Commencing__c+1, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Tuesday PM1', Type__c=week.Tuesday_PM1__c, Date__c=week.Week_Commencing__c+1, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Tuesday PM2', Type__c=week.Tuesday_PM2__c, Date__c=week.Week_Commencing__c+1, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Wednesday AM1', Type__c=week.Wednesday_AM1__c, Date__c=week.Week_Commencing__c+2, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Wednesday AM2', Type__c=week.Wednesday_AM2__c, Date__c=week.Week_Commencing__c+2, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Wednesday PM1', Type__c=week.Wednesday_PM1__c, Date__c=week.Week_Commencing__c+2, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Wednesday PM2', Type__c=week.Wednesday_PM2__c, Date__c=week.Week_Commencing__c+2, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Thursday AM1', Type__c=week.Thursday_AM1__c, Date__c=week.Week_Commencing__c+3, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Thursday AM2', Type__c=week.Thursday_AM2__c, Date__c=week.Week_Commencing__c+3, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Thursday PM1', Type__c=week.Thursday_PM1__c, Date__c=week.Week_Commencing__c+3, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Thursday PM2', Type__c=week.Thursday_PM2__c, Date__c=week.Week_Commencing__c+3, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Friday AM1', Type__c=week.Friday_AM1__c, Date__c=week.Week_Commencing__c+4, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Friday AM2', Type__c=week.Friday_AM2__c, Date__c=week.Week_Commencing__c+4, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Friday PM1', Type__c=week.Friday_PM1__c, Date__c=week.Week_Commencing__c+4, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Friday PM2', Type__c=week.Friday_PM2__c, Date__c=week.Week_Commencing__c+4, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Saturday AM1', Type__c=week.Saturday_AM1__c, Date__c=week.Week_Commencing__c+5, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Saturday AM2', Type__c=week.Saturday_AM2__c, Date__c=week.Week_Commencing__c+5, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Saturday PM1', Type__c=week.Saturday_PM1__c, Date__c=week.Week_Commencing__c+5, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Saturday PM2', Type__c=week.Saturday_PM2__c, Date__c=week.Week_Commencing__c+5, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Sunday AM1', Type__c=week.Sunday_AM2__c, Date__c=week.Week_Commencing__c+6, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Sunday AM2', Type__c=week.Sunday_AM2__c, Date__c=week.Week_Commencing__c+6, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Sunday PM1', Type__c=week.Sunday_AM2__c, Date__c=week.Week_Commencing__c+6, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),  
         new PCM_Time_Record__c(Time_Block_Name__c='Sunday PM2', Type__c=week.Sunday_PM2__c, Date__c=week.Week_Commencing__c+6, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25)
        };
     insert insertBlocks;
    }
}

 

 

Thanks for any help!

I have a visualforce page.

 

It has four buttons on it:

 

Save

Close

 

and in a section which has a few free text fields

 

Search 

Clear

 

Essentially it is a custom designed search function which adds contacts to a record based on the parameters placed in the free text fields.

 

The issue is, you need to press the search button to search. The natural thing to do is to enter your search term and press enter. This is either closing or saving the record. Once the user presses back to get back to the search screen, it actually causes a new record to be saved when they complete. The result being that lots of empty records get created.

 

Of course user education is one thing, but is there a way to make the focus shift from Save or Close down to Search?

 

Thanks,

Been amending a piece of code on here to suit my needs but it won't compile. My naieve eyes cannot see the error of my ways:

 

trigger doRollup on Time_Record__c (after insert, after update, after delete, after undelete) {

  // List of parent record ids to update
    Set<Id> parentIds = new Set<Id>();
  
  // In-memory copy of parent records
  Map<Id,Time_Record__c> parentRecords = new Map<Id,Time_Record__c>();
  
  // Gather the list of ID values to query on
  for(Daily_Time_Record__c c:Trigger.isDelete?Trigger.old:Trigger.new)
    parentIds.add(c.Time_Record_Link__c);
    
  // Avoid null ID values
  parentIds.remove(null);
  
  // Create in-memory copy of parents
  for(Id parentId:parentIds)
    parentRecords.put(parentId,new Time_Record__c(Id=parentId,RollupTarget__c=0));
    
  // Query all children for all parents, update Rollup Field value
  for(Daily_Time_Record__c c:[select id,FieldToRoll__c,Time_Record_Link__c from Daily_Time_Record__c where id in :parentIds])
    parentRecords.get(c.Time_Record_Link__c).RollupTarget__c += c.FieldToRoll__c;
    
  // Commit changes to the database
  
  Database.update(parentRecords.values());
}

Where:

 

Time_Record__c is my parent

RollUpTarget__c is the place I am trying to roll to

Daily_Time_Record__c is the child

Time_Record_Link__c is the link to parent that exists on the child

FieldToRoll__c is a test field to roll up on the child

 

I *think* that is what I had to replace from this generic template:

 

trigger doRollup on Child__c (after insert, after update, after delete, after undelete) {
  // List of parent record ids to update
  Set<Id> parentIds = new Set<Id>();
  // In-memory copy of parent records
  Map<Id,Parent__c> parentRecords = new Map<Id,Parent__c>();
  // Gather the list of ID values to query on
  for(Child__c c:Trigger.isDelete?Trigger.old:Trigger.new)
    parentIds.add(c.ParentField__c);
  // Avoid null ID values
  parentIds.remove(null);
  // Create in-memory copy of parents
  for(Id parentId:parentIds)
    parentRecords.put(parentId,new Parent__c(Id=parentId,RollupField__c=0));
  // Query all children for all parents, update Rollup Field value
  for(Child__c c:[select id,Amount__c,ParentField__c from Child__c where id in :parentIds])
    parentRecords.get(c.ParentField__c).RollupField__c += c.Amount__c;
  // Commit changes to the database
  Database.update(parentRecords.values());
}

 Ideally I want to roll up a sum of 7 fields from the child (hence needing this solution), but starting small.

 

 

Hi,

 

Without the ability to have lookup fields in the User profile or Workflows, I'm looking to try and Apex solution to my problem.

 

I would have a field on the User's profile called:

 

Region

 

I will also have an object which will have a lookup that will contain:

 

A user on the system

A region (which is a lookup field itself)

 

Using that user as the relationship, I want to pull off what Region they are and populate that field on the User profile.

 

Is this something that is relatively easy to achieve?

 

 

Hi. I have a VFpage which mimics the layout of an object in my org. The intention is to have a custom Add and Save button on the create/edit screen.

 

The VFpage is as follows:

<apex:page standardController="Call__c" extensions="TimesheetFindSOQL">
<apex:sectionHeader title="Call__c Edit" subtitle="{!Call__c.name}"/> 
<apex:form > 
<apex:pageBlock title="Call__c Edit" mode="edit">

<!--buttons for the VFpage at the top-->

<apex:pageBlockButtons location="top">
<apex:commandButton value="Save" action="{!save}"/> 
<apex:commandButton value="Save & New" action="{!save}" /> 
<apex:commandButton value="Cancel" action="{!cancel}"/> 
</apex:pageBlockButtons>

<!--buttons for the VFpage at the bottom-->

<apex:pageBlockButtons location="bottom"> 
<apex:commandButton value="Save" action="{!save}"/> 
<apex:commandButton value="Save & New" action="{!save}" /> 
<apex:commandButton value="Cancel" action="{!cancel}"/> 
</apex:pageBlockButtons>

<!--Fields from Call object with mandatory/non-mandatory flag indicators-->

<apex:pageBlockSection title="Information" columns="2"> 
<apex:inputField value="{!Call__c.Account__c}" required="true"/> 
<apex:inputField value="{!Call__c.Timesheet__c}" required="true"/>
<apex:inputField value="{!Call__c.Contact__c}" required="false"/> 
<apex:inputField value="{!Call__c.RecordTypeId}" required="false"/> 
<apex:inputField value="{!Call__c.Call_Date__c}" required="false"/> 
<apex:inputField value="{!Call__c.Call_Category__c}" required="false"/> 
<apex:inputField value="{!Call__c.Call_Notes__c}" required="false"/> 

</apex:pageBlockSection>

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

Tthe aim here is to populate 

 

<apex:inputField value="{!Call__c.Timesheet__c}" required="true"/>

with the result of some SoQL.

 

I have a class, but my issue is what on earth to do with these two entities:

 

public with sharing class TimesheetFindSOQL {

    public TimesheetFindSOQL(ApexPages.StandardController controller) {

    }

//instance variable
public Timesheet__c record {get; set;}

//class constructor
public TimesheetFindSOQL() {
  List<Timesheet__c> records = [Select Id, Name From Timesheet__c WHERE Week_Beginning__c = 2013-03-25];
  if(!records.isEmpty()) {
    record = records.get(0);
        }
    record = records.get(1);

    }
}

 Where do I go from this point?

 

Hi all,

 

Working through this fantastically useful guide here:

 

http://blog.jeffdouglas.com/2011/08/12/roll-your-own-salesforce-lookup-popup-window/

 

Except it is a little too light in places for someone of my skill level. At the moment trying to replicate the example before diving into customising.

 

I'm getting that this is the section of the 4 pieces of code where I have to start bespoking:

 

https://github.com/jeffdonthemic/Blog-Sample-Code/blob/master/salesforce/src/classes/CustomAccountLookupController.cls

      // Following is the url of Custom Lookup page. You need to change that accordingly
      baseURL = "/apex/CustomAccountLookup?txt=" + txtId;
      
      // Following is the id of apex:form control "myForm". You need to change that accordingly
      baseURL = baseURL + "&frm=" + escapeUTF("{!$Component.myForm}");
      if (modified == '1') {
        baseURL = baseURL + "&lksearch=" + searchParam;
      }
      
      // Following is the ID of inputField that is the lookup to be customized as custom lookup
      if(txtId.indexOf('Account') > -1 ){
        isCustomLookup = true;

 The top bit I have done:

 

      // Following is the url of Custom Lookup page. You need to change that accordingly
      baseURL = "/apex/CustomAccountLookup?txt=" + "066V0000000D4vc"; 
      //latter is the bespoke Salesforce ID for the CustomLookupPage - like URL hacking

 But this:

 

      // Following is the id of apex:form control "myForm". You need to change that accordingly
      baseURL = baseURL + "&frm=" + escapeUTF("{!$Component.myForm}");
      if (modified == '1') {
        baseURL = baseURL + "&lksearch=" + searchParam;
      }

 I'm not sure what I am meant to be sticking in here.

 

Assuming the third part of this is where I put the ID of the lookup field I have created on the contact screen.

 

Thanks for any help on this.

Got a bizarre concept that I wondered if it can actually be done.

 

Usually in the case of a lookup, you would create a record, save it and have the "Add New X" button appear in a related list down the bottom.

 

Is it possible to do this BACKWARDS?

 

So I go to create an item and it (invisibly) creates the record it would be related to and relates it?

 

It sounds like a ham fisted way of doing things but it may solve a problem I am facing. If anyone wants a break down of the problem to see if I am doing things in a crazy fashion, let me know.

Hopefully a relatively simple trigger.

 

I have a related list on a custom object. There is a certain Record Type that I want the user to only be able to create ONE entry/relationship with. If they try to create two entries, I want to pop an error with some information for the user.

Hi,

I'm looking to display a table in the home page for one subset of users, I'd like it to display a list of activities (these are stored in a custom object) they did last week. 

Does anyone have a nice guide or a blog which might point me in the right direction to help me make this? I'm assuming it would be rather straightforward. Doesn't necessarily have to be a table of results, if anyone has any other ideas with a bit of flair, I'm more than open to some solutions.

Trying to do a simple swap to replace an SOQL statement in my Apex with something that is generated from a string.

Here is what I'm looking at:

String AccountSOQLString = 'Select ownerid from account where ownerid=:search.ownerid'
//		List<Account> ownerAccs = Database.query(AccountSOQLString);

The above does not work.

		List<Account> ownerAccs = [Select ownerid from account where ownerid=:search.ownerid];

This does work.

The aim is to eventually have the string built up with a series of IF statements (which in itself is another sticking point it seems).

I'll start with the current sticking point though, any help?


Trying to alter some SOQL in my environment to filter on Account Owner rather than Contact Owner. Now I'm used to SQL and find SOQL maddening as I am not fully to grips with the syntax to do things I would find matter of fact in SQL. Here is what I have:

allcontacts=[select id, firstname, lastname, speciality__c, account.name, pcm_contact_type__c, account.ownerid, account.shippingpostalcode, account.target_account__c 
                           from contact 
                           where
                           Id not in (select contact__c from PCM_Activity_Attendee__c where PCM_Activity__c=:stdCtrl.getId())
                           and firstname like :'%' + search.firstname + '%'
                           and lastname like :'%' + search.lastname + '%'
                           and (pcm_contact_type__c like :search.pcm_contact_type__c+ '%' )
                           and account.name like :'%' + search.department + '%'           
                           and account.shippingpostalcode like :'%' + search.MailingPostalCode + '%'
                           and account.ownerid not in (select account.ownerid from account where account.ownerid=:search.profession__c)
                           and Account.RecordTypeId = '01230000000Y77V'
                           order by account.name asc, lastname, firstname
                           limit 50];
It is the bolded line that is the issue. 

If anyone can point out the logic to me so I can learn from this, that would be great!

Under setup --> Develop --> Appex Classes there is no "New" button please see the image below.
User-added image

I have clicked on developer console then in developer console window File --> New --> Appex Class
Give the new class name but when click on create button get the following error.

User-added image

Please help me how can i fix this so that i can create my custom controller class.
Thanks in advance.
Is there a way of doing this? I've got a controller that has some features that are taking AGES to run now. Would be nice to see how / why it is getting hung up.

Got some stuff where buttons add/delete contacts to a record but for some reason they are taking ages to do so.
Just curious. I just slapped in a clause in validation to bypass all the rules, essentialy to let bulk data updates by system admins to change records whether or not there are rules there.

How would this apply for Apex triggers? What would they run as? The code creator? I'd love to put a piece of code into Salesforce but I don't want to get spammed by errors when I do bulk updates that trigger it.
Trying to poll some opinion here. Got a standard VF page that I am quickly trying to uplift to be decent on Salesforce1. This document looks promising:

http://www.salesforce.com/us/developer/docs/salesforce1/Content/vf_dev_best_practices_approaches_mixed.htm

Now. It goes to great lengths to say what not to use in terms of pageBlock and pageBlockSection (which I have in my code that was inhereted), but what on earth are you meant to use in its stead? <div> etc?

For someone who isn't really an HTML head, it would be nice to have a little leg up.

Hi,

 

Got two objects. When saving on one, a trigger creates a bunch on the other referecing back with a lookup. When I delete from the former, I want it to delete everything that it created when saving.

 

This is what I have so far:

 

trigger CleanRelatedPCMActivities on Week__c (before delete) 

{
set<id> setActIds = Trigger.newmap.keySet();
 
//query for related Activities
 
list<PCM_Time_Record__c> ActivityRecords = [select Id from PCM_Time_Record__c where Weekly_Time__c in:setActIds];
if(ActivityRecords.size() > 0)
delete ActivityRecords;
}

Theory sounds good. Before deleting, set the ID of what you are deleting. Then query in the other object to find what it is related to, deleting whatever is found.

 

This is giving me this error though:

 

execution of BeforeDelete caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.CleanRelatedPCMActivities: line 4, column 1"

 

Anyone got a pointer on where I may have gone wrong?

Got a Q about Salesforce 1 - one of the things I really want to roll out to the users is a streamlined mobile version of their processes. One of these involves a Visualforce page that was developed for us.

Navigating to this on the mobile displays the page more in line with desktop Salesforce (i.e not really designed for form factor, no nice calendar pop up, very much not for mobile). How can I get in and start changing things to look different on mobile?

Hi, 

 

I have an established piece of code. What it is doing is writing, on save, from one record (week__c) in an object, and creating/updating a series of records in another one (PCM_Time_Record__c).

 

The only bugbear is that it is writing the other records as whoever is triggering the Apex. I need it to assign the written records as the owner of the source.

 

The code looks like this:

 

 List<PCM_Time_Record__c> insertBlocks = new List<PCM_Time_Record__c>
     {new PCM_Time_Record__c(Time_Block_Name__c='Monday AM1', Type__c=week.Monday_AM1__c,      Date__c=week.Week_Commencing__c, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),

 

As you can see, it is doing a simple create.

 

 

I assumed it was as simple as adding another clause to the bracket that said OwnerID = week__c.OwnerID, but that is throwing up an "Expect ID error".

 

 

 

Here is the full trigger in case anyone needs it:

 

 

trigger createTimeBlocks on Week__c (after insert, after update) {
   
    //hours in the day, split into quarters
    decimal hours = 7.5/4;
    String recordTypeId = [Select Id from RecordType where Name = 'Time Block' and SobjectType = 'PCM_Time_Record__c' limit 1].id;
    PCM_Time_Record__c timeBlock;
        
    for (Week__c week : Trigger.new)
    {
     //For each week record being saved
     if(Trigger.isUpdate)
     {
        //If the Week record has been saved previously, then check for existing timeBlocks. These should also exist.
        List<PCM_Time_Record__c> timeBlocks = [select id from PCM_Time_Record__c where Weekly_Time__c = :week.Id];
        if(!timeBlocks.isEmpty())
        {
            delete timeBlocks;
        }   

     }
     //Create timeblocks.
     List<PCM_Time_Record__c> insertBlocks = new List<PCM_Time_Record__c>
        {new PCM_Time_Record__c(Time_Block_Name__c='Monday AM1', Type__c=week.Monday_AM1__c, Date__c=week.Week_Commencing__c, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Monday AM2', Type__c=week.Monday_AM2__c, Date__c=week.Week_Commencing__c, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Monday PM1', Type__c=week.Monday_AM2__c, Date__c=week.Week_Commencing__c, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Monday PM2', Type__c=week.Monday_AM2__c, Date__c=week.Week_Commencing__c, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Tuesday AM1', Type__c=week.Tuesday_AM1__c, Date__c=week.Week_Commencing__c+1, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Tuesday AM2', Type__c=week.Tuesday_AM2__c, Date__c=week.Week_Commencing__c+1, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Tuesday PM1', Type__c=week.Tuesday_PM1__c, Date__c=week.Week_Commencing__c+1, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Tuesday PM2', Type__c=week.Tuesday_PM2__c, Date__c=week.Week_Commencing__c+1, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Wednesday AM1', Type__c=week.Wednesday_AM1__c, Date__c=week.Week_Commencing__c+2, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Wednesday AM2', Type__c=week.Wednesday_AM2__c, Date__c=week.Week_Commencing__c+2, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Wednesday PM1', Type__c=week.Wednesday_PM1__c, Date__c=week.Week_Commencing__c+2, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Wednesday PM2', Type__c=week.Wednesday_PM2__c, Date__c=week.Week_Commencing__c+2, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Thursday AM1', Type__c=week.Thursday_AM1__c, Date__c=week.Week_Commencing__c+3, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Thursday AM2', Type__c=week.Thursday_AM2__c, Date__c=week.Week_Commencing__c+3, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Thursday PM1', Type__c=week.Thursday_PM1__c, Date__c=week.Week_Commencing__c+3, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Thursday PM2', Type__c=week.Thursday_PM2__c, Date__c=week.Week_Commencing__c+3, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Friday AM1', Type__c=week.Friday_AM1__c, Date__c=week.Week_Commencing__c+4, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Friday AM2', Type__c=week.Friday_AM2__c, Date__c=week.Week_Commencing__c+4, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Friday PM1', Type__c=week.Friday_PM1__c, Date__c=week.Week_Commencing__c+4, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Friday PM2', Type__c=week.Friday_PM2__c, Date__c=week.Week_Commencing__c+4, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Saturday AM1', Type__c=week.Saturday_AM1__c, Date__c=week.Week_Commencing__c+5, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Saturday AM2', Type__c=week.Saturday_AM2__c, Date__c=week.Week_Commencing__c+5, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Saturday PM1', Type__c=week.Saturday_PM1__c, Date__c=week.Week_Commencing__c+5, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Saturday PM2', Type__c=week.Saturday_PM2__c, Date__c=week.Week_Commencing__c+5, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Sunday AM1', Type__c=week.Sunday_AM2__c, Date__c=week.Week_Commencing__c+6, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Sunday AM2', Type__c=week.Sunday_AM2__c, Date__c=week.Week_Commencing__c+6, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),
         new PCM_Time_Record__c(Time_Block_Name__c='Sunday PM1', Type__c=week.Sunday_AM2__c, Date__c=week.Week_Commencing__c+6, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25),  
         new PCM_Time_Record__c(Time_Block_Name__c='Sunday PM2', Type__c=week.Sunday_PM2__c, Date__c=week.Week_Commencing__c+6, Weekly_Time__c = week.Id,RecordTypeId=recordTypeId, Duration_hours__c=hours, Proportion_Of_Day__c=0.25)
        };
     insert insertBlocks;
    }
}

 

 

Thanks for any help!

I have a visualforce page.

 

It has four buttons on it:

 

Save

Close

 

and in a section which has a few free text fields

 

Search 

Clear

 

Essentially it is a custom designed search function which adds contacts to a record based on the parameters placed in the free text fields.

 

The issue is, you need to press the search button to search. The natural thing to do is to enter your search term and press enter. This is either closing or saving the record. Once the user presses back to get back to the search screen, it actually causes a new record to be saved when they complete. The result being that lots of empty records get created.

 

Of course user education is one thing, but is there a way to make the focus shift from Save or Close down to Search?

 

Thanks,

Hi..

 

I need a trigger which will work anytime the Account Owner changes, update all Account Contacts to that same Owner as their related Account.

 

So I created a trigger..Which doesn't work..To test it i created a account with two contacts .So i get contact owner same as account owner.i manually changed one contact owner to another user

So my account owner ,contact1 owner are user1 and contact 2 owner is user2

 

and changed the account owner/Out of two,only one contac whose owner id is same as account changes and other doesnt.

This is my trigger ..Please help me where i am going wrong.

 

 

trigger Changeownertrigger on Account (after insert,after update) {
  
      Set<Id> accountIds = new Set<Id>(); 
      Map<Id, String> oldOwnerIds = new Map<Id, String>();
      Map<Id, String> newOwnerIds = new Map<Id, String>();
      Contact[] contactUpdates = new Contact[0]; 
     
      for (Account a : Trigger.new) 
      { 
         if (a.OwnerId != Trigger.oldMap.get(a.Id).OwnerId) 
         {
            oldOwnerIds.put(a.Id, Trigger.oldMap.get(a.Id).OwnerId); 
            newOwnerIds.put(a.Id, a.OwnerId); 
            accountIds.add(a.Id); 
         }
      }
        if (!accountIds.isEmpty()) { 
         for (Account acc : [SELECT Id, (SELECT Id, OwnerId FROM Contacts) FROM Account WHERE Id in :accountIds])
            {
            String newOwnerId = newOwnerIds.get(act.Id); 
            String oldOwnerId = oldOwnerIds.get(act.Id); 
            for (Contact c : acc.Contacts) 
            { 
               if (c.OwnerId == oldOwnerId) 
               {
               Contact updatedContact = new Contact(Id = c.Id, OwnerId = newOwnerId);
               contactUpdates.add(updatedContact);
               }
            }
            
            }
       }
            update contactUpdates;
}

 Pease help i need this asap...