• Harmpie
  • NEWBIE
  • 474 Points
  • Member since 2007
  • Force.com Fan
  • Appsolutely


  • Chatter
    Feed
  • 17
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 25
    Questions
  • 276
    Replies

Hi All, 

I am trying to get used to writing triggers doing a fairly simple trigger but I am stuck. 

I am trying to write a trigger where te scenario is:

  1.  Two objects Account and Opportunity
  2. Account field Renewal Term (Renewal_Term__c)that is picklist of years annual through sexennial
  3. Opportunity Field Contract Length ( Contract_Length__c ) that is a picklist of values 1-6
  4. I believe that there is a master-detail relationship between Account and Opportunity
  5. When an Opportunity is Closed Won, Renewal Term should update to the corresponding contract length from the Opportunity, provided that Renewal Term isn't already populated. 

Embarrassingly, all I have so far is:

 

    

trigger updatelength on Account (after update) {
    Opportunity__c[] opptoupdate = new Opporunity__c[]{};
        for(account c: trigger.new){
            for(Opportunity__c cp: [select id,name,Contract_Length__c from Opportunity__c where Account = :c.id]{

            }
        }
}


Would anyone mind helping me out?

Thanks!

Hi,

 

today we've tried to configure a batch DataLoader process. It failed to pick up the config file, no matter how we tried. Is this a know issue with version 25? We installed 22 and 23 on the same environment, with exactly the same config (copied the one we build earlier today for version 25), and it worked fine.

 

Thanx in advance!

 

Marco

hi i have written a controller which populates the data when it loads the page in a editable mode and when the user edits the felds and click on save the data stored in custom object.I am trying to know how can we assign test data to this controller since it is retrieved from another page. cna anybody help me in writing a test class for this scenario.

 

 

global with sharing class preferenc 
{

    public PageReference cancel() {
        PageReference p = Page.user_preference;
         p.setRedirect(true);
          return p;
    }


    

 public string guestid;
    public guestuser__c gus{get;set;}

    public preferenc() 
    {
    this.guestid=ApexPages.currentPage().getParameters().get('paramID');   
        if(guestid!=null||guestid!='')
        {
            getdetails(guestid); 
        }   

    }

    
    
    public void getdetails(string guestid)
    {
        List<guestuser__c> guests=[select id,Email__c,Phone__c,Title__c,Email_Optout__c,A_H_interests__c,After_Markets_interests__c,Construction_interests__c,D_O_interests__c,Energy_interests__c,Environmental_interests__c,Financial_Enterprises_interests__c,Healthcare_interests__c,Manufacturing_interests__c,Property_interests__c,RealEstate_interests__c,Technology_interests__c,Windstorm_notification_interests__c from guestuser__c where id=:guestid];
        if(guests.size()>0)
        {
            gus=guests[0];
        }
        else
        {
            
        }
    }
    public PageReference save()
    {
        
          update gus;
          PageReference t = Page.thanks;
          t.setRedirect(true);
          return t;  
    } 
    
    static testMethod void testpreferenc()
    {
      
     
      preferenc controller = new preferenc();
     
      controller.save();    
      controller.cancel();
    }
    
}

 

 

I'd like to compare Object type using "Event.What.type" in Trigger method.
Then I wrote some code. but, it didn't work rightly.

 

It rather seems "Event.What" was null.
How should I do that it work correctly. or please tell me other way.

 

Here is the code.

trigger TestTrigger on Event (after insert) {

for (Event rec : Trigger.new) {
// "rec.What" is null...
if (rec.What.type == "ownCustonObject__c") {
}
}
// ... some code

}

 

Would someone please reply this.

 

 

Mitsutaka.

One of the great things about s-controls was the ability to navigate to a new edit screen for a new record and fill in some of the fields automatically.

 

This could be acheived with a single line (or so) of code, but had drawbacks when any of the info had non-alphanumeric characters in it.

 

I was wondering if there was an easy way to do it in Visualforce. Currently, it seems that you have to produce mark-up for the record screen and produce apex code.

 

With thanks,

Andy

Hi :

   Is there a way to hide the Edit button when the Status equals complete ....

Thanks

MMA

Hi all,

 

I have a custom object Deal with Deal_Location child objects. I created a custom button 'Replace Deal Locations' as a List Button on Deal_Location and placed this button in the Deal screen, located with the Deal_Location related list.

 

I created a custom VisualForce page that opens when the button is clicked, displaying the selected Deal_Locations for further processing. 

 

However, I'd like to do a quick check when a user clicks the button, on whether any Deal_Locations were actually checked. This can be done e.g. with the following Javascript&colon;

 

var records = {!GETRECORDIDS($ObjectType.Deal_Location__c )};

if (records[0] == null) {
alert("Please select at least one Deal Location.") }
else {
window.parent.location.href='/apex/Deal_Location_Update';
}

 

The problem is that when I open the VisualForce page with the window.parent.location.href command, I loose the reference to the Deal_Location controller, so my VisualForce page has no idea of what Deal_Locations to show.

 

How can I solve this?

An option would be to only do the check in VisualForce, but this is a huge performance killer as it will load all the VisualForce code for nothing, and will also need a page reload for the original Deal page.

 

Many thanks in advance,

Guy

 

Message Edited by GuyClairbois on 10-07-2009 02:32 AM

Based current date I need to get the month start date and end date. I have done it using java..  

java.util.Calendar cal = Calendar.getInstance();

 

Can anybody let me know whether it is possible to use java.util.Calendar in Apex class?.

If yes , sample example would be helpful.

i need to design a website. any one suggest me which technology i can use for that..?

i'm actually a beginner with apex & java..

  • September 04, 2009
  • Like
  • 0

I have a requirement to create a new custom child object for Opportunities.  Looks like I can create an APEX class to to do that and call it with a trigger on Opportunity... or just include in the trigger the code to create the new object.  

 

Is there a compelling reason to do it via apex class, or trigger would be the best?

Looking for some general help with this issue.

 

Also, in my efforts to limit my SOQL queries, I am trying to combine redundant ones using relationship queries. Such as

Select (Select Fire_Alarm_Inspection__c, Fire_Protection__c, Fire_Extinguisher__c, Fire_Suppression__c From Inspections__r), (Select Name__c From Floors1__r where exits_to_ground__c = true) From Account_c__c a Where ID = 'a0A70000006jSDV'

 

 My problem lies in how exactly to access the dat returned in this query. I tried this:

 

 

Account_c__c account =[Select (Select Fire_Alarm_Inspection__c, Fire_Protection__c, Fire_Extinguisher__c, Fire_Suppression__c From Inspections__r), (Select Name__c From Floors1__r where exits_to_ground__c = true) From Account_c__c a Where ID = :buildingid];ground = account.Floors1__r.name__c;

 but I am being told "Invalid foreign key relationship: Account_c__c.Floors1__r ", I ran the above query in the schema browser in Eclipse and got the results I wanted, but it won't work in my apex, or if it is working, I don't know how to access the data.

 

Thanks in advance for the help. 


 

 

 

I get a consistant error message when I try and use a commandlink action to assign a value to pass to a new page.  In the controller, the Param value and assignTo both show the value is passed to the controller and the PageReference  populate correctly based on my TestMethod.  However, when the commandlink is executed on the live data, the URL has the variable name of the "value=" populate the URL, i.e. {!uu.id}.

 

ERROR MESSAGE: Id value {uu.id} is not valid for the User standard controller URL: https://c.na3.visual.force.com/apex/forecastquota?id={uu.id} PORTIONS OF CONTROLLER WITH DIFFERENT OPTIONS TRIED: public PageReference UserSelected () { String s = apexPages.currentPage().getParameters().get('UserId'); PageReference retPage = new PageReference ('/apex/forecastquota?id=' + s); OR PageReference retPage = new PageReference ('/apex/forecastquota?id=' + SelectedUserId); OR PageReference retPage = Page.forecastquota; retPage.getParameters().put('Id',SelectedUserId); OR PageReference retPage = Page.forecastquota; retPage.getParameters().put('Id',s); retPage.setRedirect(true); return retPage; } public String getSelectedUserId() { return SelectedUserId; } public void setSelectedUserId(String s) { SelectedUserId = s; }

 

<apex:page standardController="User" extensions="ForecastQuotaInit"> <apex:sectionHeader title="Forecast and Quotas"/> <apex:form id="form1"> <apex:pageMessages /> <apex:outputPanel id="SearchUsers" > <apex:pageBlock title="User:" mode="edit" > <apex:pageBlockSection > <apex:pageBlockSectionItem > <apex:outputLabel for="searchText">User Name Search</apex:outputLabel> <apex:panelGroup > <apex:inputText id="searchText" value="{!searchText}"/> <apex:commandButton value="Go!" action="{!doSearch}" rerender="SearchUsers" status="status"/> </apex:panelGroup> </apex:pageBlockSectionItem> <apex:pageBlockSectionItem > <apex:outputLabel value="User Selected:" for="User_Name"/> <apex:outputText value="{!UserName}" id="User_Name" rendered="{!NOT(ISNULL(UserId))}"/> </apex:pageBlockSectionItem> </apex:pageBlockSection> <apex:actionStatus id="status" startText="Retrieving Users..."/> </apex:pageBlock> <apex:pageBlock title="User:" mode="edit" > <apex:pageBlockTable value="{!results}" var="uu" rendered="{!NOT(ISNULL(results))}" > <apex:column > <apex:commandLink action="{!UserSelected}" value="{!uu.Name}" > <apex:param name="UserId" value="{uu.id}" assignTo="{!SelectedUserId}"/> </apex:commandLink> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:outputPanel> </apex:form> </apex:page>

 

 

Thanks.

Message Edited by Brian Conlon on 05-06-2009 02:44 PM
Message Edited by Brian Conlon on 05-06-2009 02:45 PM
  • May 06, 2009
  • Like
  • 0

Hi Folks,

 

What's the best approach to transfer records from saleforce.com Org to other salesforce.com org (not like production to sandbox - But from 1 production org to another production org)

 

My Requirement is as follows:-

I have two different production orgs xORG and yORG- Now if user creates a Account in xORG i want to create same Account record in yOrg with same data - After insertion in ORG Y i want to link the records between both org via any key or a unique number.

 

So is there any native functionality available in salesforce to transfer recordsbtween two different orgs.

 

Please suggest if any one knows the solution

 

Thanks

Hi, I wanted to know how I can query a section of a contact page, and a related list of that contact and put it as a tab.

 

So my users can click the tab, and it brings up a contact look up field, with other fields from the contact, as well as a related list. 

I currently have a "before delete" trigger on OpportunityLineItem which stops line item records from being deleted if certain conditions are met.

 

Is there a way use an if to say that if the delete call is coming from the API or is due to a delete on the parent Opportunity record, to ignore the steps in the trigger?  I'd only want the steps to execute if the trigger is called from a line item delete via the UI.

 

I thought I read this once somewhere, but after all my searching, I can't seem to find it. 

 

Anybody know?

 

Thanks!!

Hi,

 

I get the following error: Return type of global method must also be global: MSAddressDirect2.GetAddress1_response op regel 2 kolom 62

 

 

does anybody know what todo i tried a few things but can't get it right!? 

 

global class TestCallOut2 {
     webservice static MSAddressDirect2.getAddress1_response getAddress1(String username, string password, string profileid, string postalcode, string housenumber, string countrycode) {
        MSAddressDirect2.AddressDirectServer2ServicePort stub = new MSAddressDirect2.AddressDirectServer2ServicePort();
        MSAddressDirect2.getAddress1_response adresje = stub.getAddress1(username, password, profileid, postalcode, housenumber, countrycode);
        return adresje;
    }
}

 

 

Apexclass (generated via WSDL):

//Generated by wsdl2apex

public class MSAddressDirect2 {
    public class getAddress1_element {
        public String username;
        public String password;
        public String profileid;
        public String postal_code;
        public String house_number;
        public String country_code;
        private String[] username_type_info = new String[]{'username','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] password_type_info = new String[]{'password','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] profileid_type_info = new String[]{'profileid','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] postal_code_type_info = new String[]{'postal_code','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] house_number_type_info = new String[]{'house_number','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] country_code_type_info = new String[]{'country_code','http://www.w3.org/2001/XMLSchema','string','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soapserver.jsm.marktselect.com','true','false'};
        private String[] field_order_type_info = new String[]{'username','password','profileid','postal_code','house_number','country_code'};
    }
    public class AddressDirectServer2ServicePort {
        public String endpoint_x = 'http://xxx.xx.xx.xx/cgi-bin/jsmdirect?MSAddressDirect2';
        public Map<String,String> inputHttpHeaders_x;
        public Map<String,String> outputHttpHeaders_x;
        public String clientCert_x;
        public String clientCertPasswd_x;
        public Integer timeout_x;
        private String[] ns_map_type_info = new String[]{'http://soapserver.jsm.marktselect.com', 'MSAddressDirect2'};
        public MSAddressDirect2.GetAddress1_response getAddress1(String username,String password,String profileid,String postal_code,String house_number,String country_code) {
            MSAddressDirect2.getAddress1_element request_x = new MSAddressDirect2.getAddress1_element();
            MSAddressDirect2.getAddress1Response_element response_x;
            request_x.username = username;
            request_x.password = password;
            request_x.profileid = profileid;
            request_x.postal_code = postal_code;
            request_x.house_number = house_number;
            request_x.country_code = country_code;
            Map<String, MSAddressDirect2.getAddress1Response_element> response_map_x = new Map<String, MSAddressDirect2.getAddress1Response_element>();
            response_map_x.put('response_x', response_x);
            WebServiceCallout.invoke(
              this,
              request_x,
              response_map_x,
              new String[]{endpoint_x,
              'getAddress1',
              'http://soapserver.jsm.marktselect.com',
              'getAddress1',
              'http://soapserver.jsm.marktselect.com',
              'getAddress1Response',
              'MSAddressDirect2.getAddress1Response_element'}
            );
            response_x = response_map_x.get('response_x');
            return response_x.getAddress1Return;
        }
    }
    public class GetAddress1_response {
        public String address_city;
        public String address_house_number;
        public String address_postalcode;
        public String address_street;
        public String resultCode;
        public String resultMessage;
        private String[] address_city_type_info = new String[]{'address_city','http://www.w3.org/2001/XMLSchema','string','1','1','true'};
        private String[] address_house_number_type_info = new String[]{'address_house_number','http://www.w3.org/2001/XMLSchema','string','1','1','true'};
        private String[] address_postalcode_type_info = new String[]{'address_postalcode','http://www.w3.org/2001/XMLSchema','string','1','1','true'};
        private String[] address_street_type_info = new String[]{'address_street','http://www.w3.org/2001/XMLSchema','string','1','1','true'};
        private String[] resultCode_type_info = new String[]{'resultCode','http://www.w3.org/2001/XMLSchema','string','1','1','true'};
        private String[] resultMessage_type_info = new String[]{'resultMessage','http://www.w3.org/2001/XMLSchema','string','1','1','true'};
        private String[] apex_schema_type_info = new String[]{'http://soapserver.jsm.marktselect.com','true','false'};
        private String[] field_order_type_info = new String[]{'address_city','address_house_number','address_postalcode','address_street','resultCode','resultMessage'};
    }
    public class getAddress1Response_element {
        public MSAddressDirect2.GetAddress1_response getAddress1Return;
        private String[] getAddress1Return_type_info = new String[]{'getAddress1Return','http://soapserver.jsm.marktselect.com','GetAddress1_response','1','1','false'};
        private String[] apex_schema_type_info = new String[]{'http://soapserver.jsm.marktselect.com','true','false'};
        private String[] field_order_type_info = new String[]{'getAddress1Return'};
    }
}

I amattempting to build a custom controller that created two collections for Opportunity and a custom object named StateCoverageScript.  I have a problem within the retrun on line 10 column 8that states "expecting "set", found 'List'. I am not sure about the error so any assistance would be ahuge help....

 

 

 

 

public class opportunityStateCovCon { public ApexPages.StandardSetController setCon { get { if(setCon == null) { setCon = new ApexPages.StandardSetController(Database.getQueryLocator([select op.OwnerId,op.name,op.closedate,op.StageName, op.State__c from Opportunity op where op.State__c = :ApexPages.currentPage().getParameters().get('state') and op.INPUT_Opportunity_ID__c != NULL]));} return setCon; set; } public List<Opportunity> getOpportunities() { return (List<Opportunity>) setCon.getRecords(); } public ApexPages.StandardSetController setStateCoverage { get { if(setStateCoverage == null) { setStateCoverage = new ApexPages.StandardSetController(Database.getQueryLocator([select scs.name,scs.StateAbbreviation__c,scs.Deployment_Manager__c,scs.Government_Program_Manager__c from setStateCoverageScript__c scs where scs.StateAbbreviation__c = :ApexPages.currentPage().getParameters().get('state')]));} return setStateCoverage; } set; } public List<StateCoverageScript__c> getStateCoverage() { return (List<StateCoverageScript__c>) setStateCoverage.getRecords(); } }

 

 

 

  • April 30, 2009
  • Like
  • 0

Currently I am working on an APEX implementation of converting leads in bulk. The Database.convertLead accepts a list of leads as input, but it seems to me that the conversion of let's say a list of 20 leads, causes 20 separate inserts on account. Since I have an @future call on the Account trigger, this is now breaking, as all the 20 inserts seem to happen within the same context for limits (i.e. 10 future calls), but in separate trigger instances. So regardless of the fact my trigger is handling Accounts in bulk and then passes a list to the @future call, it will still break, since the trigger is called for every separate new Account (i.e. 20 in a Database.convertLead call with 20 leads).

 

Anyone has any experience with this issue and how to deal with it?

 

 

Anyone knows the best approach to create a webshop with products stored in the standard Product2 object. And to attach orders (an opportunity) to the appropriate account, based on login credentials of the user when ordering. The webcatalog of products should be publicly visible, but also for logged in users (customer portal or authenticated user, either will do).

 

Looking at the fact it's impossible to display a Product2 to a customer portal user (but STUPIDLY enough it CAN be made visible to guest users), there is no way to allow ordering of products only to customer portal (logged in) users.

 

What's the best approach here?

 

 

Anyone knows if it is possible to use the label of a standardbutton to a custom button, something like:

 


<!--This does not work, anyone knows if it is possible? -->
<apex:commandButton value="{!$Action.Account.Save.label}" action="{!save}"/>

 

 

 

  • September 03, 2009
  • Like
  • 0
When I change the account owner, and select opportunities to be transferred as well, it looks like opportunity triggers are not executing. Why is this?

WARNING Warning: The element type "br" should be terminated by the matching end-tag "
". at line 30

 

 

This message occasionally occurs as a warning on my VF pages (containing a <apex:pageMessages  /> tag). I have no idea where this warning is coming from...anyone knows (how to get rid of it)?

When saving a new product, on a new Opportunity I receive this error:

 

common.exception.FieldIntegrityException: java.sql.SQLException: ORA-20067: ORA-06512: at "GRUMPY.GUTIL", line 42 ORA-06512: at "GRUMPY.SOPPLINEITEM", line 1091 ORA-06512: at line 1 : {call sOppLineItem.update_opplineitems(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)})}

 

 

There's no (active) triggers or validation rules on the OpportunityLineItem object. Cannot explain this. Below is a screenshot

 

Error!

 

 

When I run this query:

PriceBookEntry[] pbeList = [SELECT Id,PriceBook2Id,PriceBook2.Name,Product2.Name,Product2.Inzamelmiddel__c,Product2.Description,UnitPrice FROM PriceBookentry WHERE PriceBook2.Name='Pricebookname' AND Product2.Name in :afvalstromen AND Product2.Description in :fqList AND Product2.Inzamelmiddel__c in :piList];

 

all is fine.

 

However, the contents from field Inzamelmiddel__c were originally meanth to be stored in standard field Family. But when trying this query:

 

PriceBookEntry[] pbeList = [SELECT Id,PriceBook2Id,PriceBook2.Name,Product2.Name,Product2.Inzamelmiddel__c,Product2.Description,UnitPrice FROM PriceBookentry WHERE PriceBook2.Name='Pricebookname' AND Product2.Name in :afvalstromen AND Product2.Description in :fqList AND Product2.Family in :piList];

 

 

it seems to somehow do a DISTINCT on Family, returning an incorrect (too small) resultset!

 

Is this a know issue, or did I miss some limitation with querying theFamily (or selectlist in general) field?

 

FYI: piList is a List<String>, just like fqList and afvalstromen.

Message Edited by Harmpie on 02-23-2009 02:56 PM

I have created a VF page, which is included in the page layout of an object, that displays amounts from related records. Amount above 10.000.000 are displayed in the 6.0E+7 notation on screen. How can I prevent this?

 

The code that sets the field value:

this.noc1 = afcst.Forecasted_Amount__c;

 

Where Forecasted_Amount__c is a normal currency field in SF. noc1 is a Double in the code, however I tried with Decimal as well.

 

The pagecode that displays this field:

<td><apex:outputText id="noc1" value="{!noc1}" /></td>

 

 

Another question I have, is how to prevent the numbers to show with 1 decimal position. 1.000.000 will always be displayed as 1000000.0, regardless of what method I append to the first line of code (round(), toPlainString() etc..)

Code:
Sharing Rule Limit Exceeded 
Your organization has exceeded the maximum number of sharing rules allowed of this type. Please contact your administrator for more information. 


 
Can someone please point me to the Help Section where this limit is mentioned? Why can't I create more than 100 sharing rules on an object??? There's nothing in the app Setup limits page...nothing. It's obstructing the current project I am doing, so hope somebody of SF can help me work around this 1!
I have the following Trigger, which I want to use to update ownership of 2 custom objects (Business_Unit__c & Sub_Unit__c) when a user role changes. The role and it's corresponding BU / Sub BU are fetched and should be updated with this new UserId as the owner.
 
Code:
trigger RoleUpdateBuOwner on User (after update) {
 
 Map<ID,User> trUsersNew = Trigger.newMap;
 Map<ID,User> trUsersOld = Trigger.oldMap;
 
 Set<String> allUpdatedRoles = new Set<String>(); 
 
 Map<Id,Business_Unit__c> allBu = new Map<Id,Business_Unit__c>([SELECT Id,Name,OwnerId FROM Business_Unit__c]);
 Map<Id,Sub_Unit__c> allSubBu = new Map<Id,Sub_Unit__c>([SELECT Id,Name,OwnerId FROM Sub_Unit__c]);
 
 Integer numBuUpdated = 0;
 List<Business_Unit__c> buToUpdate = new List<Business_Unit__c>();
 for(Business_Unit__c aBu : allBu.values()) {
  for(User userWithNewRole : trUsersNew.values()) {
   if(userWithNewRole.Id != aBu.OwnerId) {
    if(userWithNewRole.Role_Name__c.contains(aBu.Name)  && userWithNewRole.Role_Name__c.contains('Plant Manager')) {
     aBu.OwnerId = userWithNewRole.Id; 
     buToUpdate.add(aBu);
     numBuUpdated++;
    }
   }  
  }
 }
  
 Integer numSubBuUpdated = 0;
 List<Sub_Unit__c> subBuToUpdate = new List<Sub_Unit__c>();
 for(Sub_Unit__c aSubBu : allSubBu.values()) {
  for(User userWithNewRole : trUsersNew.values()) {
   if(userWithNewRole.UserRoleId == null) continue;
   if(userWithNewRole.Id != aSubBu.OwnerId) {
    if(userWithNewRole.Role_Name__c.contains(aSubBu.Name) && userWithNewRole.Role_Name__c.contains('Plant Manager')) {
     aSubBu.OwnerId = userWithNewRole.Id; 
     subBuToUpdate.add(aSubBu);
     numSubBuUpdated++;
    }
   }  
  }
 }
 update subBuToUpdate;
 update buToUpdate;
 
 /*
 // For testing
 for(User thisUser : Trigger.new) {
  thisUser.addError('Updating '+numBuUpdated+' BU and '+numSubBuUpdated+' Sub BU');
 }
 */
 
}

 
Now, when I update a user role, the following error appears:
 
Code:
Error: Invalid Data. 
Review all error messages below to correct your data.
Apex trigger RoleUpdateBuOwner caused an unexpected exception, contact your administrator: RoleUpdateBuOwner: execution of AfterUpdate caused by: System.DmlException: Update failed. First exception on row 0 with id a0FR00000007OWzMAM; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object: DML operation on non-setup object is not supported after you have updated a setup object: Business_Unit__c: [Id]: Trigger.RoleUpdateBuOwner: line 40, column 5

 
What is wrong with my trigger (that causes this error:))?


Message Edited by Harmpie on 12-12-2008 05:35 AM
Hi. I tried to 'disable' the default Attachment function of SFDC with the following trigger:
 
Code:
trigger AttachmentDisabler on Attachment (before insert) {
 List<Attachment> atts = Trigger.new;
 for(Attachment a:atts) {
  a.addError('Please use the "Attach(FTP)" button on top of the detail page to attach a file.'); 
 }
}

 
But this does not seem to work. Did I do something wrong or is it impossible this way? Even the debug did not show anything, the trigger does not seem to do anything. Any other ways to disable the normal Attach function of SFDC without removing the entire related list? (want to keep notes function)
In the help for VLOOKUP() it says:
VLOOKUP(field_to_return, field_on_lookup_object, lookup_value) and replace field_to_return with the field that contains the value you want returned, field_on_lookup_object with the field on the related object that contains the value you want to match, and lookup_value with the value you want to match.
 
However when I try to save:
 
IF(VLOOKUP($ObjectType.Sales_History__c.Fields.Checksum__c,$ObjectType.Sales_History__c.Fields.Checksum__c,  Checksum__c)= Checksum__c,True,False)
 
I receive the error:
Error: Incorrect parameter for function VLOOKUP(). Expected Record Name field.
 
Why doesn't the manual mention that this field_on_lookup_object MUST be a Name field?? When I try:
 
IF(VLOOKUP($ObjectType.Sales_History__c.Fields.Checksum__c,$ObjectType.Sales_History__c.Fields.Name,  Checksum__c)= Checksum__c,True,False)
 
I receive no errors, but ofcourse this is not what I want :(
 
Is this behaviour intended anyway and will you adjust the help text, or is the VLOOKUP() simply not working as intended? Or am I doing something wrong?



Message Edited by Harmpie on 11-14-2008 08:05 AM
Is something like this possible using a formula field? I want to add a numberfield (number of months in 'Estimated_Time_For_Exection__c') to a start date, to calculate the end date.
 
The formula below gives an error:
 
Code:
DATE(YEAR(Start_Date__c),MONTH(Start_Date__c)+ Estimated_Time_For_Exection__c ,DAY(Start_Date__c))

 
Is something like this possible using a formula field? I want to add a numberfield (number of months in 'Estimated_Time_For_Exection__c') to a start date, to calculate the end date.
 
The formula below gives an error:
 
Code:
DATE(YEAR(Start_Date__c),MONTH(Start_Date__c)+ Estimated_Time_For_Exection__c ,DAY(Start_Date__c))

 
Hi,
 
I am trying to make a trigger that will update fields on a related object. The functionality of the trigger is working fine, however, it contains 2 SOQL queries. These SOQL queries give me trouble. The involved objects (Productline__c) will be userted daily, 10000's of them. This fires the trigger, but when the batchsize of the dataloader is set to 200, exceptions will start occurring, because I am exceeding the 20 SOQL query limit. When I put the batchsize on 10, no exceptions occur based on the SOQL limit, but I will run into the API call limit. How can i circumvent this catch-22?
 
Here's the code:
Code:
// -------------------------------------------------------------------------------------------
// This trigger makes sure that changes to order amounts/quantities (based on productlines
// in the order are aggregated at Budget level. This is necessary because Master detail detail
// relations are unsupported by SFDC, as a consequence Roll-up will not work.
// -------------------------------------------------------------------------------------------
trigger productLineSaved on Productline__c (after insert, after update, after delete, 
after undelete) {

 if(!Trigger.isInsert) {
  integer z = Trigger.old.size();
  
  for (integer i=0; i<z; i++) {
   // Set old numbers to zero
   Double qtyOld = 0;
   Double amOld =  0;
   
   if(Trigger.isUpdate) {
    // Retrieve old values in case of an update
    Productline__c plOld = Trigger.old[i];
    qtyOld = plOld.Total_Quantity_Ordered__c;
    amOld =  plOld.Total_amount__c;
   }
   
   Productline__c plNew;
   if(!Trigger.isDelete) {
    plNew = Trigger.new[i];
   } else {
    plNew = Trigger.old[i];
   }
  
   // Fetch the Budget which we are updating.
   CI_Order__c ord = [SELECT Id,Budget__c FROM CI_Order__c WHERE Id = :plNew.Order__c  LIMIT 1];
   Budget__c bud = [SELECT Id,Total_Amount_Orders__c,Total_Quantity_Orders__c FROM Budget__c WHERE Id = :ord.Budget__c  LIMIT 1]; 
  
   // Make calculation for the figures on Budget level
   Double budgetOrderAmountBefore = 0;
   Double budgetOrderQuantityBefore = 0; 
   budgetOrderAmountBefore = bud.Total_Amount_Orders__c; 
   budgetOrderQuantityBefore = bud.Total_Quantity_Orders__c;
   if(!Trigger.isDelete) {
    bud.Total_Amount_Orders__c = (budgetOrderAmountBefore - amOld) + plNew.Total_amount__c;
    bud.Total_Quantity_Orders__c = (budgetOrderQuantityBefore - qtyOld) + plNew.Total_Quantity_Ordered__c;
   } else {
    // In case of a delete the calculation is a bit different
    bud.Total_Amount_Orders__c = (budgetOrderAmountBefore - plNew.Total_amount__c);
    bud.Total_Quantity_Orders__c = (budgetOrderQuantityBefore - plNew.Total_Quantity_Ordered__c);
   }
   update bud;
  }
 }
 if(Trigger.isInsert) {
  integer z = Trigger.new.size();
  
  for (integer i=0; i<z; i++) {
   // Set old numbers to zero
   Double qtyOld = 0;
   Double amOld =  0;

   Productline__c plNew;
   plNew = Trigger.new[i];
  
   // Fetch the Budget which we are updating.
   CI_Order__c ord = [SELECT Id,Budget__c FROM CI_Order__c WHERE Id = :plNew.Order__c  LIMIT 1];
   Budget__c bud = [SELECT Id,Total_Amount_Orders__c,Total_Quantity_Orders__c FROM Budget__c WHERE Id = :ord.Budget__c  LIMIT 1]; 
  
   // Make calculation for the figures on Budget level
   Double budgetOrderAmountBefore = 0;
   Double budgetOrderQuantityBefore = 0; 
   budgetOrderAmountBefore = bud.Total_Amount_Orders__c; 
   budgetOrderQuantityBefore = bud.Total_Quantity_Orders__c;

   bud.Total_Amount_Orders__c = (budgetOrderAmountBefore - amOld) + plNew.Total_amount__c;
   bud.Total_Quantity_Orders__c = (budgetOrderQuantityBefore - qtyOld) + plNew.Total_Quantity_Ordered__c;

   update bud;
  }
 }
}

 


Message Edited by Harmpie on 11-06-2008 01:01 AM
How can I allow decimal and currency fields to take input with a comma as decimal separator. Right now, the controller is giving an error, but I cannot find a way around this. I allready set the locale of user (customer portal) and org to different values.
 
  • September 15, 2008
  • Like
  • 0
I was wondering if someone could answer this question:
 
When upserting an object that has a lookup-field to a User, one can match this User with an external Id field (which of course one should define on the User object). However, when upserting an object where the User object is only referenced as an Owner of this object, only an actual OwnerId (User Id) is accepted, one cannot use the external Id to match the Owner..... Why not?
 
(FYI: I ran into this when upserting using the Dataloader)


Message Edited by Harmpie on 08-21-2008 06:15 AM
See my trigger:
Code:
trigger copyCursusDataToOpp on Cursusinschrijving__c (after insert, after update) {

 if(System.Trigger.isUpdate) {
  for(Cursusinschrijving__c ci : Trigger.new) {
   if(ci.Via_opportunity__c!=null) {
    Opportunity Opp = [SELECT Id,Name FROM Opportunity WHERE Id = :ci.Via_opportunity__c];
    Cursus C = [SELECT Id,Cursusdagen__c FROM Cursus__c WHERE Id = :ci.Cursus__c  LIMIT 1];
    Opp.Cursusdata__c = C.Cursusdagen__c;
    Opp.Cursus__c = ci.Cursus__c;
    update Opp;   
   }
  } 
 } else if(System.Trigger.isInsert) {
  for(Cursusinschrijving__c ci : Trigger.new) {
   if(ci.Via_opportunity__c!=null) {
    Opportunity Opp = [SELECT Id,Name FROM Opportunity WHERE Id = :ci.Via_opportunity__c];
    Cursus C = [SELECT Id,Cursusdagen__c FROM Cursus__c WHERE Id = :ci.Cursus__c LIMIT 1];
    Opp.Cursusdata__c = C.Cursusdagen__c;
    Opp.Cursus__c = ci.Cursus__c;
    update Opp;   
   }
  } 
 }
 static testMethod void testTrigger() {
  Cursus__c tc = new Cursus__c();
  insert tc;
  Cursusinschrijving__c tci = new Cursusinschrijving__c();
  Opportunity to = new Opportunity();
  to.Name = 'testopp';
  insert to;
  tci.Via_opportunity__c = to.Id;
  tci.Cursus__c = tc.id;
  insert tci;
  System.assertEquals(to.Cursus__c, tc.Id); 
 }
}

 
I got a few questions on this:
1) Why does ci.Cursus__r.Cursusdagen__c return null in the first parts, while the query to the related object (as in the example) DOES return a value?
2) Saving the code above gives an error: Compile Error: Only top-level class methods can be declared static at line 2 column 748. Can someone tell me how to write testmethods on triggers?
3) When trying to deploy the trigger (without any testcoverage at that time), selecting only the trigger to be deployed in the deploymentplan using Eclipse, I will receive an error, complaining about testcoverage for multiple APEX components (while only the trigger is selected in the deployment plan !!), because the trigger is untested, and my other APEX class has minimal testcoverage (78%), the average of coverage drops below 75%, making deployment impossible. Why does eclipse take unselected component's testcoverage into account ?
Is it somehow possible to log in using the API with an external script and then, using this session to redirect the user from this external script right into SF ?
 
I.e. can I pass the session Id using the requeststring somehow?
Something like
Now whenever I try to do the redirect it will send me straight to the log in screen.
 
 

Message Edited by Harmpie on 10-01-2007 05:44 AM

Hi All,

I have a requirement where i need to have a lookup relationship on account to external object which is present in mysql database.
I need to select the record when creating an account link that selected record to account record.
Any ideas ?

Many Thanks 

Hi All, 

I am trying to get used to writing triggers doing a fairly simple trigger but I am stuck. 

I am trying to write a trigger where te scenario is:

  1.  Two objects Account and Opportunity
  2. Account field Renewal Term (Renewal_Term__c)that is picklist of years annual through sexennial
  3. Opportunity Field Contract Length ( Contract_Length__c ) that is a picklist of values 1-6
  4. I believe that there is a master-detail relationship between Account and Opportunity
  5. When an Opportunity is Closed Won, Renewal Term should update to the corresponding contract length from the Opportunity, provided that Renewal Term isn't already populated. 

Embarrassingly, all I have so far is:

 

    

trigger updatelength on Account (after update) {
    Opportunity__c[] opptoupdate = new Opporunity__c[]{};
        for(account c: trigger.new){
            for(Opportunity__c cp: [select id,name,Contract_Length__c from Opportunity__c where Account = :c.id]{

            }
        }
}


Would anyone mind helping me out?

Thanks!

Hi,

 

today we've tried to configure a batch DataLoader process. It failed to pick up the config file, no matter how we tried. Is this a know issue with version 25? We installed 22 and 23 on the same environment, with exactly the same config (copied the one we build earlier today for version 25), and it worked fine.

 

Thanx in advance!

 

Marco

Currently I am working on an APEX implementation of converting leads in bulk. The Database.convertLead accepts a list of leads as input, but it seems to me that the conversion of let's say a list of 20 leads, causes 20 separate inserts on account. Since I have an @future call on the Account trigger, this is now breaking, as all the 20 inserts seem to happen within the same context for limits (i.e. 10 future calls), but in separate trigger instances. So regardless of the fact my trigger is handling Accounts in bulk and then passes a list to the @future call, it will still break, since the trigger is called for every separate new Account (i.e. 20 in a Database.convertLead call with 20 leads).

 

Anyone has any experience with this issue and how to deal with it?

 

 

Hi Friends,

 

I am trying to pull out data from one instance.Here comes the situation.I have,for example, 10 custom  price books in one instance and I just wants to move data under two custom price books to another instance.When I use data loader to export data from the custom price books I get  all data which is listed under 10 books including standard price book,I do not want that.Is there a way to just directly extract data under the two custom price books into the excel sheet.?Please help.

 

Thanks,

Trick

Hi All,

 

I have an object called Notes where it has a look up to the Client(Account) Object. I have a trigger on after insert and update.

 

For update, I am checking the old Client lookup value to the new one and doing some processing for that. But the Trigger.Old[i] only return's the Id, OwnerId and the isDeleted flag when I click "Save and New" Button and it return's the whole object when I click "Save". As a result I am getting an error. This seems like a salesforce bug, but I am just wondering if anyone have come across this before? Thanks.

 

The error message is:

 

 

Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger NotesSharing caused an unexpected exception, contact your administrator: NotesSharing: execution of AfterUpdate caused by: System.NullPointerException: Attempt to de-reference a null object: Trigger.NotesSharing: line 61, column 4". 
The error message occurs when I access Trigger.Old[i].Client__c. This works fine for Save, but it doesn't have the Client__c field value for Save and New. Does anyone know why? Thanks.
Sanch.

 

 

 

  • February 23, 2011
  • Like
  • 0

Iam trying to write an extension class for pagination as follows below.
However this is throwing a compilation error:


Error: Compile Error: Method does not exist or incorrect signature: Database.getQueryL​ocator(LIST<Product2>) at line 5 column 71.

Please help me as i  have justt modified this from a forum post and iam not sure how to do it

 

 

also,how do i incorporate this in my  vf page??

 

Please help!

public class samplePagination {
public ApexPages.StandardSetController samplePagination{
get {
if(samplePagination== null) {
samplePagination= new ApexPages.StandardSetController(Database.getQueryL​ocator([ select id,created_inv__c,supplier__r.id,pid__c,pinv__c,Product_Type_custom__c,purchase_price__c,name,select__c,description,family,productcode from product2 where id
in (select product2id from pricebookentry where pricebook2.name='Purchase') ]));
//set number of records you want to show on UI.
samplePagination.setPageSize(5);
}
return samplePagination;
}
set;
}
// indicates whether there are more records after the current page set..
public Boolean hasNext {
get {
return samplePagination.getHasNext();
}
set;
}

// indicates whether there are more records before the current page set..
public Boolean hasPrevious {
get {
return samplePagination.getHasPrevious();
}
set;
}


public ApexPages.StandardSetController samplePagination

{

get

{

if(samplePagination== null)

{

samplePagination= new ApexPages.StandardSetController(Database.getQueryL​ocator([select id,created_inv__c,supplier__r.id,pid__c,pinv__c,Product_Type_custom__c,purchase_price__c,name,select__c,description,family,productcode from product2 where id
in (select product2id from pricebookentry where pricebook2.name='Purchase') ]));

//set number of records you want to show on UI

samplePagination.setPageSize(5);

}

return samplePagination;

}

set;

}

Hi,

 

We have enabled Chatter in our org. and the number of records in Feed Track Changes increased our storage space so we were not able to load any more data.

 

When I tried to delete each feed from the Standard Object feeds like Accountfeed, Contactfeeds etc. there  were no data available in those objects. But the number of records in the Feed Track Change object still remained the same.

 

I tried to delete the feeds of Custom Objects as well but I did not find any records in them as well.

 

Can anyone provide me a solution of where can i search for these feeds in order to delete them??

 

Is there an easy way to delete all the feeds together rather than deleting each Objects feeds individually???

 

Thanks in advance.

 

Regards,

prak

  • July 19, 2010
  • Like
  • 0

Hi

 

can't seem to find an answer to this one anywhere !

 

Can i use select to SOQL picklist values ? If as I suspect the answer is 'no' what is the standard way to do this.

 

ta in advance

Hello Friends,

 

My requirement is that, i need to generate an XML out of my VF page. For this, i specified the "ContentType="application/xml" on my page header and then included the DOCTYPE tags to generate a standard XML out of it.

 

But somehow, i am not able to get the XML styling in the generated page and it shows me the shole page elements intead of just showing me the data.

 

Can you please let me know where i am going wrong or is this possible in VF? Pasting my VF page code below:

 

 

<apex:page cache="true" Controller="TestController" contentType="application/xml" showHeader="false">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/html" xml:lang="en" lang="en">
<body>
<apex:form >
<apex:pageblock id="exportDocs">
<apex:pageBlockTable value="{!exportValues}" var="actual">
<apex:column headerValue="Id" value="{!actual.Id}"/>
<apex:column headerValue="Act Name" value="{!actual.Name}"/>
<apex:column headerValue="MType" value="{!actual.A_Type__c}"/>
<apex:column headerValue="Country" value="{!actual.Country__c}"/>
<apex:column headerValue="B" value="{!actual.B__c}"/>
<apex:column headerValue="Actual C" value="{!actual.C__c}"/>
<apex:column headerValue="Actual G" value="{!actual.G__c}"/>
<apex:column headerValue="Actual I" value="{!actual.I__c}"/>
</apex:pageBlockTable>
</apex:pageblock>
</apex:form>
</body>
</html>
</apex:page>

 

Any help/guidance would be highly appreciated!!

 

Many Thanks,

Cool_D
Can I create an array of checbox (group of checkbox with the same name ) with <apex:checkbox> component?
  • April 21, 2009
  • Like
  • 0
How do i resolve this...This is my code...I am sending an XML to an endpoint n number of times(its in a for loop)...Cant i do that?

public PageReference saveUsers() {
String[] listOfSelectedUsers = getUsers();
String domainId = System.currentPageReference().getParameters().get('ex');
for(String presentVar: listOfSelectedUsers)
{

Http h = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('http://84.40.30.147/cm/spws');
req.setMethod('POST');

TestExtranet__c extranet = [select Extranet_Name__c from TestExtranet__c where id = :domainId];
Lead lead = [select id,firstname,lastname,email from Lead where id = :presentVar];
String requestXML = buildXMLRequest('createUser',extranet.Extranet_Name__c,lead.id,lead.firstname,lead.lastname,lead.email);

req.setBody(requestXML);
HttpResponse res = h.send(req);
XmlStreamReader reader = res.getXmlStreamReader();
boolean errorExists = parseResponseForError(reader);
if(!errorExists)
{
Extranet_User_Mapping__c mapping = new Extranet_User_Mapping__c();
mapping.Extranet_Id__c = domainId;
mapping.Leads__c = presentVar;
insert mapping;
}else
{

}


}
PageReference userConfPage = new PageReference('/apex/userConfirmation?ex='+ System.currentPageReference().getParameters().get('ex'));
return Page.userConfirmation;
}