• ECL47
  • NEWBIE
  • 5 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 2
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 2
    Replies
A trigger created by the previous admin is not working correctly - it works sometimes but not always, and I can't figure out any pattern.

The trigger is meant to allow salespeople to take over old contacts by adding a task to the contact record. If the contact hasn't had any activity in a year and the salesperson has the right user role, the contact is supposed to change to Active and ownership should change to the new salesperson.

I know almost nothing about Apex and am still learning Salesforce, so any help would be appreciated. This is the code:

    trigger Task_After_Update on Task (after update) {
//Update Contact Fields: Last Activity Trigger, Contact Owner
Set<Id> cIds = new Set<Id>();
 for(Task t: [SELECT Subject,WhoId,Status,OwnerId,Owner_role__c,Made_Contact__c FROM TASK WHERE ID IN:trigger.new]){
   String wId = t.WhoId;
   Task oldTask = Trigger.oldMap.get(t.ID);
   if( oldTask.Made_Contact__c !='Yes' && wId!=null && !cIds.contains(t.WhoId) && t.Status == 'Completed' && t.Made_Contact__c == 'Yes' && t.owner_role__c.Contains('Broker')){
   cIds.add(t.WhoId);
    for(Contact c:[SELECT ownerid, type__c, Last_Activity_Trigger__c  FROM Contact WHERE ( type__c = 'Active' AND ID IN:cIds) ]){
        if( c.ownerid == t.ownerid ){
                 c.Last_Activity_Trigger__c=System.now();
                 c.Last_Activity_Completed_By__c=t.ownerid;}
        if( c.ownerid != t.ownerid ){
                 c.Last_Activity_Completed_By__c=t.ownerid;}         
        update c;
    }
    for(Contact c:[SELECT ownerid, type__c, Last_Activity_Trigger__c  FROM Contact WHERE ( type__c != 'Active' AND ID IN:cIds) ]){
        if( c.ownerid == t.ownerid ){
                 c.Last_Activity_Trigger__c=System.now();
                 c.Last_Activity_Completed_By__c=t.ownerid;}
        if( c.ownerid != t.ownerid ){
                 c.Last_Activity_Trigger__c=System.now();
                 c.Last_Activity_Completed_By__c=t.ownerid;
                 c.ownerid=t.ownerid;}
        update c;
    }
   }
 }  
}

 
  • February 20, 2015
  • Like
  • 0
We are using the Activity Manager app by VersatileCapitalist to mass create tasks.

We have buttons to mass create tasks on the contact views (where whoid=contact id), and on a custom Property object (pba__Property__c)  views (where whatid=property id) - Both buttons are below.

On the Property object, we have a contact lookup field for the Property Owner (PropertyOwner__c). We would like to be able to mass create tasks from the Property view with the whoid=PropertyOwner__c.  The app has all of the functionality that we need, I am not sure how to pull/set the contact ids from the property view.

I am pretty new to code, so any help would be appreciated.

Custom Contact Button
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
var records = {!GETRECORDIDS( $ObjectType.Contact)};
var returnURL = window.location.href;
if(records != null && records != ''){
mywin = window.open('/apex/activities__createTasks?Ids='+records+'&retURL='+returnURL+'&type=whoid' , '_top',
'height=400,width=600,status=yes,toolbar=no,menubar=no,location=no,center=yes,resizable=no');
mywin.focus();
}else{
alert('Please select atleast one record.');
}

Custom Property Button
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
var records = {!GETRECORDIDS( $ObjectType.pba__Property__c)};
var returnURL = window.location.href;
if(records != null && records != ''){
mywin = window.open('/apex/activities__createTasks?Ids='+records+'&retURL='+returnURL+'&type=whatId' , '_top',
'height=400,width=600,status=yes,toolbar=no,menubar=no,location=no,center=yes,resizable=no');
mywin.focus();
}else{
alert('Please select atleast one record.');
}


  • April 08, 2014
  • Like
  • 1
I've been reading the other posts, but due to my lack of coding experience (button admin just learning code) I'm having difficulting translating solutions for standard VF pages to my Flow VF page where I have no code for the buttons.

I have a flow which is launched in a new window through a custom link on a custom object. I want the window to close and refresh the custom object page when the flow is completed. I have two VF Pages - The first with the flow, and the second which I am using as a finish location which holds my Javascript currently. I have been able to get the new window to close using the code below, but I have been unsuccessful in getting any code to refresh the custom object/parent window. Any help/recommendations would be appreciated!

Custom Link
/apex/New_PP_with_Listing_Decision_Tree?pba_property_id={!pba__Listing__c.pba__PropertyId__c}

Flow VF Page - New_PP_with_Listing_Decision_Tree
<apex:page showHeader="False" sidebar="False">
  <flow:interview name="New_PP_with_Listing_Decision_Tree" finishLocation="{!$Page.Close}" >
  </flow:interview>
</apex:page>

Javascript VF Page - Close
<apex:page >
    <script type="text/javascript">
        window.close();
    </script>
</apex:page>
  • January 03, 2014
  • Like
  • 1
We are using the Activity Manager app by VersatileCapitalist to mass create tasks.

We have buttons to mass create tasks on the contact views (where whoid=contact id), and on a custom Property object (pba__Property__c)  views (where whatid=property id) - Both buttons are below.

On the Property object, we have a contact lookup field for the Property Owner (PropertyOwner__c). We would like to be able to mass create tasks from the Property view with the whoid=PropertyOwner__c.  The app has all of the functionality that we need, I am not sure how to pull/set the contact ids from the property view.

I am pretty new to code, so any help would be appreciated.

Custom Contact Button
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
var records = {!GETRECORDIDS( $ObjectType.Contact)};
var returnURL = window.location.href;
if(records != null && records != ''){
mywin = window.open('/apex/activities__createTasks?Ids='+records+'&retURL='+returnURL+'&type=whoid' , '_top',
'height=400,width=600,status=yes,toolbar=no,menubar=no,location=no,center=yes,resizable=no');
mywin.focus();
}else{
alert('Please select atleast one record.');
}

Custom Property Button
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
var records = {!GETRECORDIDS( $ObjectType.pba__Property__c)};
var returnURL = window.location.href;
if(records != null && records != ''){
mywin = window.open('/apex/activities__createTasks?Ids='+records+'&retURL='+returnURL+'&type=whatId' , '_top',
'height=400,width=600,status=yes,toolbar=no,menubar=no,location=no,center=yes,resizable=no');
mywin.focus();
}else{
alert('Please select atleast one record.');
}


  • April 08, 2014
  • Like
  • 1
I've been reading the other posts, but due to my lack of coding experience (button admin just learning code) I'm having difficulting translating solutions for standard VF pages to my Flow VF page where I have no code for the buttons.

I have a flow which is launched in a new window through a custom link on a custom object. I want the window to close and refresh the custom object page when the flow is completed. I have two VF Pages - The first with the flow, and the second which I am using as a finish location which holds my Javascript currently. I have been able to get the new window to close using the code below, but I have been unsuccessful in getting any code to refresh the custom object/parent window. Any help/recommendations would be appreciated!

Custom Link
/apex/New_PP_with_Listing_Decision_Tree?pba_property_id={!pba__Listing__c.pba__PropertyId__c}

Flow VF Page - New_PP_with_Listing_Decision_Tree
<apex:page showHeader="False" sidebar="False">
  <flow:interview name="New_PP_with_Listing_Decision_Tree" finishLocation="{!$Page.Close}" >
  </flow:interview>
</apex:page>

Javascript VF Page - Close
<apex:page >
    <script type="text/javascript">
        window.close();
    </script>
</apex:page>
  • January 03, 2014
  • Like
  • 1
We are using the Activity Manager app by VersatileCapitalist to mass create tasks.

We have buttons to mass create tasks on the contact views (where whoid=contact id), and on a custom Property object (pba__Property__c)  views (where whatid=property id) - Both buttons are below.

On the Property object, we have a contact lookup field for the Property Owner (PropertyOwner__c). We would like to be able to mass create tasks from the Property view with the whoid=PropertyOwner__c.  The app has all of the functionality that we need, I am not sure how to pull/set the contact ids from the property view.

I am pretty new to code, so any help would be appreciated.

Custom Contact Button
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
var records = {!GETRECORDIDS( $ObjectType.Contact)};
var returnURL = window.location.href;
if(records != null && records != ''){
mywin = window.open('/apex/activities__createTasks?Ids='+records+'&retURL='+returnURL+'&type=whoid' , '_top',
'height=400,width=600,status=yes,toolbar=no,menubar=no,location=no,center=yes,resizable=no');
mywin.focus();
}else{
alert('Please select atleast one record.');
}

Custom Property Button
{!REQUIRESCRIPT("/soap/ajax/20.0/connection.js")}
var records = {!GETRECORDIDS( $ObjectType.pba__Property__c)};
var returnURL = window.location.href;
if(records != null && records != ''){
mywin = window.open('/apex/activities__createTasks?Ids='+records+'&retURL='+returnURL+'&type=whatId' , '_top',
'height=400,width=600,status=yes,toolbar=no,menubar=no,location=no,center=yes,resizable=no');
mywin.focus();
}else{
alert('Please select atleast one record.');
}


  • April 08, 2014
  • Like
  • 1
I've been reading the other posts, but due to my lack of coding experience (button admin just learning code) I'm having difficulting translating solutions for standard VF pages to my Flow VF page where I have no code for the buttons.

I have a flow which is launched in a new window through a custom link on a custom object. I want the window to close and refresh the custom object page when the flow is completed. I have two VF Pages - The first with the flow, and the second which I am using as a finish location which holds my Javascript currently. I have been able to get the new window to close using the code below, but I have been unsuccessful in getting any code to refresh the custom object/parent window. Any help/recommendations would be appreciated!

Custom Link
/apex/New_PP_with_Listing_Decision_Tree?pba_property_id={!pba__Listing__c.pba__PropertyId__c}

Flow VF Page - New_PP_with_Listing_Decision_Tree
<apex:page showHeader="False" sidebar="False">
  <flow:interview name="New_PP_with_Listing_Decision_Tree" finishLocation="{!$Page.Close}" >
  </flow:interview>
</apex:page>

Javascript VF Page - Close
<apex:page >
    <script type="text/javascript">
        window.close();
    </script>
</apex:page>
  • January 03, 2014
  • Like
  • 1