• sfdevnick
  • NEWBIE
  • 0 Points
  • Member since 2008

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 8
    Replies

Hi, I'm new to Apex, trying to learn triggers, and would appreciate any help. 

 

I have two custom objects "ObjectA" and "ObjectB". Both objects are on the detail side of Master-Detail relationships with Opportunity. ObjectB also has a lookup to ObjectA. When the user is on the main page for ObjectA, they can click on the button "New Object B" in the related list. In the edit screen for Object B that opens, the ID for ObjectA is of course pre-filled. I want to create a trigger that automatically fills the OpportunityID field in ObjectB with the same OpportunityID that already exists in the OpportunityID field in ObjectA.

 

Would the following work?

 

trigger SetOpportunityField on ObjectB__c (before insert, before update) {
    for (ObjectB__c ob : Trigger.new) {
        String cid = ob.ObjectA_ID__c;
        List<ObjectA> ObjectAs = [SELECT OpportunityId FROM ObjectA__c WHERE Id = :cid];
   
        ob.OppID__c = ObjectAs.get(0).OpportunityId;
    }
 }

 

Message Edited by sfdevnick on 02-08-2009 09:17 PM

Hi, I'm an apex newbie. I need a trigger to fill the AccountID lookup field on the Contact record with a fixed ID every time a Contact is saved with that field empty. Would the following work?

  

trigger SetAccountField on Contact (before insert, before update) {
    for (Contact contact : Trigger.new) {
        Contact.Account = '0017000000UzTRj';
    }
 }

 

//Where 0017000000UzTRj is the ID of the Account record

 

Do I need to add something to make sure it ONLY does this when the AccountID field is empty? Like  IF(isempty(Contact.Account,..

 

And how would I modify so that it works if Contacts without an Account ID were loaded via the SF import wizards or via the API?

 

Thanks in advance.:smileyhappy:

I need a trigger to create a Dummy Account record every time a Contact is saved with its AccountID field empty (so that Contact is not marked Private and thereby inaccesssible to all beside Owner and Admin). Would the following work? Do I need to add something so that it ONLY creates a dummy record when the AccountID field is empty?

 

trigger create_dummy_accnt on Contact (before insert) {

 

  // create a container to bulk insert accounts
  List<Account> accountsToInsert = new List<Account>(); 

 

  // loop through trigger records
  for (int i=0; i<Trigger.new.size(); i++)
  {
    {
      Account CreateAccnt = new Account();
      CreateAccnt.Name = 'Dummy Account';
      accountsToInsert.add( CreateAccnt );
    }
  }

  // bulk insert accounts
  if (!accountsToInsert.isEmpty()) {
    insert accountsToInsert;
  }
}

 

Also, can anyone think of a way to keep the resulting dummy accounts off the recently viewed items list?

 

Ideally I'd like to drop this workaround and somehow prevent the system from marking Contacts with blank Account ID private - there's no way to do that programatically I don't suppose?

 

The only other workaround I know is to make everyone a system admin. Yikes!

This must be such a common requirement, perhaps someone could provide the code for this?

 

I need to create a "New Account" button in a lookup dialog (the search layout page that pops up when you click on a lookup lens icon) so that once the new Account is created the user is returned to the page (from where the user clicked the lens icon that opened the search layout) with the newly created account now selected in the lookup field.

Hi, I'm new to Apex, trying to learn triggers, and would appreciate any help. 

 

I have two custom objects "ObjectA" and "ObjectB". Both objects are on the detail side of Master-Detail relationships with Opportunity. ObjectB also has a lookup to ObjectA. When the user is on the main page for ObjectA, they can click on the button "New Object B" in the related list. In the edit screen for Object B that opens, the ID for ObjectA is of course pre-filled. I want to create a trigger that automatically fills the OpportunityID field in ObjectB with the same OpportunityID that already exists in the OpportunityID field in ObjectA.

 

Would the following work?

 

trigger SetOpportunityField on ObjectB__c (before insert, before update) {
    for (ObjectB__c ob : Trigger.new) {
        String cid = ob.ObjectA_ID__c;
        List<ObjectA> ObjectAs = [SELECT OpportunityId FROM ObjectA__c WHERE Id = :cid];
   
        ob.OppID__c = ObjectAs.get(0).OpportunityId;
    }
 }

 

Message Edited by sfdevnick on 02-08-2009 09:17 PM

Hi, I'm an apex newbie. I need a trigger to fill the AccountID lookup field on the Contact record with a fixed ID every time a Contact is saved with that field empty. Would the following work?

  

trigger SetAccountField on Contact (before insert, before update) {
    for (Contact contact : Trigger.new) {
        Contact.Account = '0017000000UzTRj';
    }
 }

 

//Where 0017000000UzTRj is the ID of the Account record

 

Do I need to add something to make sure it ONLY does this when the AccountID field is empty? Like  IF(isempty(Contact.Account,..

 

And how would I modify so that it works if Contacts without an Account ID were loaded via the SF import wizards or via the API?

 

Thanks in advance.:smileyhappy:

I need a trigger to create a Dummy Account record every time a Contact is saved with its AccountID field empty (so that Contact is not marked Private and thereby inaccesssible to all beside Owner and Admin). Would the following work? Do I need to add something so that it ONLY creates a dummy record when the AccountID field is empty?

 

trigger create_dummy_accnt on Contact (before insert) {

 

  // create a container to bulk insert accounts
  List<Account> accountsToInsert = new List<Account>(); 

 

  // loop through trigger records
  for (int i=0; i<Trigger.new.size(); i++)
  {
    {
      Account CreateAccnt = new Account();
      CreateAccnt.Name = 'Dummy Account';
      accountsToInsert.add( CreateAccnt );
    }
  }

  // bulk insert accounts
  if (!accountsToInsert.isEmpty()) {
    insert accountsToInsert;
  }
}

 

Also, can anyone think of a way to keep the resulting dummy accounts off the recently viewed items list?

 

Ideally I'd like to drop this workaround and somehow prevent the system from marking Contacts with blank Account ID private - there's no way to do that programatically I don't suppose?

 

The only other workaround I know is to make everyone a system admin. Yikes!

This must be such a common requirement, perhaps someone could provide the code for this?

 

I need to create a "New Account" button in a lookup dialog (the search layout page that pops up when you click on a lookup lens icon) so that once the new Account is created the user is returned to the page (from where the user clicked the lens icon that opened the search layout) with the newly created account now selected in the lookup field.

Hi,
    I am new to salesforce.com and want to know more about the limitations one faces while developing an application on AppExchange . Since since salesforce hosts the applications built for AppExchange, i guess there must be some space constraints or other constraints. I just want to know what are the space, application size , or any other limitations one faces while developing an application for AppExchang.
I have searched the boards looking for an answer, and can't quite find what I'm looking for.

We have a custom object called 'domains' which is simply a form listing off any domains that a user may have purchased through us.  Each contact is associated with an account, a company and an office.  In the cases section when we select a contact it auto-populates the account and office information.  In this new custom object it doesn't seem to grab the account or office info.

Tried creating a trigger to update these fields, but was not successful.  I'm a bit of a SalesForce n00b and would greatly appreciate any help in creating this function.  Basically, when we select a contact the contacts account and office information should auto populate those fields, either on save or when it is selected.

Help?

Thanks,

Benjamin Higginbotham
I am getting ready to launch a product and I am scratching my head on this one as to how I would go about packaging (managed versus unmanaged) it for my clients.

Here is my understanding of Managed versus unManaged package:

Managed:


1. Clients don't see my code - my IP is protected
2. Once I publish the managed package as released, my engineering won't be able to modify a lot of things - such  objects and object attributes in the developer environment. This is clearly undesirable for a startup.
3. Once I create a managed package in a developer environment, my object get prefixed with the unique prefix - even if i delete the managed package, objects retain their prefix.
4. Clients can upgrade without uninstall...
5. Managed beta package is an not an option, since it can't be done in production environment - only sandbox or developer. I am looking for real production customers who will pay me, but appreciate the fact that product might change based on their feedback.

UnManaged:

1. Code is visible to my clients - my IP is unprotected
2. I can freely modify my product in developer environment, downside being that customers have to uninstall the prior release and manually reimport all the data.

Ideally I want a managed package (to protech my IP and enable  upgrades). However, I  find the prospect of my engineering  not being able to modify the  objects for eternity a  little scary. I understand this is important so that clients can upgrade, but since my product will evolve, I don't want to be locked in early on. Early clients might be willing to uninstall and reimport, if they see newer functionality is worth it.

One option I was thinking was to always maintain an unpackaged version as my golden source code. I can then use this to create multiple managed packages, each in a different developer enviroment, each with a different prefix. So let's say I create release 1 with a prefix "mycom1". My first client installs this - the objects are called mycom1__abc etc...If my client finds bugs, I fix them in the mycom1 and also in my golden source (yucks!). Let's say that I find that I do have to modify my objects. I go back to my golden source and and create a new managed package with prefix  "mycom2". I can give this to customer 2....Now I have to fix bugs in three places(really yucks!!!)

Does anyone have any better ideas or is my understanding flawed (I hope so).

I wish I could put beta managed packages in a production environment - I will have best of both worlds in that case!!!