• Vijay Raut
  • NEWBIE
  • 183 Points
  • Member since 2006

  • Chatter
    Feed
  • 7
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 14
    Questions
  • 113
    Replies

Hi there,

I am trying to create a trigger on a custom object "VerwijderFnc__c" what deletes records in another custom object "Functionaris__c"

 

process is: insert a record into VerwijderFnc__c and get the Id from the Functionaris__c to delete those Functionaris__c record(s).

Sometimes i get more then 20 records as a result! and that is too much!

 

so i try to make this trigger bulksafe .... But i can't get ik to work for me !

This was 1e my code for the trigger: (NOT BULKSAFE)

 

trigger deleteFromFunctionaris on VerwijderFnc__c (before insert) {
     for(VerwijderFnc__c verwijdertabel: Trigger.new){
         for (Functionaris__c fs: [SELECT Id FROM Functionaris__c WHERE mskey__c = :verwijdertabel.MSkey__c]){
            //Delete all the Functionaris__c entries with given mskey__c
            delete fs;
         }
     }
}

 

then i tried something like: (BUT ALSO GIVES TOO MANYDML STATMENTS)

 

trigger deleteFromFunctionaris on VerwijderFnc__c (before insert) {

 

Map<String, VerwijderFnc__c> fncMap = new Map<String, VerwijderFnc__c>(); for (VerwijderFnc__c fnc : System.Trigger.new) {  if ((fnc.mskey__c != null) && (System.Trigger.isInsert || (fnc.mskey__c != System.Trigger.oldMap.get(fnc.Id).mskey__c))) {

fncMap.put(fnc.mskey__c, fnc);

}

}

 

for (Functionaris__c func : [SELECT Id FROM Functionaris__c WHERE mskey__c IN :fncMap.KeySet()]) { delete func;

}

}

 

 

 

!! Help !!

 

 

 

Message Edited by Streepeye on 03-31-2009 05:56 AM

All,

 

Please let me know, how do I link Contact to an Account through webservices API.

 

I am able to create contact through API, but not able to link to an Account.

 

Tried updating setContacts in Account(to existing account), after creating the contact. But, no luck.

 

Any pointers are appreciated.

 

Thanks.

I have a trigger which prepopulate a filed before insert, but it does not work.

 

 

trigger GetLastAssocID on Obj__c (before insert) {

 

for (Obj__c ori: System.Trigger.New){

 

  if (ori.ObjName__c == ''){

  ori.Obj_ID__c = [Select Obj_ID__c from

                         Obj__c

                         Order by Obj_ID__c Desc

                         Limit 1];

  }

 }

}

 

 

Obj__c is an object I created and Obj_ID is a number(Double) field.

  • January 29, 2009
  • Like
  • 0

Hello,

 

I've written a trigger on a custom object that updates a picklist field on a Contact record, and I have Person Accounts enabled.  The trigger works, updating the Contact only under the right circumstances.  I'm now trying to write a test method to move this into Prod and am having trouble updating a Contact record in the method.   Before the trigger is even fired I'm trying to set up my Contacts with the right information. 

 

Here is what my test method looks like so far, just setting up the initial Person Account contact:

 

// create person account by filling in the Account's lastname field.
Account a1 = new Account();
a1.lastname = 'Test1';
insert a1;
// now pull up Contact to set the value of my picklist field
Contact c1;
c1 = [select id, courses_completed__c from Contact where accountid = :a1.id];
c1.courses_completed__c = 'POE';
update c1;

 

At this point my method throws up a DML error on the update:

 

System.DmlException: Update failed. First exception on row 0 with id 003S0000002u36xIAA; first error: INVALID_CROSS_REFERENCE_KEY, Can not select a contact: [AccountId]

 

Any ideas on how to update a Person Account's contact fields in the test method?  I don't think I can update the contact field on my Account object - it comes up as invalid field when I access a1.courses_completed__c or a1.personcourses_completed__c.

 

Any thoughts would be much appreciated.  The API docs say you can't create or delete a Person Account type Contact but I should be able to update it.  The fact that my trigger works when I test it out in the UI points to an issue with the test method rather than my trigger coding.

 

Thanks!

  • January 29, 2009
  • Like
  • 0
We are trying to automatically assign lead ownership based on our database of Zip Codes. Since there are so many zip codes, we can't manually put them in the native assignment rules.

I'm trying to write a trigger to reassign the Lead Owner but this is my first one and I can't seem to get it right. Here's what I have:

Code:
trigger LeadAssignmentTrigger on Lead (before insert) 
{
    List<Lead> leadsToUpdate = new List<Lead>();

    for (Lead lead : Trigger.new)
    {
     
      if (lead.PostalCode != NULL)
      {
          // Find the sales rep for the current zip code
          List<Zip_Code__c> zip = [select Sales_Rep__c from Zip_Code__c 
where Name = :lead.PostalCode limit 1];


// if you found one
if (zip.size() > 0)
{
//assign the lead owner to the zip code owner
lead.Owner = zip.Sales_Rep__c; // This is my problem line

leadsToUpdate.add(lead);

}
}

}

// update the records
try
{
update leadsToUpdate;
}
catch (DmlException dm)
{
leadsToUpdate.addError('There was a problem reassigning the Lead Owner');
}

}

I have bolded the problem line. All I want to do is to assign the User from my Zip Code object (just a list of zip codes and user lookups) to the current lead creation on any given Lead insert.

Can someone please tell me what the correct syntax should be?

Thanks
Hi,

I have a 'before insert trigger' on Opportunity. The trigger contains an SOQL select query which returns(may or may not) one record and assigns to an Opportunity variable.
The query statement is:
"Opportunity Opp_variable = [SELECT id,Counter__c,AccountId FROM Opportunity where (AccountId=:New_record.AccountId AND Counter__c!=null) ORDER BY Counter__c DESC LIMIT 1];"

After this statement I have "if(Opp_variable!=NULL)..statements",
But I get the Error message:
"System.QueryException: List has no rows for assignment to SObject"
This is caused because there is no record satisfying my query conditions.. But it should have returned NULL.. ?

Why Am I getting this error..!! SOQL query cannot return null value??

How can I sove this issue..? Please help me

Thanks in Advance..
Krishna
Hi all,
 
I have been trying to convert a lookup field to master detail relation field, while we were changing the field type we encountered an error message saying
"There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Generic Exception Creator".
 
We also tried creating a new Master-Detail Field instead of converting the existing one, but in this case we encountered the following error message
"You cannot create a new Master-Detail relationship on an existing custom object if records already exist. You must first create a Lookup relationship, populate the lookup field with data in all records, and then change the relationship type to Master-Detail. "
Then we made a lookup field and populated all the recods with value in that field and then tried converting it to Master-Detail Relation but again encountered the first error message..
"There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Generic Exception Creator".
 
We have also deleted all the reports which use that lookup Field but still were'nt able to change it to Master Detail Relation
If any one has any knowledge regarding the same, Please do let us know.
 
Thanks in Advance,
Bharat.
 

Hi,

 

We have one application which calls external web services in apex code. It is working fine and i am getting response back.

 

Now we are looking for implementing compression using "setCompressed()" method / gzip compression. We have set compression using this method and now i am getting "BAD REQUEST - 400" response from web service. Any thoughts?

 

Thanks in advance.

 

V.R.

Hi All,

We are having "Transform__c" field on User Object. We are having problem in Owner relationship in following queries.

Select count() from event e where e.Owner.Transform__c = 1

It gives error saying that
"No Such column 'Transform__c' on entity 'Owner'. If you are attempting to use custom field, be sure to append '__c' after the custom field name. Please reference your WSDL or describe call for appropriate names".

But we are having 'Transform__c' field on User (Owner) and following query is working fine.

Select count() from Account a where a.Owner.Transform__c = 1

I was just checking and this type of relationship query is working fine for Account, Contact, Opportunity,... etc object.
But i am getting error for above query when i am trying to get count for Task, Event, Lead,..etc

Does anyone come across such type of problem.

I am not sure what is different in Task, Event, Lead object compare to Account, Contact, Opportunity object

Thanks in advance.
V.R.


Message Edited by Vijay Raut on 09-25-2008 12:25 PM
Hi All,

In my Apex Code, I am having Number fields. If those fields has the data greater than 9,999,999.99 then it will automatically convert to the Exponential value (Like in case 19,999,999.99 would e replaced to 1.999999999E7).

But i want to keep this value intact and not want auto conversion to exponential value.

Is there any easy way to acheive this?
What i thaught is use of String split and some logic. but is there any better way to acheive same.

Thanks in Advance.

V.R.
Hi All,

Is it possible to login with another user in Apex Trigger.

My Use Case:
I want to deleting Account in UPDATE trigger based on some conditions. But when account get deleted, it will be available in SFDC Recycle bin of that User. I want to hide that record from recycle bin of that user.

So i am thinking of, before deleting, i will login with some dummy user and perform the delete operation. So that deleted record will be available to the dummy user's recycle bin.

Or is there any function available to clear SFDC recycle bin from Apex?

Any help on this would be appreciated.

Thanks
V.R.
Hi,

As per SFDC Docs, Query call in Scontrol retrives 200 records. If we are going to retrive more than 200 records then querymore function is used.

I am using same query and queryMore using done flag.

But in my case, query call retrives more than 200 records and as I am updating those retrived records, update call has limit of 200 records in one call (Hence getting exception in SControl).

So is there any change in  query and query more call behavior or i am missing some thing?

Thanks
V. R.
Hi,
 
According to Apex Document, Number of records processed as a result of DML statement (Number of DML Rows) is 100. But this limit scales with trigger batch size. Means if i pass 200 records in trigger then this limit will be 100 * 200 = 20,000.
 
Strange thing, It is working fine in case of the Insert DML statement but for delete DML Statement, it throws exception for Trigger batch of more than 100 records.
 
I have attached two trigger code. One is working properly (having insert DML) with batch more than 100. And another throwing exception (having Delete DML).
 
This Code Works Properly:
 
Code:
trigger MFD_Archive on Account (before delete) 
{
 try  
 {
  String MARK_FOR_DELETE_ADMIN = '005T0000000ifGGIAY';
  String BUSINESS_ACCOUNT_RECORDTYPEID = '01250000000DJZIAA4';
  
  for ( Account [] sourceAccounts : [Select Id, Name, MFD_OldOwnerId__c, OwnerId,
    RecordTypeId, MFD_IsArchived__c from Account
    where MFD_IsArchived__c = :false and Id IN :Trigger.oldMap.keyset()
    and RecordTypeId = :BUSINESS_ACCOUNT_RECORDTYPEID])
  {
   Account[] targetAccounts = sourceAccounts.deepClone(false);
   
   for(Integer i = 0; i<targetAccounts.size(); i++)
   {
    targetAccounts[i].MFD_SourceId__c = sourceAccounts[i].Id;
      targetAccounts[i].MFD_OldOwnerId__c = targetAccounts[i].OwnerId;
      targetAccounts[i].OwnerId = MARK_FOR_DELETE_ADMIN;
      targetAccounts[i].MFD_IsArchived__c = true;
   }
  
   insert targetAccounts;   
  
  }
    
    for ( Account [] sourceAccounts : [Select Id, FirstName, LastName, MFD_OldOwnerId__c, OwnerId,
      RecordTypeId, MFD_IsArchived__c from Account
      where MFD_IsArchived__c = :false and Id IN :Trigger.oldMap.keyset()
      and RecordTypeId != :BUSINESS_ACCOUNT_RECORDTYPEID])
  {
   Account[] targetAccounts = sourceAccounts.deepClone(false);
   
   for(Integer i = 0; i<targetAccounts.size(); i++)
   {
    targetAccounts[i].MFD_SourceId__c = sourceAccounts[i].Id;
      targetAccounts[i].MFD_OldOwnerId__c = targetAccounts[i].OwnerId;
      targetAccounts[i].OwnerId = MARK_FOR_DELETE_ADMIN;
      targetAccounts[i].MFD_IsArchived__c = true;
   }
  
   insert targetAccounts;   
  
  }
 }
 catch(Exception e)
 {
  // TODO - Log Error to Integration_Error__c object
   System.debug('Exception in MFD_Archive Trigger' + e.getMessage()); 
 }
}

 Following code throws Exception:
 
Code:
trigger MFD_Undelete on Account (after undelete) 
{
 try 
 {
  for ( Account[] archivedAccts : [select Id from Account
    where MFD_IsArchived__c = :true and MFD_SourceId__c IN :trigger.newMap.keyset()])
  {
   System.debug('Number of Archived Accounts ' + archivedAccts.size());
   
   if(archivedAccts.size()>0)
   {
    delete archivedAccts;
   }
  }
 }
 catch(Exception e)
 {
  System.debug('Exception in MFD_Undelete Trigger' + e.getMessage()); 
 }
}

 
Is anyone come accross this scenario? Or I am missing some thing in my code then please reply me.
 
Thanks in Advance.


Message Edited by Vijay Raut on 12-06-2007 10:50 AM
Hi ,
 
I am using Eclipse toolkit. I am not able to run the tests from eclipse.
Its giving me following error, when tried to do so.
 
ERROR: Unable to run tests
 
com.salesforce.toolkit.remote.SalesforceConnectionException: Failed to send request to https://tapp0-api.salesforce.com/services/Soap/s/10.0/190300D500000006hSY
 at com.salesforce.toolkit.remote.ApexExecuteService.runTests(ApexExecuteService.java:201)
 at com.salesforce.toolkit.remote.ApexExecuteService.runClassTests(ApexExecuteService.java:89)
 at com.salesforce.toolkit.actions.RunTestsAction$1.run(RunTestsAction.java:68)
 at org.eclipse.jface.operation.ModalContext.runInCurrentThread(ModalContext.java:369)
 at org.eclipse.jface.operation.ModalContext.run(ModalContext.java:313)
 at org.eclipse.jface.dialogs.ProgressMonitorDialog.run(ProgressMonitorDialog.java:495)
 at org.eclipse.ui.internal.progress.ProgressMonitorJobsDialog.run(ProgressMonitorJobsDialog.java:268)
 at org.eclipse.ui.internal.progress.ProgressManager.run(ProgressManager.java:1123)
 at com.salesforce.toolkit.actions.RunTestsAction.run(RunTestsAction.java:82)
 at org.eclipse.ui.internal.PluginAction.runWithEvent(PluginAction.java:256)
 at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:546)
 at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:490)
 at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:402)
 at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:66)
 at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:938)
 at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3682)
 at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3293)
 at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2389)
 at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2353)
 at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2219)
 at org.eclipse.ui.internal.Workbench$4.run(Workbench.java:466)
 at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:289)
 at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:461)
 at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
 at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:106)
 at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:169)
 at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:106)
 at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:76)
 at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:363)
 at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:176)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:508)
 at org.eclipse.equinox.launcher.Main.basicRun(Main.java:447)
 at org.eclipse.equinox.launcher.Main.run(Main.java:1173
 
If any one come accross same problem and able to resolve it, then please reply me.
 
Thanks
Vijay Raut
Hi All,
 
I am new to Forecasting supported in sfdc.
I want to know in which sfdc entity Salesforce stores the information about forecasting.
 
I mean to say in which entity... the data for Opportunity Forecast , user forecast is stored.
 
Kindly reply to this post if anyone know about this.
 
Thanks in Advance
 
Regards
Vijay Raut
Hi,
 
In my personal setting i have unchecked Send Apex Warning Emails.
 
Though i am getting the Exception Email when trigger fire and get some error msg on duplicate record.
 
So please suggest me right way to block the email when there is exception in Trigger.
 
Thanks in Advance
 
Regards
Vijay Raut
Hi All,
 
I am facing following problem in Email2Case Agent.
If anyone having any idea about same ...... then please do reply to this blog.
 
Following is the error snapshort....
 
2007-06-07 18:15:14,138 [Thread-1] ERROR Unable to connect to mail service.
Service: xxxx.xxx.xxxx
User: xxxx.xxxx.xxxx
Message: Connection timed out: connect;
  nested exception is:
        java.net.ConnectException: Connection timed out: connect
 
Thanks in Advance
Hi ,
 
In my account i am baving two cutome fields as picklist (like Market and Segment).
Segment is dependant on the Maket.
I have used the DescribeSObject function, which returns me the all picklistvalues for Market and Segment.
But i want to get only those values of Segment which are available for selected Market in my SControl page.
 
So is there any way to find out how to get dependant picklist values according controlling picklist value selected.
 
If anyone having clue about same then please reply to this post.
 
Thanks in Advance.
Hi ,
I have done the Join of Account and Contact and retrived data from them.
 
But i want to put that data in into Array.
 
Like for one Account there are many contacts. So i have tried to take the fields as follows, but able to get only account fields and for contacts fields it is giving me error.
 

account_arr[account_cnt][0]=dynaBean.get("Id");

account_arr[account_cnt][1]=dynaBean.get("Name");

account_arr[account_cnt][2]=dynaBean.get("Site");

But in the QueryResult i am having all the data of contact. Its juct i m not getting way to use get method.

So please anyone having idea about how to overcome this then reply to this post.

Thanks in Advance

Hi guys....
I want to create SControl which show me the list of Product based on some criteria.
 
And then if i select on some product name from select list then it shuld show me the conole at bottom which displays the information of that product. ( Something like Console provided in Winter release).
 
So does anyone having idea of how to accomplish that in SControl?
 
Or can i use the standard product console in this SControl?
 
Please reply to this.
 
Thanks in advance.

We have an Apex web service that calls out to a RESTful web service with the Http.send() method.

 

When the URL is http (i.e. non-secure http), all works great. But, if we change only the protocol to https the response is a "Bad Request" error code 400. 

 

The strange thing is that it works if we issue the Http.send() command a second time right after getting the failure, i.e. the Http.send() fails the first time, but succeeds if called again.

 

Looking at the debug log's time stamps, we can see that the failure response is coming back in 0 time, i.e. it looks like the request isn't really going out at all to the remote server.

 

Thanks

Message Edited by jbjb on 05-18-2009 05:18 PM
Message Edited by jbjb on 05-19-2009 09:33 AM
  • May 19, 2009
  • Like
  • 0

Salesforce automatically emails the sys admin whenever a exception error or someother error occurs.

1. Is there a way to make salesforce email the debug log to more than one person?

2. Is there a way  to make salesforce email the debug log when a certain trigger or apex class is fired? 

Could someboby please let me know why I'm getting this error?

 

Error: Compile Error: Invalid field CommentBody for SObject Case at line 8 column 23 trigger

 

UpdateCaseCom on Task (after insert)

{

String LastCaseComment;

Datetime DateFilter = Datetime.now().addSeconds(30);

for (Case dc : [Select id, CommentBody, CreatedDate from CaseComment where CreatedDate >: DateFilter])

{

   LastCaseComment = dc.CommentBody;

}

r insert) { String LastCaseComment; Datetime DateFilter = Datetime.now().addSeconds(30); for (Case dc : [Select id, CommentBody, CreatedDate from CaseComment where CreatedDate >: DateFilter]) { LastCaseComment = dc.CommentBody; }
  • April 01, 2009
  • Like
  • 0

Could somebody please explain to me why I'm getting this error? I want to extract the Comment from the CaseComment entity if was just recently added to the ase

 

 
Error: Compile Error: Variable does not exist: cc.CommentBody at line 9 column 23 

 

trigger UpdateCaseCom on Task (after insert)

 {

    String LastCaseComment; Datetime DateFilter = Datetime.now().addSeconds(-30);

    for (CaseComment cc : [select id, CommentBody, CreatedDate from CaseComment where CreatedDate >: DateFilter]);

    {

 

            LastCaseComment = cc.CommentBody;

     }

    for (Task t : [select Description, Type, Subject, isclosed, status, WhatId from task where Id in :Trigger.new]) {

  • April 01, 2009
  • Like
  • 0

Hi there,

I am trying to create a trigger on a custom object "VerwijderFnc__c" what deletes records in another custom object "Functionaris__c"

 

process is: insert a record into VerwijderFnc__c and get the Id from the Functionaris__c to delete those Functionaris__c record(s).

Sometimes i get more then 20 records as a result! and that is too much!

 

so i try to make this trigger bulksafe .... But i can't get ik to work for me !

This was 1e my code for the trigger: (NOT BULKSAFE)

 

trigger deleteFromFunctionaris on VerwijderFnc__c (before insert) {
     for(VerwijderFnc__c verwijdertabel: Trigger.new){
         for (Functionaris__c fs: [SELECT Id FROM Functionaris__c WHERE mskey__c = :verwijdertabel.MSkey__c]){
            //Delete all the Functionaris__c entries with given mskey__c
            delete fs;
         }
     }
}

 

then i tried something like: (BUT ALSO GIVES TOO MANYDML STATMENTS)

 

trigger deleteFromFunctionaris on VerwijderFnc__c (before insert) {

 

Map<String, VerwijderFnc__c> fncMap = new Map<String, VerwijderFnc__c>(); for (VerwijderFnc__c fnc : System.Trigger.new) {  if ((fnc.mskey__c != null) && (System.Trigger.isInsert || (fnc.mskey__c != System.Trigger.oldMap.get(fnc.Id).mskey__c))) {

fncMap.put(fnc.mskey__c, fnc);

}

}

 

for (Functionaris__c func : [SELECT Id FROM Functionaris__c WHERE mskey__c IN :fncMap.KeySet()]) { delete func;

}

}

 

 

 

!! Help !!

 

 

 

Message Edited by Streepeye on 03-31-2009 05:56 AM

Hello,

 

Is it possible to write an APEX trigger or S-Control that would merge duplicate records based on certain duplicate rule.

 

For example, is it possible to automatically merge records upon insert or update if a lead's full name and website match that of a contact's full name and contact's account website?

 

-Thanks

Hi there,

 

I used the Solution titled "How do I use formula fields to link to files on a network" and setup fields in my Sandbox per the instructions.  My hyperlink field works perfectly well in Internet Explorer, but nothing happens in Firefox.  The only advice from Salesforce.com Support has been to optimize my Firefox settings, which I did and the behavior hasn't changed.

 

Any ideas as to why this works in IE 7, but not Firefox 3?

 

Kristin

Message Edited by flewells on 03-26-2009 09:07 AM

Hi All,

 

 I am new in Apex trigger . I am facing problem with bulk data .

I am using a trigger that takes data from one Custom Object and copy in Account object.

It is working fine only for 5 rows I am trying to import more then 5 rows , its shows 

For Insert data in Custom object , I am using Data Loader.

 

System.Exception: Too many SOQL queries 

 

Pls correct the code ...

 

 

trigger accountand_invoice_update on STG_AR_INVOICE__c (after insert) {
 
  List< Account> aList = new List<Account>(); 
  List<STG_AR_INVOICE__c> bList=new List<STG_AR_INVOICE__c>(); 
  STG_AR_INVOICE__c sgtUpd;
 

  Account b;
 
  for (STG_AR_INVOICE__c stg : Trigger.new ){       
         Account[] acc = [select id,name,company_code__c,bu_code__c from account Where Name =:stg.Customer_Name__c and Company_Code__c =:stg.Company_Code__c and Bu_Code__c =:stg.Bu_Code__c];
         if(acc.size()>=1){
         for(integer i=0;i<acc.size();i++){
          b=acc[i] ;
          b.Credit_Limit__c=stg.Credit_Limit__c;
          b.Credit_Available__c=stg.Credit_Available__c;
          b.Net_Credit_Available__c=stg.Net_Credit_Available__c;
          b.OutStanding_Orders__c=stg.OutStanding_Orders__c;
          b.Out_Standing_Net_AR__c=stg.OUT_STANDING_NET_AR__c;
          b.STATUS__c='OLD';        
          aList.add( b );
         
          STG_AR_INVOICE__C [] stgexist=[SELECT ID,NAME,COMPANY_CODE__c,CUSTOMER_NAME__c,CUSTOMER_KEY__C FROM STG_AR_INVOICE__C
                 WHERE BU_CODE__c =:b.BU_CODE__C AND CUSTOMER_NAME__c =:b.NAME AND COMPANY_CODE__c =:b.COMPANY_CODE__c];
         if(stgexist.size()>=1){       
          for(integer j=0;j<stgexist.size();j++){
             sgtUpd=stgexist[j];            
             sgtUpd.Customer_key__c=b.Id;             
             bList.add(sgtUpd); 
          }
         }
         }
         
         }else{
           b = new Account();
           b.Name =stg.CUSTOMER_NAME__c;
           b.COMPANY_CODE__c=stg.COMPANY_CODE__c;
           b.BU_CODE__c=stg.BU_CODE__c;              
           b.Credit_Limit__c=stg.Credit_Limit__c;
           b.Credit_Available__c=stg.Credit_Available__c;
           b.Net_Credit_Available__c=stg.Net_Credit_Available__c;
           b.OutStanding_Orders__c=stg.OutStanding_Orders__c;
           b.Out_Standing_Net_AR__c=stg.OUT_STANDING_NET_AR__c;
           b.STATUS__C='NEW';
          
           aList.add(b);
         }
    }
     upsert aList; 
     update bList;  

 

 

Thanks 

  • March 16, 2009
  • Like
  • 0
We are using the future annotation to raise governor limits for Apex Managed Sharing recalculations on object updates.  This works well when doing live testing through the UI, but after writing test methods, it appears that the testing routine does not apply the appropriate increase to the governor limit for soql queries that takes place in the 'live' environment when using the UI.  See below for two snippets of the debug log placed inside the future annotated method.  The first shows the number of queries avaialable when the original trigger is part of a test routine, the second when the same trigger is fired 'for real'.

---

Test class debug results:

20090223145031.385:Class.ManagedSharing.queueRecalcProperty: line 14, column 9: Passing through the future annotated method, 0 of 20 queries used.

...

Eventual error:

20090223145155.055:Class.ManagedSharing.recalcEsrEvent: line 349, column 70: returning from end of method public static void addRegionClientGroups(MAP:Id,Id, MAP:Id,Id) in 17 ms
System.Exception: Too many SOQL queries: 21

---

UI debug results:

20090223145235.009:Class.ManagedSharing.queueRecalcProperty: line 14, column 9: Passing through the future annotated method, 0 of 100 queries used.

Evenual successs:
Status Success

Hey Guys,

             I want to know that is there any way to get Organization's server url using Apex (neither via Visualforce nor via Site, let Site is disabled or let I want to use that in Trigger).

 

eg. https://na6.salesforce.com/home/home.jsp

in this server url would be https://na6.salesforce.com/

 

Thankx

Hi,

 

I am not able to create vote object in trigger or apex class to retreive records.

I am trying to fetch the records from Vote Object as shown below..
Vote[] vote = [select id, createdById from Vote];

I am getting an error message like this
Illegal assignment from LIST:SOBJECT:Vote to Vote

If we get records into SObject, we are not able to convert SObject to Vote.

This problem we are facing in sandbox(cs1).

 

 

Thanks,

Soujanya.

All,

 

Please let me know, how do I link Contact to an Account through webservices API.

 

I am able to create contact through API, but not able to link to an Account.

 

Tried updating setContacts in Account(to existing account), after creating the contact. But, no luck.

 

Any pointers are appreciated.

 

Thanks.

I have a trigger which prepopulate a filed before insert, but it does not work.

 

 

trigger GetLastAssocID on Obj__c (before insert) {

 

for (Obj__c ori: System.Trigger.New){

 

  if (ori.ObjName__c == ''){

  ori.Obj_ID__c = [Select Obj_ID__c from

                         Obj__c

                         Order by Obj_ID__c Desc

                         Limit 1];

  }

 }

}

 

 

Obj__c is an object I created and Obj_ID is a number(Double) field.

  • January 29, 2009
  • Like
  • 0

I need to identify for a given case whether the owner of the case is a queue or an agent.

 

When I query the CASE table for OwnerId field, it gives me different string values and I was hoping to identify how to differentiate between whether this OwnerId references a Queue or if it references an agent.

 

Any clues?

 

 

Sorry for the newbie question, but I've added an autonumber field to my opportunity page, and while it works great assigning numbers to new opportunities, I can't for the life of me figure out how to retroactively have it number my existing records.  Any help would be appreciated.  Thanks very much!
I have written an S-Control which switches Account owners to different owners. I would also like to be able to switch any manual shares for accounts and opportunities. I don't seem to be able to create new rows in either the AccountShare or OpportunityShare show because the RowCause field is readonly.

Is there a better way to switch manual AccountShares / OpportunityShares to a different user via the API?


Hi all,
 
I have been trying to convert a lookup field to master detail relation field, while we were changing the field type we encountered an error message saying
"There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Generic Exception Creator".
 
We also tried creating a new Master-Detail Field instead of converting the existing one, but in this case we encountered the following error message
"You cannot create a new Master-Detail relationship on an existing custom object if records already exist. You must first create a Lookup relationship, populate the lookup field with data in all records, and then change the relationship type to Master-Detail. "
Then we made a lookup field and populated all the recods with value in that field and then tried converting it to Master-Detail Relation but again encountered the first error message..
"There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Generic Exception Creator".
 
We have also deleted all the reports which use that lookup Field but still were'nt able to change it to Master Detail Relation
If any one has any knowledge regarding the same, Please do let us know.
 
Thanks in Advance,
Bharat.
 
Hi,
 
I know this question is a straight forward but still if anybody has any clue then please let us know.
 
We are trying to insert data in AccountShare table and are facing problem. While trying to insert data in AccountAccessLevel field, API is throwing the following error message:
 

Message: Account Access: bad value for restricted picklist field: Read Only\nStatus Code:INVALID_OR_NULL_FOR_RESTRICTED_PICKLIST\nFields: System.String[]\nID: \n\n

 

We are trying to insert value which reads as "Read Only" without double quotes.

 

We checked the field properties and found that it is restricted picklist and filterable. Is there any way we can insert data in this field or leave it blank.

 

Thanks in advance.

 

Regards,

Manas.