• carramrod81
  • NEWBIE
  • 25 Points
  • Member since 2008

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 7
    Questions
  • 12
    Replies
Hi
 
Iam inserting records into the custom object.
The custom object is given look up Relation ship (The custom object appears in Opportunities tab)
 
I have wriiten a trigger which inserts records into the custom object.
The trigger is executing fine, but I am not able to see the records in the corrosponding Custom Object
 
I have checked about the presence of records in the Custom Object by writing a SOQL query
here the records are coming.
 
can any one suggest why the records are not displayed in the view part
 
please help me in solving this
 

Is there any way to implement Apex trigger like functionality on a before/after merge? Before the merge is called, i want to do some housecleaning and need at least the recordid of the master record and that of the discarded or merged records.

 

I know that you can't create a trigger like :  trigger autoAcceptRecord on Account (before merge) , but how can I mimic that functionality? As we have an external integration, we need to be able to know when duplicates in SFDC were merged so we can either change the ID in the other system, or delete the duplicate record on the other system and re-update the new master that was selected during the merge in SFDC.

 

I'm in a pickle, because there isn't functionality to tie an approval to a standard or custom object in a report, i'd like to pull down the data in the approval object and do a join with the custom object in question. My problem is is while the Approval object is queryable, it doesn't return any data in any tool i've hit it with.

 

My question is this, am I querying the correct object? Is there some hidden object containing Approval data that i can't see, which contains the data i need?

Hi,
I successfully wrote my first apex class/trigger AND got it into production with Eclipse after all was working on my dev account.
It works, but i started getting email exceptions that the class threw an exception because of too many SOQL queries (21).
This happened when i was doing a mass import of previous_user_codes__c. I know which part of the code is calling too many queries (in bold) but can't figure out how to move the the query outside the loop so i don't hit the limits. It works fine when the trigger is only one record, but as soon as it goes through with multiple Previous_User_Code__c (in bulk) it fails. FWIW i was loading 12000 Previous_User_Code__c.
Code:
public class cPreviousUserCodeRecordSave{
public static void checkForPrevious(Previous_User_Code__c[] pucs) {
for (Previous_User_Code__c p:pucs) {
if (p.Previous_User_Code__c != null) {
p.Name = p.Previous_User_Code__c;
String code = p.Previous_User_Code__c;
//load all accounts usercodes for this Previous User Code
Account[] Matches = [SELECT Name,ID,M_User_Code__c FROM Account
WHERE Account.M_User_Code__c =: code];


if(Matches.size() >= 1 && Matches[0].ID != p.Account__c) {
//this ID is already in another account, throw a warning
//do not allow saving in the Account.M_User_Code__c
p.Previous_User_Code__c.addError('This User Code is associated with another
account.<br> Account: ' + '<a href=https://na2.salesforce.com/' + Matches[0].ID + ' target=newWindow1>' +
Matches[0].Name + '</a>');
}
}
}
}
}



Message Edited by carramrod81 on 05-29-2008 07:39 AM
Hi,
I've created a trigger, and be it with my dev account or my production account, when i try and deploy with Eclipse, i get "Cannot deploy to project's organization" on the first page of the deploy wizard. I know my trigger works, as i've uploaded it and made it active on my development account, but obviously that isn't possible on production. This was modified from one of the cookbook examples on lead deduplication.

Please help:

trigger trDuplicatePreviousUserCodeCheck on Previous_User_Code__c (before insert, before update) {
Map<String, Previous_User_Code__c> ucMap = new Map<String, Previous_User_Code__c>();
for(Previous_User_Code__c puc : System.Trigger.new) {
    if((puc.Name != null) && (System.Trigger.isInsert ||
                                (puc.Name != System.Trigger.oldMap.get(puc.ID).Name))) {
                                   
                    if(ucMap.containsKey(puc.Name)){
                        puc.Name.addError('Another Account has this same previous user code');
                    } else {
                        ucMap.put(puc.Name, puc);
                    }
            }
}

for(Previous_User_Code__c puc : [SELECT Name FROM Previous_User_Code__c
                                 WHERE Name IN : ucMap.Keyset()]) {
        Previous_User_Code__c newPuc = ucMap.get(puc.Name);
        newPuc.Name.addError('This user code already exists.');
                                 }
   
}

i did read that i need some sort of test class, so i tried to create one but am still getting the same results. I created the class and did Force.com -> Run Tests and it does it's thing, but when i try and go back to the trigger to deploy, i get nothin. Am i doing all this correctly?

public class DuplicatePreviousUserCodeCheckTests {
  static testMethod void testUserCodeDupePreventer()
  {
      Set<String> testUserCodes = new Set<String>;
      testUserCodes.add('1');
      testUserCodes.add('2');
      testUserCodes.add('3');
      System.assert([SELECT count() FROM Previous_User_Code__c
                      WHERE Name IN: testUserCodes] == 0)
                     
      Previous_User_Code__c code1 = new Previous_User_Code__c(Name='1',Account=0014000000Hb89g,
                                                              Previous_User_Code='1');
      insert Previous_User_Code__c
     
  }
}


Message Edited by carramrod81 on 05-27-2008 09:23 AM
Hi,
I Have a custom object named Trip Log that has two lookups (account and contact). The user can only create a new Trip log from the contact level. When they create a new Trip Log off of a contact, the Contact lookup is obviously filled out, but the Account lookup is blank. Is there a way it can pull the associated account from the contact and populate this box?

Also another question, is there a way to check if the selected contact is part of the selected account?

thanks
carramrod
Hello,
I have a a very very simple custom object that i'd like to use to track previous customer numbers. The customer object is Previous_User_Code and it's fields are as follows
Account Master-Detail(Account)
Previous User CodeText(20) (External ID) (Unique Case Insensitive)

There is a field on the account named User_code__c.
When updating/inserting an account, after the insert/update when there is a value in user_code__c, i'd like to make sure that there is a record in the custom object Previous_User_code. If there is, then do nothing, else insert into the custom object.

The whole point of this is our base data has some duplication and when we merge accounts, i'd like to be able to track what the previous user codes were. By making the field Previous User Code in the custom object to an external Id, i should be able to search for old codes.
I'm a VB programmer, but can't find a good book beginners book on apex, (the cookbook doesn't seem to help much with the basics, just chunks of code).


Message Edited by carramrod81 on 05-21-2008 07:08 AM
    I'm using the leadDuplicatePreventer example in the cookbook to prevent a user from duplicating a product/serial number in assets. I've gotten it to work with only checking for unique serial number, but i'm stuck on getting it to check the Product2Id field as well. Could use a helping hand :)

trigger assetPreventDuplicateSerial on Asset (before insert, before update) {
    Map<String, Asset> assetMap = new Map< String, Asset>();
    for(Asset asset : System.Trigger.new){
    if((asset.SerialNumber != null) &&
        (System.Trigger.isInsert || (asset.SerialNumber != System.Trigger.oldMap.get(asset.id).SerialNumber))) {
            if (assetMap.containsKey(asset.SerialNumber) && assetMap.containsKey(asset.Product2ID)){
                asset.SerialNumber.addError('Another Asset has the same serial number');
            }
            else{
                assetMap.put(asset.SerialNumber,asset);
            }
        }
    }
   
    for(Asset asset : [SELECT SerialNumber FROM Asset
                        WHERE SerialNumber IN :assetMap.KeySet() AND
                        Asset.Product2Id IN :assetMap.KeySet()]) {
                            Asset newAsset = assetMap.get(asset.SerialNumber);
                            newAsset.SerialNumber.addError('An asset with this serial number already exists.');
                        }
       
   
}

Hey,

 

Couple of questions about merging Accounts, where there's one Master Acct and one or two 'victims':

  1. Clearly this causes an update to the Master and deletions to the victims.  Presumably these DML operations fire whatever Apex triggers are there.  Is there some field on the Account object that I can consult in an Update trigger, to tell me that this update was the result of a merge?  And - is there anything that gets set on a 'victim' Acct just before it's deleted, that a Delete trigger can consult to see that this deletion was the result of a merge - and to which Master Acct?
  2. The documentation says that all related lists of a 'victim' Acct are re-parented to the Master Acct.What about this operation - does it cause the Update triggers to fire on those related lists?  (I have a suspicion the answer is 'no'.)

Anyone out there know about this stuff?

 

Thanks!

  • November 18, 2009
  • Like
  • 0
hi,

I am facing a problem regarding picklist's selected value. I am not able to save the picklist's selected Value into a custom field
that is already created on an SObject. Please let me know any way or solution to get the ID or somthing so that i can save the picklist's selected value in my custom field.


regards,
Akash

  • June 26, 2008
  • Like
  • 0
I am feeling my way through Apex.... I am trying to modify this code to allow it to run in bulk (data loader)  I am just a little confused about how to get there.  I am guessing I should replace what I have in red with a list.  I am unsure on how to make this
usable in bulk?? any help would be greatly appreciated!!! thanks!!!!!!  Fred
Code:
trigger UpdatePrimaryQuoteOnOpp on Quote__c (after insert, after update) {
for (Quote__c q : Trigger.new)
{   
        String OppId = q.Opportunity__c;
        String CurrentQuoteId = q.Id;
        String CurrentQuoteStage = q.Stage__c;
                try{
            Quote__c[] allquotes = [Select Quote__c.Id, Quote__c.Date_Closed__c, Quote__c.Opportunity__c, Quote__c.Stage__c 
            FROM Quote__c WHERE Quote__c.Opportunity__c = :OppId ORDER BY Quote__c.Date_Closed__c DESC];
            if(allquotes.size()>0)
            {
                //Opportunity o = [select Id from Opportunity where Id=:q.Opportunity__c]; 
                Opportunity o = new Opportunity(Id=OppId);

                //if there is only one quote, use that one
                if(allquotes.size() == 1)
                {
                    o.Primary_Quote__c = CurrentQuoteId;
                    o.StageName = CurrentQuoteStage;
                    update o;
                }
                else        //else there is more than one, so we must find the one with most advanced stage
                {
                    Quote__c FinalQuote = New Quote__c();
                    Integer FinalStage = 0;
                    
                    for (Integer i = 0; i < allquotes.size(); i++)
                    {
                        Integer NewStage = 0;
                        if(allquotes[i].Stage__c == 'Closed Won')
                        {
                            NewStage = 7;
                        }
                        else if(allquotes[i].Stage__c == 'Finalist')
                        {
                            NewStage = 6;
                        }
                        else if(allquotes[i].Stage__c == 'Released to Client')
                        {
                            NewStage = 5;
                        }
                        else if(allquotes[i].Stage__c == 'Released to Sales')
                        {
                            NewStage = 4;
                        }
                        else if(allquotes[i].Stage__c == 'In Underwriting')
                        {
                            NewStage = 3;
                        }
                        else if(allquotes[i].Stage__c == 'Closed Lost')
                        {
                            NewStage = 2;
                        }
                        else if(allquotes[i].Stage__c == 'Closed Sales Declined')
                        {
                            NewStage = 2;
                        }
                        else if(allquotes[i].Stage__c == 'Closed U/W Declined')
                        {
                            NewStage = 2;
                        }
                        //now we evaluate
                        
                        if(NewStage > FinalStage)
                        {
                            //check to see which one is most recent
                            FinalQuote = allquotes[i];
                            FinalStage = NewStage;
                            
                        }
                    }
                    
                    o.Primary_Quote__c = FinalQuote.Id;
                    o.StageName = FinalQuote.Stage__c;
                    update o;
                }
                
                /*Qualify
                In Underwriting
                Released to Sales
                Released to Client
                Finalist
                Closed Lost
                Closed Won
                Closed Sales Declined
                Closed U/W Declined*/
            }
        }
        catch(Exception e){}
}
}

 

I want to remind task owner (through e-mail) 2 days before a task is due.
I want to send them another e-mail when the task becomes due (on due date).
Finally I want to send them yet another e-mail if task is overdue by more than 2 days.

Workflow rules on tasks do NOT allow creation of e-mail alerts.

How do I do this?

Salesforce has "Reminder popups" - but this works only if the user logs into the app!






Hi
 
Iam inserting records into the custom object.
The custom object is given look up Relation ship (The custom object appears in Opportunities tab)
 
I have wriiten a trigger which inserts records into the custom object.
The trigger is executing fine, but I am not able to see the records in the corrosponding Custom Object
 
I have checked about the presence of records in the Custom Object by writing a SOQL query
here the records are coming.
 
can any one suggest why the records are not displayed in the view part
 
please help me in solving this
 
Hi
 
I have created a custom object, Iam inserting the records by apex code
this is code I had wriiten
 
 
Scheduling__c sch=new Scheduling__c();

sch.Name='My Scheduling Name';
sch.Line_Description__c=sch_desc;
sch.Date__c=sch_date;
insert sch;
 
My records are inserted into Custom object but they are not visible in the UI part
 
I have checked by writing a SOQL query, Iam getting the inserted values in System.debug() when I click Run Test
 
why the records are not displayed in the view part
 
can any one suggest me a solution
 

 
Hi,
I successfully wrote my first apex class/trigger AND got it into production with Eclipse after all was working on my dev account.
It works, but i started getting email exceptions that the class threw an exception because of too many SOQL queries (21).
This happened when i was doing a mass import of previous_user_codes__c. I know which part of the code is calling too many queries (in bold) but can't figure out how to move the the query outside the loop so i don't hit the limits. It works fine when the trigger is only one record, but as soon as it goes through with multiple Previous_User_Code__c (in bulk) it fails. FWIW i was loading 12000 Previous_User_Code__c.
Code:
public class cPreviousUserCodeRecordSave{
public static void checkForPrevious(Previous_User_Code__c[] pucs) {
for (Previous_User_Code__c p:pucs) {
if (p.Previous_User_Code__c != null) {
p.Name = p.Previous_User_Code__c;
String code = p.Previous_User_Code__c;
//load all accounts usercodes for this Previous User Code
Account[] Matches = [SELECT Name,ID,M_User_Code__c FROM Account
WHERE Account.M_User_Code__c =: code];


if(Matches.size() >= 1 && Matches[0].ID != p.Account__c) {
//this ID is already in another account, throw a warning
//do not allow saving in the Account.M_User_Code__c
p.Previous_User_Code__c.addError('This User Code is associated with another
account.<br> Account: ' + '<a href=https://na2.salesforce.com/' + Matches[0].ID + ' target=newWindow1>' +
Matches[0].Name + '</a>');
}
}
}
}
}



Message Edited by carramrod81 on 05-29-2008 07:39 AM
 I am trying to use the Case Detachifier, but when I attempt to log in I recevie the following error:

Error: Unable to login.
LOGIN_MUST_USE_SECURITY_TOKEN: Invalid Username, password, security token; or user

I know my creds are correct as I ca log into the online app with them.

I notice in the documentation that there was an issue with login for the SF Professional edition that was to be resolved 1/17/2007. Has this been resolved?

Thanks,

 - JK
Hi,
I've created a trigger, and be it with my dev account or my production account, when i try and deploy with Eclipse, i get "Cannot deploy to project's organization" on the first page of the deploy wizard. I know my trigger works, as i've uploaded it and made it active on my development account, but obviously that isn't possible on production. This was modified from one of the cookbook examples on lead deduplication.

Please help:

trigger trDuplicatePreviousUserCodeCheck on Previous_User_Code__c (before insert, before update) {
Map<String, Previous_User_Code__c> ucMap = new Map<String, Previous_User_Code__c>();
for(Previous_User_Code__c puc : System.Trigger.new) {
    if((puc.Name != null) && (System.Trigger.isInsert ||
                                (puc.Name != System.Trigger.oldMap.get(puc.ID).Name))) {
                                   
                    if(ucMap.containsKey(puc.Name)){
                        puc.Name.addError('Another Account has this same previous user code');
                    } else {
                        ucMap.put(puc.Name, puc);
                    }
            }
}

for(Previous_User_Code__c puc : [SELECT Name FROM Previous_User_Code__c
                                 WHERE Name IN : ucMap.Keyset()]) {
        Previous_User_Code__c newPuc = ucMap.get(puc.Name);
        newPuc.Name.addError('This user code already exists.');
                                 }
   
}

i did read that i need some sort of test class, so i tried to create one but am still getting the same results. I created the class and did Force.com -> Run Tests and it does it's thing, but when i try and go back to the trigger to deploy, i get nothin. Am i doing all this correctly?

public class DuplicatePreviousUserCodeCheckTests {
  static testMethod void testUserCodeDupePreventer()
  {
      Set<String> testUserCodes = new Set<String>;
      testUserCodes.add('1');
      testUserCodes.add('2');
      testUserCodes.add('3');
      System.assert([SELECT count() FROM Previous_User_Code__c
                      WHERE Name IN: testUserCodes] == 0)
                     
      Previous_User_Code__c code1 = new Previous_User_Code__c(Name='1',Account=0014000000Hb89g,
                                                              Previous_User_Code='1');
      insert Previous_User_Code__c
     
  }
}


Message Edited by carramrod81 on 05-27-2008 09:23 AM
Hi All,
 
As a new user to Salesforce, I am investigating ways in which we can clean up our data.  One of our main issues is duplicate contact information.  I have found some good products on Appexchange that allow duplicates to be detected via a report, however I am wondering if anything is available that would actually detect possible duplicates as the user is entering the information into Salesforce. 
 
Has anyone come across a product that would provide this, or is it something that would be available through some custom code?
 
Cheers,
Andrew
Hi,
I Have a custom object named Trip Log that has two lookups (account and contact). The user can only create a new Trip log from the contact level. When they create a new Trip Log off of a contact, the Contact lookup is obviously filled out, but the Account lookup is blank. Is there a way it can pull the associated account from the contact and populate this box?

Also another question, is there a way to check if the selected contact is part of the selected account?

thanks
carramrod