• nimdhar
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 10
    Questions
  • 16
    Replies
Hi,

I am getting the following error when trying to insert an object called IncentiveCount. I have a trigger which runs when inserting DFR object. DFR object has link to an Account. When inserting DFR object I should see the Account Id and get all the Incentives associated with that Account. After that I should see if there is any incentive which has start date equal to DFR date. If it has I need to insert a record in Incentive Count that has a DFR Id, Incentive Id, Account Id. When I did this with the below code
for(integer i=0;i<accountIds.size();i++)
 {
if(entries.containsKey(accountIds[i]) && (!uniqueAccountIdsToLoop.contains(accountIds[i])))
{
uniqueAccountIdsToLoop.add(accountIds[i]);
List<Incentive__c> incentivesToLoop= new List<Incentive__c>();
incentivesToLoop = entries.get(accountIds[i]);
for(integer j=0;j<incentivesToLoop.size();j++)
{
for(Doctors_First_Report__c newDFRs: Trigger.new.deepClone())
{

if(newDFRs.Account__c<>null && newDFRs.Account__c==accountIds[i])
{

if(incentivesToLoop[j].Start_Date__c<>null && incentivesToLoop[j].End_Date__c<>null)
{
if(newDFRs.DFR_Date__c >= incentivesToLoop[j].Start_Date__c && newDFRs.DFR_Date__c <= incentivesToLoop[j].End_Date__c)
{
IncentiveCount__c ic=new IncentiveCount__c();
ic.Account__c=accountIds[i];
ic.Doctor_s_First_Report__c=newDFRs.Id;
ic.Incentive__c=incentivesToLoop[j].Id;
incentivesToInsert.add(ic);
}
}
}
}
}
insert incentivesToInsert;
}
}
}
I get the below exception
caused by: System.DmlException: Insert failed. First exception on row 0 with id a0DR0000000ktPAMAY; first error: INVALID_FIELD_FOR_INSERT_UPDATE, cannot specify Id in an insert call: [Id]

Can anyone please let me know what this error is about?

Thanks,
Nimdhar

Hi All,

Scenario

Account has two fields Current Total Year to date count(which stores count of some records for  current year) and Previous Total Year to date count (which stores count of some records for the previous year).  At the end of the year I need to update Previous Total Year to date count with Current Total Year to date count and  Current Total Year to date count to zero.

 Possible Solution
I created a AccountBatch Object which has NextRunTime variable and in my Time Based workflow I set my workflow to run after 0 hrs NextRuntime and update some field in AccountBatch Object which runs my trigger to do the above mentioned logic.  But my workflow doesn't run at the time I mentioned in the NextRunTime. It runs only when I update my AccountBatch.

Any suggestions on how to solve the above problem is greatly appreciated.

Thanks,
Nimdhar
Hi,

I am calling a web method from a javascript function in a visual force page. But that function is not getting called. Below is the  code

This is in my visual force page calling the javascript function
<apex:outputlink onclick="setLeadLocation('{!$CurrentPageReference.parameters.leadid}','{!location.id}');"> Attach </apex:outputlink>

This is my javascript function which calls the webmethod
function setLeadLocation(leadid,locationid)
{
   sforce.apex.execute('LeadServices','assignLocationToLead', {leadId:leadid,locationId:locationid});
 }

This is my web method

global class LeadServices
{
 
Webservice static void assignLocationToLead(ID leadId, ID locationId) {
   
      
Lead lead = [select Id from Lead where Id=:leadId];
      
lead.Location__c = locationId;
       
update lead;
       
return;
}

Can anyone tell is this not possible from a visual force page?

Thanks,
Nimdhar
Hi,
I have the following code that displays all the locations iterating through the locationresults. The commandLink sends the correct id to the controller only for the first record.  For the rest of the records it sends null. I think it is set only once. Can anyone tell me how to do this?
<apex:pageblocksection title="Locations" id="locationresults">
   <apex:pageblocklist value="{!locationresults}" var="location" rendered="{!NOT(ISNULL(locationresults))}">
                    <apex:column headerValue="Name">
                               <apex:outputlink value="/{!location.id}">{!location.name}</apex:outputlink>
                      </apex:column>
                       <apex:column value="{!location.Address__c}" />
                        <apex:column value="{!location.City__c}" />
                         <apex:column value="{!location.State__c}" />
                          <apex:column value="{!location.ZipCode__c}" />
                            <apex:column>
                                   <apex:commandLink value="Attach"  action="{!attach}" oncomplete="closewindow()">
                                           <apex:param assignTo="{!myclient}" value="{!location.id}"/>
                                     </apex:commandLink> 
                               </apex:column>
                                </apex:pageblocklist>
                        </apex:pageblocksection>

Thanks,
Nimdhar
Hi,
 
I have a pop up window which popups a visual force page. I am trying to close this popup and reload my original page when some action is done as follows

<script>
 function closeSearchWindow()
 {
    window.close();
 }
</script>
<apex:commandLink value="Attach" action="{!attach}"  onclick="closeSearchWindow();">
      <apex:param assignTo="{!myclient}" value="{!location.id}"/>
</apex:commandLink>

But this is not working. Is there any other way to do this.

Thanks,
Nimdhar


Message Edited by nimdhar on 04-29-2008 07:22 AM
Hi,
<apex:commandLink  value="attach" action="{!attach}">
 <apex :param assignto="{!test}" value="{!location.id}"/>
</apex:commandLink>

And I have getter and setter methods in my controller. This works fine. But when I replace it with commandButton it is not working.

Thanks,
Nimdhar
Hi,

I am sending parameters using a command button to a controller as follows
 <apex:commandButton value="Attach" action="{!attach}" >
 <apex:param name="leadId" value="{!$CurrentPageReference.parameters.q}" />
 <apex:param name="locId" value="{!location.id}" />
 </apex:commandButton>


I am trying to access those parametrs in the controller by having a get and set method. But it is not working. Can anyone suggest me how to access those parameters in a controller.

Thanks,
Nimdhar
Hi,

I have a S-control that invokes the visual force page as follows
window.open ("/apex/searchLocation?q={!Lead.Id}","myWindow",' status=1,height=600, width=1000,menubar=no,toolbar=no');

I am passing a query parameter lead id to the visual force page. when I accessed the lead id it is passing or getting the id with last three letters truncated
   <apex:commandButton value="Attach" action="{!attach}" onclick="alert('{!$CurrentPageReference.parameters.q}');"/>

Lets say the actual lead id is 00QT0000004RErUMAW. I am getting 00QT0000004RErU. Why is that last three letters truncated?


Thanks,
nimdhar
Hi,
  I am not able to understand why the below code is giving the Id correct  for the  first alert box and  giving null when trying to access using DOM.

<apex:page StandardController="Account">

<script>
function twistsections(id)
{
alert(id);
alert(document.getElementById(id));
document.getElementById(id).style.display="none";
}
</script>
<apex:form>
<apex:pageBlock title="Customer Information" id="block" mode="edit">
<apex:pageBlockSection title="Account Information" id="sample"   onclick="twistsections('{!$component.block.sample}');">
<apex:inputField id="accountName" value="{!account.Name}" />
<apex:inputField id="accountSite" value="{!account.Site}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Thanks,
nimdhar
Hi,

I am trying to expand and collapse a pageBlockSection. Documentation  says  it has collapsible property and default value is true. But it is not working     Is there any other property? 

Thanks,
nimdhar
Hi,

I am calling a web method from a javascript function in a visual force page. But that function is not getting called. Below is the  code

This is in my visual force page calling the javascript function
<apex:outputlink onclick="setLeadLocation('{!$CurrentPageReference.parameters.leadid}','{!location.id}');"> Attach </apex:outputlink>

This is my javascript function which calls the webmethod
function setLeadLocation(leadid,locationid)
{
   sforce.apex.execute('LeadServices','assignLocationToLead', {leadId:leadid,locationId:locationid});
 }

This is my web method

global class LeadServices
{
 
Webservice static void assignLocationToLead(ID leadId, ID locationId) {
   
      
Lead lead = [select Id from Lead where Id=:leadId];
      
lead.Location__c = locationId;
       
update lead;
       
return;
}

Can anyone tell is this not possible from a visual force page?

Thanks,
Nimdhar
Hi,
I have the following code that displays all the locations iterating through the locationresults. The commandLink sends the correct id to the controller only for the first record.  For the rest of the records it sends null. I think it is set only once. Can anyone tell me how to do this?
<apex:pageblocksection title="Locations" id="locationresults">
   <apex:pageblocklist value="{!locationresults}" var="location" rendered="{!NOT(ISNULL(locationresults))}">
                    <apex:column headerValue="Name">
                               <apex:outputlink value="/{!location.id}">{!location.name}</apex:outputlink>
                      </apex:column>
                       <apex:column value="{!location.Address__c}" />
                        <apex:column value="{!location.City__c}" />
                         <apex:column value="{!location.State__c}" />
                          <apex:column value="{!location.ZipCode__c}" />
                            <apex:column>
                                   <apex:commandLink value="Attach"  action="{!attach}" oncomplete="closewindow()">
                                           <apex:param assignTo="{!myclient}" value="{!location.id}"/>
                                     </apex:commandLink> 
                               </apex:column>
                                </apex:pageblocklist>
                        </apex:pageblocksection>

Thanks,
Nimdhar
Hi,
 
I have a pop up window which popups a visual force page. I am trying to close this popup and reload my original page when some action is done as follows

<script>
 function closeSearchWindow()
 {
    window.close();
 }
</script>
<apex:commandLink value="Attach" action="{!attach}"  onclick="closeSearchWindow();">
      <apex:param assignTo="{!myclient}" value="{!location.id}"/>
</apex:commandLink>

But this is not working. Is there any other way to do this.

Thanks,
Nimdhar


Message Edited by nimdhar on 04-29-2008 07:22 AM
Hi,
<apex:commandLink  value="attach" action="{!attach}">
 <apex :param assignto="{!test}" value="{!location.id}"/>
</apex:commandLink>

And I have getter and setter methods in my controller. This works fine. But when I replace it with commandButton it is not working.

Thanks,
Nimdhar
Hi,

I am sending parameters using a command button to a controller as follows
 <apex:commandButton value="Attach" action="{!attach}" >
 <apex:param name="leadId" value="{!$CurrentPageReference.parameters.q}" />
 <apex:param name="locId" value="{!location.id}" />
 </apex:commandButton>


I am trying to access those parametrs in the controller by having a get and set method. But it is not working. Can anyone suggest me how to access those parameters in a controller.

Thanks,
Nimdhar
Hi,

I have a S-control that invokes the visual force page as follows
window.open ("/apex/searchLocation?q={!Lead.Id}","myWindow",' status=1,height=600, width=1000,menubar=no,toolbar=no');

I am passing a query parameter lead id to the visual force page. when I accessed the lead id it is passing or getting the id with last three letters truncated
   <apex:commandButton value="Attach" action="{!attach}" onclick="alert('{!$CurrentPageReference.parameters.q}');"/>

Lets say the actual lead id is 00QT0000004RErUMAW. I am getting 00QT0000004RErU. Why is that last three letters truncated?


Thanks,
nimdhar
Hi,
  I am not able to understand why the below code is giving the Id correct  for the  first alert box and  giving null when trying to access using DOM.

<apex:page StandardController="Account">

<script>
function twistsections(id)
{
alert(id);
alert(document.getElementById(id));
document.getElementById(id).style.display="none";
}
</script>
<apex:form>
<apex:pageBlock title="Customer Information" id="block" mode="edit">
<apex:pageBlockSection title="Account Information" id="sample"   onclick="twistsections('{!$component.block.sample}');">
<apex:inputField id="accountName" value="{!account.Name}" />
<apex:inputField id="accountSite" value="{!account.Site}"/>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

Thanks,
nimdhar
Hi,

I am trying to expand and collapse a pageBlockSection. Documentation  says  it has collapsible property and default value is true. But it is not working     Is there any other property? 

Thanks,
nimdhar