• Harold
  • NEWBIE
  • 30 Points
  • Member since 2013

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

Hi Everyone!

 

I am writing an apex trigger. The trigger is designed to fire when a revenue event is created. The trigger is suposed to perform a query on Accounts to find an item called Commission Calculation. If the Commission Calculation is active, the trigger gets the Sales Agent's ID and the Commission Calculation ID, which it uses to populate fields in the Commission record. 

 

My problem is I can't see to find a way to get the For loop to operate correctly. Below is the trigger in all its glory. If anyone can help it would be deeply appreciated!

 

trigger GenerateCommission on Revenue_Event__c (after insert) {

For (Revenue_Event__c NewRevenueEvent : Trigger.new){

If (NewRevenueEvent != null)
{
list <Account> CommissionList = [SELECT Id,
(SELECT id, Sales_Agent__C FROM Commission_Calculations__r WHERE Active__c = TRUE)
FROM Account];

Integer i = CommissionList.size();

list <Commission__c> NewCommission = new list <Commission__c>();

for (Account j : NewCommissionList) {
NewCommission[0].Revenue_Event__c = NewRevenueEvent.id;
NewCommission[0].Sales_Agent__c = CommissionList[0].Commission_Calculations__r.get(0).Sales_Agent__c;
NewCommission[0].Commission_Percentage__c = CommissionList[0].Commission_Calculations__r.get(0).id;
}
// Insert NewCommission[0];
}

}
}

I have created a custom link that sits on the home page.  It's a java script link that kicks off a batch processing job.  What I'd like to do is put in a confirmation dialog to the give the user a chance to back out of running the process.  I can't seem to get the confirm call to work . Here is the code:

{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js')}
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js')}
if(Confirm('You are about to update the Opportunities via the batch process. You should make sure no one is modifying Opportunities or Opportunity Splits while this process is running. You can monitor the process under setup/monitoring/apexJobs. Do you want to continue?')sforce.apex.execute("clsOpportunitySplitManageBchbl","processAllManual",{}));


  • December 26, 2013
  • Like
  • 0

Is it possible to write a trigger on the Opportunity Split Object?

  • December 07, 2013
  • Like
  • 0

So I have a need to build a custom url that is built from an object and soql queries.  It's for a custom report screen.  

 

Basically the flow is like this:  The user clicks on a report link that should fire a controller method that sends the report name to a controller method, the method uses the report name and a custom object and soql to build a report url.  Then a window.open should be done in the vf page to open that url into a new window.  

 

Here is the visualforce code

----Where the link is displayed

<apex:repeat value="{!lstUnitReport}" var="pUnitRep" >
<apex:commandlink style="font-size:13px;color:#black;white-space:nowrap;" rendered="{!AND(unitselectedval!=null,pUnitRep.Surl!=null)}"
onclick="execreport('{!pUnitRep.CR.Report_Name__c}');" immediate="true">
{!pUnitRep.CR.Report_Name__c}2<br/>
</apex:CommandLink>

</apex:repeat>

 

--Java script code

<apex:outputpanel id="jspanel">
<script type="text/javascript">
function execreport (param) {
dosetvariable('param');
alert('{!stringUrl}');
}
</script>
</apex:outputpanel>

 

--action function

<apex:actionfunction name="dosetvariable" action="{!setclassvariable}" rerender="jspanel" >
<apex:param name="param1" assignTo="{!sreportName}" value=""></apex:param>
</apex:actionfunction>

 

I can see through the debug log that the action function is calling the controller method "setclassVariable" but the alert in the java script is blank.  

 

Im not sure if there is a better way to handle this if there is please let me know.

Thanks in advanced.

  • November 26, 2013
  • Like
  • 0

I have a visual force page with inline editing enabled.  It works great when a record exists, however I can't seem to get the page to not be inline editiable when no record exists.  I've tried changing the mode to just edit or detail when no record exists but it doesn't seem to be working. 

 

What I would like is when the page loads, if there is a record then inline editing should be enabled, if no record exists then it shouldn't.

 

I have a feeling that I'm going to have to disable each individual field when no record exists.

 

 

  • November 13, 2013
  • Like
  • 0

So I have a basic query Select id, Object__r.Name from myCustomObject  that works fine to get me the name field from my lookup relationship object__r

 

However, when I build this statement exactly the same and run it through database.query(mySql); I get an invalid field name on the object__r.Name?

 

Are there issues using __r relationship with dynamic soql?

  • November 08, 2013
  • Like
  • 0

Has anyone else run into the issue with the Developer Console not showing the code coverage rows?  The documentation says that it should be highlighting covered rows in blue and missed rows in red.  I used to be able to get to this info via the classes in SF.  They've moved it to Dev Console but it doesn't work.

 

 

  • October 30, 2013
  • Like
  • 0

Basically I have a numeric field in by object. A field that has existed for quite sometime.  There is also a visualforce page where the value is entered.  Recently we have decided that the only valid values for the field are 1 and 2.  So rather than changing the field type or tying validation rules to the field,  I've decided to change the visualforce page to just give them a select option of 1 or 2.  So I added the code below to my VF page.

 

<apex:column headervalue="Number of Motors" rendered="{!measureType='NVB'}" >
<apex:selectlist value="{!R.objTreatment.Installed_Count__c}" multiselect="false" size="1" >
<apex:selectOption itemValue="1" itemLabel="1" />
<apex:selectOption itemValue="2" itemLabel="2" />
</apex:selectlist>
</apex:column>

 

"R" is a wrapper, objTreatment is a custom object and of course installed Count is the field.  There is no code in the controller, it just loads the object from the database.  It works fine to set the field value on a save.  However it won't load with the correct value.  If I choose 2 and click save, it reloads the data and display's 1 even though the field is set to 2.  

 

I know I could probably create the select options list in the controller, then set the value.  But I'm hoping there's a way to make the select list default to the value in {!R.objectTreatment.Installed_Count__c} without moving the code to the controller.

  • October 29, 2013
  • Like
  • 0

I have a strange rounding issue and I'm not sure if saleforce has a formula for this kind of rounding.  It's probably best explained with an example.

 

.1,.2,.3 would round down to the whole number

.4,.5,.6 would round to .5

.7,.8,.9 would round up to the next value.

 

So 88.3 becomes 88

     88.4 becomes 88.5

     88.7 becomes 89

 

I can write my own code to do this, but I was hoping there was already something out there. 

  • March 25, 2013
  • Like
  • 0

I'm trying to refresh our full sandbox from production.  However when I choose the refresh link, the only radio button it will let me choose is Developer?  Anyone seen this before?

  • February 09, 2013
  • Like
  • 0
I have created a custom link that sits on the home page.  It's a java script link that kicks off a batch processing job.  What I'd like to do is put in a confirmation dialog to the give the user a chance to back out of running the process.  I can't seem to get the confirm call to work . Here is the code:

{!REQUIRESCRIPT("/soap/ajax/14.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/14.0/apex.js")}
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js')}
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js')}
if(Confirm('You are about to update the Opportunities via the batch process. You should make sure no one is modifying Opportunities or Opportunity Splits while this process is running. You can monitor the process under setup/monitoring/apexJobs. Do you want to continue?')sforce.apex.execute("clsOpportunitySplitManageBchbl","processAllManual",{}));


  • December 26, 2013
  • Like
  • 0

Hi Everyone!

 

I am writing an apex trigger. The trigger is designed to fire when a revenue event is created. The trigger is suposed to perform a query on Accounts to find an item called Commission Calculation. If the Commission Calculation is active, the trigger gets the Sales Agent's ID and the Commission Calculation ID, which it uses to populate fields in the Commission record. 

 

My problem is I can't see to find a way to get the For loop to operate correctly. Below is the trigger in all its glory. If anyone can help it would be deeply appreciated!

 

trigger GenerateCommission on Revenue_Event__c (after insert) {

For (Revenue_Event__c NewRevenueEvent : Trigger.new){

If (NewRevenueEvent != null)
{
list <Account> CommissionList = [SELECT Id,
(SELECT id, Sales_Agent__C FROM Commission_Calculations__r WHERE Active__c = TRUE)
FROM Account];

Integer i = CommissionList.size();

list <Commission__c> NewCommission = new list <Commission__c>();

for (Account j : NewCommissionList) {
NewCommission[0].Revenue_Event__c = NewRevenueEvent.id;
NewCommission[0].Sales_Agent__c = CommissionList[0].Commission_Calculations__r.get(0).Sales_Agent__c;
NewCommission[0].Commission_Percentage__c = CommissionList[0].Commission_Calculations__r.get(0).id;
}
// Insert NewCommission[0];
}

}
}

I have something strange happening in my test code and I can't figure out what's happening.

 

I have to following code:

//other code to create O1 exists above. 

ApexPages.StandardController sc = new ApexPages.standardController(O1);

    cntrCreateCompanyProduct CCP = new cntrCreateCompanyProduct(sc);

    CCP.newCP(); //creates a new ComProd varible and loads it.

    if(CCP.ComProd != null) system.debug('testing comp is not null');

    System.AssertEquals(CCP.ComProd,null);

 

So I see the debug message in my debug log, which means that CCP.ComProd is not null however the Assert is firing causing my test code to fail at this point?

 

I'm not sure what I'm missing.

So I have a basic query Select id, Object__r.Name from myCustomObject  that works fine to get me the name field from my lookup relationship object__r

 

However, when I build this statement exactly the same and run it through database.query(mySql); I get an invalid field name on the object__r.Name?

 

Are there issues using __r relationship with dynamic soql?

  • November 08, 2013
  • Like
  • 0

Hi,

 

I  need a trigger when account owner changes,my customobject owner(Look up relationship) also changes .

 

Trigger updateowner on Account (after insert,after update) {

    set<Id> setOfAccoutOwnerChanged = new set<Id>();
    for(Account a : Trigger.new){
    if(a.OwnerId != Trigger.oldMap.get(a.Id).OwnerId)
    setOfAccoutOwnerChanged.add(a.Id);
    }
    if(!setOfAccoutOwnerChanged.isEmpty()) {
    List<Customobject__c> listOfCandidatesToUpdate = new List<Customobject__c>();
    
    Map<Id,Account> accountMap = new Map<Id,Account>();
//It error at this line.   
accountmap=[SELECT ID,OwnerId,(Select id,name,ownerid from Customobject__c) FROM Account WHERE Id =:setOfAccoutOwnerChanged]; } }

 

I am failing with my SOQL query...What am i missing.I feel this is similar to account-contact 

I want to create an Inline Visualforce that auto update the record when the page is viewed.

So I created a page that calls a component controlled by a custom controller.

 

It's possible to include an action in this component that calls a function to update the record when the page is visualized for the user?

Can someone help me?

Basically I have a numeric field in by object. A field that has existed for quite sometime.  There is also a visualforce page where the value is entered.  Recently we have decided that the only valid values for the field are 1 and 2.  So rather than changing the field type or tying validation rules to the field,  I've decided to change the visualforce page to just give them a select option of 1 or 2.  So I added the code below to my VF page.

 

<apex:column headervalue="Number of Motors" rendered="{!measureType='NVB'}" >
<apex:selectlist value="{!R.objTreatment.Installed_Count__c}" multiselect="false" size="1" >
<apex:selectOption itemValue="1" itemLabel="1" />
<apex:selectOption itemValue="2" itemLabel="2" />
</apex:selectlist>
</apex:column>

 

"R" is a wrapper, objTreatment is a custom object and of course installed Count is the field.  There is no code in the controller, it just loads the object from the database.  It works fine to set the field value on a save.  However it won't load with the correct value.  If I choose 2 and click save, it reloads the data and display's 1 even though the field is set to 2.  

 

I know I could probably create the select options list in the controller, then set the value.  But I'm hoping there's a way to make the select list default to the value in {!R.objectTreatment.Installed_Count__c} without moving the code to the controller.

  • October 29, 2013
  • Like
  • 0

I'm trying to refresh our full sandbox from production.  However when I choose the refresh link, the only radio button it will let me choose is Developer?  Anyone seen this before?

  • February 09, 2013
  • Like
  • 0