• JoeSpec
  • NEWBIE
  • 0 Points
  • Member since 2013

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 9
    Replies

I have an instance where it looks like all the workflows/process flows associated with an update command in apex are sometimes not completed before a later insert command.
The system has a validation rule where we can only have a single 'Active' ag, which uses a unique field that is set by a workflow.
There's also a process builder process that does some updating on the ag based on record type.

here's the code I believe is causeing the error:

             ag = [select Id, Funding__c,Contract__c,Revision_Narrative__c, RecordTypeId  from Allocation_Group__c where id = :ag.id];
             if(ag.recordtypeId == rtIdActive )  {  // we need to set the old AG to inactive before proceeding, otherwise duplicate active ag error
                ag.recordtypeId = rtIdInactive ;
                update ag;
                ag.recordtypeId = rtIdActive;
             }    
             ag.Revision_Narrative__c=New_Revision_Narrative;
             ag.Revision_History__c=New_Revision_History;
             newAG = ag.clone(false);
             insert newAG;

The problem is I'm sometimes, but not always getting an error from the process builder process that says there are duplicate active AG's.
So I'm wondering how syncronous is the apex.  Does the first update command wait until all workflows/process builders etc have completed before moving on to the next line of code?   I've seen the order of execution information on a update or what happens during the commit, but I'd like to know if apex waits for all that to completely finish before moving on to the next step.

Thanks,

Joe

I'm trying to add some buttons conditionally to a layout.  They will only be displayed for under certain conditions (such as field values).   I've tried to override the standard view with a VF page (shown below) to add the new buttons and using the <apex:detail > tag to render the standard layout.
The problems occur with inline editing.  The buttons remain during inline editing, but if they are pushed , the inline edits don't save.  So I've tried to remove the custom buttons during inline editing, but that's not working.  Either I'd like to be able to code the buttons to save all data on the standard layout or remove them during inline editing.
 
01 <apex:page standardController="Allocation_Group__c" extensions="Controller_Custom_Buttons">
02 <apex:form >
03  <apex:inlineEditSupport hideOnEdit="TestItID" event="ondblclick">
04  
05   <div style ="padding-left:33%;">
06     <apex:commandButton rendered="{!btn_AGPost_Visible}" action="{!LockIt}" value="Post AG"oncomplete="(window.top.location.href = '{!retURL}')"/>
07     <apex:commandButton rendered="{!btn_AGLock_Visible}" action="{!LockIt}" value="Lock AG"oncomplete="(window.top.location.href = '{!retURL}')"/>
08     <apex:commandButton rendered="true" action="{!TestIt}" ID="TestItID" value="Test It"/>
09  </div>
10 
11   <apex:detail inlineEdit="true" subject="{!Allocation_Group__c}" relatedList="true"relatedListHover ="false" title="false" showChatter="true" />
12   </apex:inlineEditSupport>
13 </apex:form>
14 
15</apex:page>


Here's the controller  .  Note I'm trying a few different approaches here but none of it is working for me.
01 public class Controller_Custom_Buttons {
02    private final Allocation_Group__c myAG , myAGtest;
03    public String retURL {get;set;}
04    public Boolean btn_AGPost_Visible{get;set;}
05    public Boolean btn_AGLock_Visible{get;set;}
06    ApexPages.StandardController  stdController;
07 
08    public Controller_Custom_Buttons(ApexPages.StandardController controller) {
09      
10    stdController=controller;
11    myAGtest = (Allocation_Group__c)controller.getRecord();
12    myAG = [SELECT Id, Active__c, Status__c FROM Allocation_Group__c
13                  WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
14    if(myAG.Status__c != 'Posted')
15       btn_AGPost_Visible=true;
16    else
17       btn_AGPost_Visible=false;
18        
19    if(!approval.islocked(myAG) && (myAG.Active__c==false || myAG.Status__c =='Posted') )
20       btn_AGLock_Visible=true;
21    else
22       btn_AGLock_Visible=false;
23 
24 
25    }
26 public PageReference PostIt() {
27 
28 myAG.Status__c='Posted';
29 update myAg;
30 approval.lock(myAG.Id);  // doing this in trigger onAllocation_Group
31 
32 retURL='/' + myAG.Id;
33 
34 return null;
35 }
36 public PageReference LockIt() {
37 
38 update myAg;
39 approval.lock(myAG.Id);  // doing this in trigger onAllocation_Group
40 
41 retURL='/' + myAG.Id;
42 
43 return null;
44 }
45 public PageReference TestIt() {
46 myAGtest.Revision_History__c='Testing';
47 stdController.save();
48 // update myAGtest;
49 
50 return null;
51 
52 }
53 
54 }

any help would be appreciated.

Thanks,
Joe
 
I'm trying to add some buttons conditionally to a layout.  They will only be displayed for under certain conditions (such as field values).   I've tried to override the standard view with a VF page (shown below) to add the new buttons and using the <apex:detail > tag to render the standard layout.
The problems occur with inline editing.  The buttons remain during inline editing, but if they are pushed , the inline edits don't save.  So I've tried to remove the custom buttons during inline editing, but that's not working.  Either I'd like to be able to code the buttons to save all data on the standard layout or remove them during inline editing.


 
<apex:page standardController="Allocation_Group__c"  extensions="Controller_Custom_Buttons">
<apex:form >
 <apex:inlineEditSupport hideOnEdit="TestItID" event="ondblclick">

   <div style ="padding-left:33%;">
     <apex:commandButton rendered="{!btn_AGPost_Visible}" action="{!LockIt}" value="Post AG" oncomplete="(window.top.location.href = '{!retURL}')"/>
     <apex:commandButton rendered="{!btn_AGLock_Visible}" action="{!LockIt}"  value="Lock AG" oncomplete="(window.top.location.href = '{!retURL}')"/>
     <apex:commandButton rendered="true" action="{!TestIt}"  ID="TestItID" value="Test It"/>
 </div>

   <apex:detail inlineEdit="true" subject="{!Allocation_Group__c}" relatedList="true" relatedListHover ="false" title="false" showChatter="true" /> 
   </apex:inlineEditSupport>
</apex:form>

</apex:page>
Here's the controller  .  Note I'm trying a few different approaches here but none of it is working for me.
public class Controller_Custom_Buttons {
    private final Allocation_Group__c myAG , myAGtest;
    public String retURL {get;set;}
    public Boolean btn_AGPost_Visible{get;set;}
    public Boolean btn_AGLock_Visible{get;set;}
    ApexPages.StandardController  stdController; 

    public Controller_Custom_Buttons(ApexPages.StandardController controller) {
     
    stdController=controller;
    myAGtest = (Allocation_Group__c)controller.getRecord();
    myAG = [SELECT Id, Active__c, Status__c FROM Allocation_Group__c
                  WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    if(myAG.Status__c != 'Posted')
       btn_AGPost_Visible=true;
    else
       btn_AGPost_Visible=false;
       
    if(!approval.islocked(myAG) && (myAG.Active__c==false || myAG.Status__c =='Posted') )
       btn_AGLock_Visible=true;
    else
       btn_AGLock_Visible=false;


    }
public PageReference PostIt() {

myAG.Status__c='Posted';
update myAg;
approval.lock(myAG.Id);  // doing this in trigger onAllocation_Group

retURL='/' + myAG.Id;

return null;
}
public PageReference LockIt() {

update myAg;
approval.lock(myAG.Id);  // doing this in trigger onAllocation_Group

retURL='/' + myAG.Id;

return null;
}
public PageReference TestIt() {
myAGtest.Revision_History__c='Testing';
stdController.save();
// update myAGtest;

return null;

}

}
any help would be appreciated.

Thanks,
Joe
 

Is it possible to have a trigger run (or any other way to catch the action) when the 'Unlock' button is clicked?   right now it doesn't actually update the record that is being unlocked, so a trigger doesn't fire.    
 

It doesn't appear I have any control over the display/action of that button or any way to know when it's clicked.

What I'm trying to do is have a field on the object that indicates if the record is locked or not so various other things can happen based on that info.  I'm doing this outside an actuall approval process so have other apex that is used to lock the record. 

I've been having a lot of difficulty gettting the data i want from a soql query.  First I was having trouble getting it from a report so gave up thinking soql would be more robust, but it seems to thwart me at every turn.

I have the following 3 objects  contacts,  Cases__c, DirectServices__c  (note taht cases is custom obj)   

 

Cases - > DirectService is Master/Detail.

Cases and DirectSerivices both have contact lookup

 

I want to get results from soql for how i would assume this would work :

 

Select contact__c, contact__r.Client_Full_Name__c, Owner.Name   , (select sum(total_time__c) from direct_service__r where date <x and date >y) from case__c  where case__c.Service = 'xxx' and date<x and date>y

 

But it won't let me use aggregate function in the subquery.  and ultimately I actually want a sum of all direct services  on any case over that time period for a client who had an open case of service 'xxx;  not actually the direct_service__r relationship which is just Direct_Services for cases with service 'xxx'.

 

I also tried it from the other direction doing a select on the direct_service and  grouping by the contact and doing a Contact_c in (select contact__c from case__C where ....)

 

something like :

SELECT  MIN(Client__r.Client_Full_Name__c) Client_Name,  MIN(case__r.HSA_Worker_Name__c) HSA_Worker_Name,  MIN(case__r.HSA_Worker_ID__c) HSA_Worker_ID ,MIN(Case__r.CalWORKS_Case_Number__c) Calworks_Case_Number ,  MIN(case__r.Owner.Name) Owner, MIN(case__r.open_date__c) Open_Date ,  MIN(case__r.close_date__c) Close_Date, sum(Total_Time__c) Total_Time   
FROM Direct_Service__c  
WHERE Client__c  in 
    (Select contact__c from case__c 
           WHERE (service__c = 'a1R20000000xxxx' AND  open_date__c<= 2013-08-31) 
           AND (status__c='Case Open'  or (Status__c='Case Closed' and Close_date__c >= 2013-08-31 )))  
AND Location__c != 'Phone' AND Direct_Service_Type__c != 'Collateral'
group by Client__c 

 

 

This almost worked but it turns out the MIN(Case__r....) data isn't what I want.  I actually want it for the specific service__c, and since multiple cases can get returned ...

also what I really want is all cases not just those with DirectService entries,  if no direct service entries it should return 0 total time.

 

 

  • September 24, 2013
  • Like
  • 0

I have a class that contains a test method. this method passes in production and seems to be working fine.

When I run the test on the sandbox though, the test fails.

I took out all my new code.  I refreshed the sandbox (which took 3 days by the way) and still it fails on the sandbox.

 

The code basically calls some soql  and sets 2 fields in an assessment object , previous assessment and next assessment.

The test class makes an assertion to see if the earliest assessment has a null in the previous assessment field as it should.   but instead it links back to one of the other assessments which  the test creates.

 

any ideas on why the difference when running it from the sandbox?

 

also this isn't my code making it a bit more difficult to understand what's going on.

 

thanks,

 

 

Hi I have a custome object related to contacts as a lookup.

so a contact can have many cust_obj.

I need to update all the contacts so they have ownership ID of the most recent entry of the cust_obj.

 

so basically trying to get a file with contactID, OwnershipID of Cust_Obj with max(created_date)

 

is there a way to write this report.  or Soql (which I can export to a file,  I seem to have trouble finding a tool to let me do that) or some other way to handle this?

 

thanks in advance for any input,

Joe

Hi I am finding the documentation I can find on running and debugging apex code in the force IDE to be lacking.

Wondering if anyone could point me to a tutorial video or documentation that will help me with running apex code or VF pages from IDE and debugging it.

 

thanks

Hi I'm new to apex development,

 

I'm just trying to get a general idae on the tools available and when to use them.

 

When do you use the eclipse force.com IDE vs the Developer console?

 

writting code I assume you do in the IDE.

how about debugging?  

and test runs?  I'm finding I sometimes get errors on tests run in salesforce.com but not in the IDE.

do people generally deploy from IDE or salesforce.com?

 

Phrased another way,  what do you do in the devloper console, and what do you do in the IDE?

 

 

Thanks for any insight..  

 

-Joe

Hi,

I'm writing some apex code and trying to something like the following SOQL statment but have run into a few problems.

 

Select
ID, OwnerID, Total_Time__c,  Case__r.Contact__c, Date__c
From Staff_UOS__c
Where
Date__c >= :select_start_date
and Date__c <= :select_end_date
and Case__r.Contact__c  IN ( Select Id from Contact where xxxx )

basically it doesn't seem to  like the care__r.Contact__c in the where clause.  

I see this error in the IDE

Save error: The left operand 'Case__r.Contact__c' cannot have more than one level of relationships.

I was sure i saw in the soql doccumentation that you could use the dot notation in the where clause, but it doesn't seem to allow it.

 

I tried to create  a formulat field pm Staff_UOS that equaled Care__r.Contact__c  but then i started running into errors because they were different data types (formula couldn't be ID type) and I coulnd't  get around that.

 

Perhaps I'm getting the syntax wrong or missing something, hence this post.

 

Thanks

Joe

I'm trying to add some buttons conditionally to a layout.  They will only be displayed for under certain conditions (such as field values).   I've tried to override the standard view with a VF page (shown below) to add the new buttons and using the <apex:detail > tag to render the standard layout.
The problems occur with inline editing.  The buttons remain during inline editing, but if they are pushed , the inline edits don't save.  So I've tried to remove the custom buttons during inline editing, but that's not working.  Either I'd like to be able to code the buttons to save all data on the standard layout or remove them during inline editing.
 
01 <apex:page standardController="Allocation_Group__c" extensions="Controller_Custom_Buttons">
02 <apex:form >
03  <apex:inlineEditSupport hideOnEdit="TestItID" event="ondblclick">
04  
05   <div style ="padding-left:33%;">
06     <apex:commandButton rendered="{!btn_AGPost_Visible}" action="{!LockIt}" value="Post AG"oncomplete="(window.top.location.href = '{!retURL}')"/>
07     <apex:commandButton rendered="{!btn_AGLock_Visible}" action="{!LockIt}" value="Lock AG"oncomplete="(window.top.location.href = '{!retURL}')"/>
08     <apex:commandButton rendered="true" action="{!TestIt}" ID="TestItID" value="Test It"/>
09  </div>
10 
11   <apex:detail inlineEdit="true" subject="{!Allocation_Group__c}" relatedList="true"relatedListHover ="false" title="false" showChatter="true" />
12   </apex:inlineEditSupport>
13 </apex:form>
14 
15</apex:page>


Here's the controller  .  Note I'm trying a few different approaches here but none of it is working for me.
01 public class Controller_Custom_Buttons {
02    private final Allocation_Group__c myAG , myAGtest;
03    public String retURL {get;set;}
04    public Boolean btn_AGPost_Visible{get;set;}
05    public Boolean btn_AGLock_Visible{get;set;}
06    ApexPages.StandardController  stdController;
07 
08    public Controller_Custom_Buttons(ApexPages.StandardController controller) {
09      
10    stdController=controller;
11    myAGtest = (Allocation_Group__c)controller.getRecord();
12    myAG = [SELECT Id, Active__c, Status__c FROM Allocation_Group__c
13                  WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
14    if(myAG.Status__c != 'Posted')
15       btn_AGPost_Visible=true;
16    else
17       btn_AGPost_Visible=false;
18        
19    if(!approval.islocked(myAG) && (myAG.Active__c==false || myAG.Status__c =='Posted') )
20       btn_AGLock_Visible=true;
21    else
22       btn_AGLock_Visible=false;
23 
24 
25    }
26 public PageReference PostIt() {
27 
28 myAG.Status__c='Posted';
29 update myAg;
30 approval.lock(myAG.Id);  // doing this in trigger onAllocation_Group
31 
32 retURL='/' + myAG.Id;
33 
34 return null;
35 }
36 public PageReference LockIt() {
37 
38 update myAg;
39 approval.lock(myAG.Id);  // doing this in trigger onAllocation_Group
40 
41 retURL='/' + myAG.Id;
42 
43 return null;
44 }
45 public PageReference TestIt() {
46 myAGtest.Revision_History__c='Testing';
47 stdController.save();
48 // update myAGtest;
49 
50 return null;
51 
52 }
53 
54 }

any help would be appreciated.

Thanks,
Joe
 
I'm trying to add some buttons conditionally to a layout.  They will only be displayed for under certain conditions (such as field values).   I've tried to override the standard view with a VF page (shown below) to add the new buttons and using the <apex:detail > tag to render the standard layout.
The problems occur with inline editing.  The buttons remain during inline editing, but if they are pushed , the inline edits don't save.  So I've tried to remove the custom buttons during inline editing, but that's not working.  Either I'd like to be able to code the buttons to save all data on the standard layout or remove them during inline editing.


 
<apex:page standardController="Allocation_Group__c"  extensions="Controller_Custom_Buttons">
<apex:form >
 <apex:inlineEditSupport hideOnEdit="TestItID" event="ondblclick">

   <div style ="padding-left:33%;">
     <apex:commandButton rendered="{!btn_AGPost_Visible}" action="{!LockIt}" value="Post AG" oncomplete="(window.top.location.href = '{!retURL}')"/>
     <apex:commandButton rendered="{!btn_AGLock_Visible}" action="{!LockIt}"  value="Lock AG" oncomplete="(window.top.location.href = '{!retURL}')"/>
     <apex:commandButton rendered="true" action="{!TestIt}"  ID="TestItID" value="Test It"/>
 </div>

   <apex:detail inlineEdit="true" subject="{!Allocation_Group__c}" relatedList="true" relatedListHover ="false" title="false" showChatter="true" /> 
   </apex:inlineEditSupport>
</apex:form>

</apex:page>
Here's the controller  .  Note I'm trying a few different approaches here but none of it is working for me.
public class Controller_Custom_Buttons {
    private final Allocation_Group__c myAG , myAGtest;
    public String retURL {get;set;}
    public Boolean btn_AGPost_Visible{get;set;}
    public Boolean btn_AGLock_Visible{get;set;}
    ApexPages.StandardController  stdController; 

    public Controller_Custom_Buttons(ApexPages.StandardController controller) {
     
    stdController=controller;
    myAGtest = (Allocation_Group__c)controller.getRecord();
    myAG = [SELECT Id, Active__c, Status__c FROM Allocation_Group__c
                  WHERE Id = :ApexPages.currentPage().getParameters().get('id')];
    if(myAG.Status__c != 'Posted')
       btn_AGPost_Visible=true;
    else
       btn_AGPost_Visible=false;
       
    if(!approval.islocked(myAG) && (myAG.Active__c==false || myAG.Status__c =='Posted') )
       btn_AGLock_Visible=true;
    else
       btn_AGLock_Visible=false;


    }
public PageReference PostIt() {

myAG.Status__c='Posted';
update myAg;
approval.lock(myAG.Id);  // doing this in trigger onAllocation_Group

retURL='/' + myAG.Id;

return null;
}
public PageReference LockIt() {

update myAg;
approval.lock(myAG.Id);  // doing this in trigger onAllocation_Group

retURL='/' + myAG.Id;

return null;
}
public PageReference TestIt() {
myAGtest.Revision_History__c='Testing';
stdController.save();
// update myAGtest;

return null;

}

}
any help would be appreciated.

Thanks,
Joe
 
When we try to get a visualforce page to be visible in our Community it says that the page is under construction and the worst part is that is references our other community.  Here is a Thread from an email regarding this.  I hope I can get some help on this.  Please and Thank you,

We need help with an error message that is coming up… And this is one of those weird ones again that we found.

We have a button called “Add New Items for Credit.” That when you select it should bring you to a visual force page. Now in the communicates environment when we select the button, it gives us an error message. Pay attention to the URL changes in the screen shots below. We need this fixed asap as this is a pretty big deal blocking roll out of communities.
User-added image

This is the error message… Notice the /ahold is missing now before the /apex.  Why??? Should not be like that. In addition, the error message is /APtea . That is a different community not yet published.

User-added image

This is what it should do and look like. Notice when we put the ahold in there as it should for the community, it works.

User-added image

I've been having a lot of difficulty gettting the data i want from a soql query.  First I was having trouble getting it from a report so gave up thinking soql would be more robust, but it seems to thwart me at every turn.

I have the following 3 objects  contacts,  Cases__c, DirectServices__c  (note taht cases is custom obj)   

 

Cases - > DirectService is Master/Detail.

Cases and DirectSerivices both have contact lookup

 

I want to get results from soql for how i would assume this would work :

 

Select contact__c, contact__r.Client_Full_Name__c, Owner.Name   , (select sum(total_time__c) from direct_service__r where date <x and date >y) from case__c  where case__c.Service = 'xxx' and date<x and date>y

 

But it won't let me use aggregate function in the subquery.  and ultimately I actually want a sum of all direct services  on any case over that time period for a client who had an open case of service 'xxx;  not actually the direct_service__r relationship which is just Direct_Services for cases with service 'xxx'.

 

I also tried it from the other direction doing a select on the direct_service and  grouping by the contact and doing a Contact_c in (select contact__c from case__C where ....)

 

something like :

SELECT  MIN(Client__r.Client_Full_Name__c) Client_Name,  MIN(case__r.HSA_Worker_Name__c) HSA_Worker_Name,  MIN(case__r.HSA_Worker_ID__c) HSA_Worker_ID ,MIN(Case__r.CalWORKS_Case_Number__c) Calworks_Case_Number ,  MIN(case__r.Owner.Name) Owner, MIN(case__r.open_date__c) Open_Date ,  MIN(case__r.close_date__c) Close_Date, sum(Total_Time__c) Total_Time   
FROM Direct_Service__c  
WHERE Client__c  in 
    (Select contact__c from case__c 
           WHERE (service__c = 'a1R20000000xxxx' AND  open_date__c<= 2013-08-31) 
           AND (status__c='Case Open'  or (Status__c='Case Closed' and Close_date__c >= 2013-08-31 )))  
AND Location__c != 'Phone' AND Direct_Service_Type__c != 'Collateral'
group by Client__c 

 

 

This almost worked but it turns out the MIN(Case__r....) data isn't what I want.  I actually want it for the specific service__c, and since multiple cases can get returned ...

also what I really want is all cases not just those with DirectService entries,  if no direct service entries it should return 0 total time.

 

 

  • September 24, 2013
  • Like
  • 0

I have a class that contains a test method. this method passes in production and seems to be working fine.

When I run the test on the sandbox though, the test fails.

I took out all my new code.  I refreshed the sandbox (which took 3 days by the way) and still it fails on the sandbox.

 

The code basically calls some soql  and sets 2 fields in an assessment object , previous assessment and next assessment.

The test class makes an assertion to see if the earliest assessment has a null in the previous assessment field as it should.   but instead it links back to one of the other assessments which  the test creates.

 

any ideas on why the difference when running it from the sandbox?

 

also this isn't my code making it a bit more difficult to understand what's going on.

 

thanks,

 

 

Hi I have a custome object related to contacts as a lookup.

so a contact can have many cust_obj.

I need to update all the contacts so they have ownership ID of the most recent entry of the cust_obj.

 

so basically trying to get a file with contactID, OwnershipID of Cust_Obj with max(created_date)

 

is there a way to write this report.  or Soql (which I can export to a file,  I seem to have trouble finding a tool to let me do that) or some other way to handle this?

 

thanks in advance for any input,

Joe