I'm new to SalesForce. What happens when the Convert button on the Lead Details page is clicked? I've read that   The lead is marked as 'closed'. An Account object is created. An Opportunity tied to the Account is also created.   Where is this workflow documented? Where can I see the code that does it?  How can I intercept or extend this to create/re-parent other objects that need to lose their association to the lead and be associated with the new Account and Opportunity.  When I explore Customize > Leads, there are no validation rules, triggers, assignment rules, processes, or whatnot that would lead me in the right direction (excuse the pun).  I've also explored create > Workflow and Approvals to no avail.  Is this covered in any of the Force.com Workbooks, or perhaps any 3rd party books.  Mucho Puzzled.  Edit (1): I found the following:   which covers the general process.  and this:    This may help someone else looking for the same thing.  Edit (2): Marked as duplicate  I checked the referenced question regarding the order of trigger execution. In the context of this question, I do not care about the order of trigger execution; my question attempts to elicit what changes when a lead is connverted and how the process might be extended. The two links in Edit (1) answer the process side of the question and the mechanism by which the process can be extended.
76257
I've got a project where I'm looking to tweak the standard lead conversion process.   Triggers and lead conversion has always been funky in past projects so I was hoping to start the design off by reviewing the order of execution, but after a long google search I'm coming up empty handed.   Anyone out there know the specific trigger order for lead conversion?    Edit: I'm not asking about trigger execution order for any object, but all the objects created in the lead conversion process.  I'd think it would be something like this:        Lead Before Update Triggers (isConverted = false, convertedAccountId = null, convertContactId = null, convertedOpportunityId = null)         Account Before Insert Triggers (not fired if merged with existing account)   Account After Insert Triggers (not fired if merged with existing account)   Contact Before Insert Triggers (not fired if merged with existing contact)   Contact After Insert Triggers (not fired if merged with existing contact)   Opportunity Before Insert Triggers (not fired if no opportunity) (OpportunityContactRoles null)   Opportunity After Insert Triggers (not fired if no opportunity) (OpportunityContactRoles = convertedContactId)   Lead After Update Triggers (isConverted = true, convertedAccountId = XXX, convertedContactId = XXX, convertedOpportunityId = XXX)
64525
I'd like to do something pretty straightforward: After user fills out a , I'd like a button that simply redirects them to a URL (in this case it's to a demo sandbox). Of course I'd want the user to fill in their info to capture for lead-generation purposes. My  is set up correctly in that it correctly captures all the user fields and submits them to me via email. However, upon completion "click" I'd like to have the user redirected to a determined internal URL www.mysite.com/foo  I can't figure out how this is done with the vanilla webform settings. Am I missing something obvious?
32675
I have a VF page that is the 'edit' page for a certain object. I have a button 'Clone'. Upon clicking this button, I wish to be redirected to a new edit page with all the previous objects fields still intact (except for a few that should be cleared and set to default). Note that this new object should not be inserted until I click 'Save'. The Id of the object should be different compared to the previous object, so that on Save, the previous object is not overwritten.   I am thinking I will split this up into two parts, an apex method, and a javascript method for resetting the fields:  &lt;apex:commandButton action="{!saveAsTemplate}" onclick="initTemplate();" value="Clone" /&gt;   The javascript portion is easy enough, but I'm having trouble of figuring out what to do on the apex side, besides for setting the id of the record to null.
71582
I have a URL button 'New Opportunity' which creates the new opportunity and takes the user to the edit page passing through some values through the button which is on Opp Related List in a custom object.  The problem is, now I need to adapt the majority of my custom buttons to Salesforce1 and this app doesn't accept custom buttons so I need to create a Publisher Action in order to replicate the same action.  I've created a Publisher Action redirecting to a Visualforce. Inside this visualforce I've tried passing the values through the sforce.one.navigateToURL(); function using the standard controller values  to redirect, but this doesn't seem to work. Do you know of a workaround for this?  URL Button Code: /006/e?&amp;retURL=%2Fa0BS0000002pJhs&amp;opp4={!Estudio_economico__c.Empresa__c}&amp;opp3=No informar&amp;RecordType=01220000000Iw8t&amp;CF00N20000002GXnJ_lkid={!Estudio_economico__c.Id}&amp;CF00N20000002GXnJ={!Estudio_economico__c.Name}
61376
I have a condition where I need to disable standard Lead Assignment Rules if certain criteria are met.   if(emailWithAccIdMap.containsKey(ledRec.Email) &amp;&amp; emailWithAccIdMap.get(ledRec.Email) != null &amp;&amp; !openOppMap.isEmpty() &amp;&amp; openOppMap.get(emailWithAccIdMap.get(ledRec.Email)) != null &amp;&amp; openOppMap.get(emailWithAccIdMap.get(ledRec.Email)).Owner.isActive ==true){                     ledRec.Status = 'Duplicate';                     System.debug('Changing the Status');                     //then assign the original lead owner to new lead owner                     ledRec.OwnerId = openOppMap.get(emailWithAccIdMap.get(ledRec.Email)).OwnerId;                     ledRec.Account_Name__c = openOppMap.get(emailWithAccIdMap.get(ledRec.Email)).AccountId;                     ledRec.Field_for_Lead_Workflow__c = true;                     Database.DMLOptions dmo = new Database.DMLOptions();                     dmo.assignmentRuleHeader.useDefaultRule = false;                     ledRec.setOptions(dmo);                     //since owner is assigned, it shouledRec not pass through round robin                     ledRec.checkAssignment__c = false;  }   This is my code snippet which is running on before insert. The control is entering the IF condition as the debug statement is getting printed. Yet, the owner assigned through this snippet is being overridden by the assignment rules.  I also tried executing this in after insert trigger context but it did not work. Can somebody tell me what I'm doing wrong?
80179
i have created a trigger which creates an opprtunity when the accounte is created and i have a custom field No of contact on account which displays the count of related contact for a particular account whenever it is updated.  I have tested seperated that the opportnity is created but for the second part ,it displays a big error when i try to save a record.  I am not getting any error while saving a record.Can someone help      trigger insertOpp on Account(After insert,after update,before update) { List&lt;Opportunity&gt; opplist=new List&lt;Opportunity&gt;(); for(Account acc:Trigger.new){  Opportunity op=new Opportunity(); op.Name='Cook'; op.accountid=acc.id; op.CloseDate=System.today(); op.StageName='Qualification'; opplist.add(op); }  insert opplist;     if(trigger.isupdate) {         Integer no_of_contact;         String accID;      for(Account c:Trigger.new )     {         accid = c.id;      }      account acclist = new account();     acclist = [select No_of_Contacts__c from account where id = :accid ];     no_of_contact = [SELECT count() FROM Contact WHERE AccountId = :accid];     acclist.No_of_Contacts__c = no_of_contact;     //update acclist;  }  }   ERROR:       Review all error messages below to correct your data. Apex trigger   insertOpp caused an unexpected exception, contact your administrator:   insertOpp: execution of AfterUpdate caused by: System.DmlException:   Update failed. First exception on row 0 with id 00128000002r8gKAAQ;   first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, insertOpp: maximum   trigger depth exceeded Account trigger event AfterUpdate for   [00128000002r8gK] Account trigger event AfterUpdate for   [00128000002r8gK]
95834
I have an approval process on a Custom object and also two custom buttons on the same record.  Once the record goes into the approval process, it gets locked. During that period, I want to disable/hide the two custom buttons.  How can I check if the record/custom object is locked or not using Apex?  And how can I disable/hide the buttons?
98624
I'd like to write a Lead trigger, to check for duplicate Contacts before inserting the lead, or converting it.   Contacts fields I'd like to check:   Firstname - should not be the same as the leads name Lastname - should not be the same as the leads name Email - should not be the same as the leads phone   After checking these fields &amp; failing to find a duplicate, only then should the lead be converted.
16290
This is a canonical question and answer developed by the community to help address common questions. If you've been directed here, or your question has been closed as a duplicate, please look through the resources here and use them to shape more specific questions. To browse all canonical questions and answers, navigate to the  tag. This question and answer is owned by the community! If you can improve it and make it more useful, you're welcome to edit it. I am building a trigger, a unit test, or other Apex code. I'm working with sObject records, and trying to access related record information. For example, I might have a structure like this: Account a = new Account(Name = 'Test'); insert a;  Opportunity o = new Opportunity(Name = 'Donation', AccountId = a.Id); insert o;  System.assertEquals(o.Account.Name, 'Test', 'Correct Account associated'); // Assertion fails!  Or, in a trigger, I might be aiming for something like this: trigger ContactTrigger on Contact (after insert) {     for (Contact c : Trigger.new) {         if (c.Account.Name == 'Test') {             // Take some action here         }      } }  Why doesn't this work? Why am I getting null values, or NullPointerExceptions?
46169
I'm getting an error INACTIVE_OWNER_OR_USER, operation performed with inactive user, and I have been doing a lot of research and the cause that I have found for this is its attempting to assign a my lead to inactive user.  So I understand that part I think the issue is now I don't actually know how to fix it, I didn't write this trigger/test class and I'm not sure how to go forward.  Do I need to create a new Test User?  I've never worked on the Lead object before..  Edit** I added IsActive = True the trigger user query, no luck.  Edit** I just went talking to anyone that might have an idea about UserTypes, and they have no idea what UserType = 'PowerPartner' is.  So I changed it to a different UserType.. didn't work  Edit**  I'm nuking this trigger, I have to re write it..  Test Class  @isTest private class PartnerLeadShare_test { static testMethod void myUnitTest1() { List&lt;Lead&gt; leadList = new List&lt;Lead&gt;(); List&lt;LeadShare&gt; leadShareList = new list&lt;LeadShare&gt;();   Lead ld = new Lead(); ld.lastName = 'Tester';//=/ ld.Company = 'MyCompany'; ld.Status = 'Open'; ld.Program_EAU__c ='11'; insert ld; system.debug('ld****' +ld);  GroupMember groupMemberStore = [select GroupId,UserOrGroupId from GroupMember limit 1];  LeadShare ls = new LeadShare();  ls.LeadId = ld.id; ls.UserOrGroupId = groupMemberStore.UserOrGroupId ; ls.LeadAccessLevel = 'Edit'; leadShareList.add(ls);   if(leadShareList.size()&gt;0){     system.debug('INSIDE LEADSHARE LIST.');      insert leadShareList;  }  } }   Don't know this will help but here is my trigger..  trigger PartnerLeadShare on Lead (after insert,after update) {  Map&lt;id,User&gt;PartnerUsermap = new Map&lt;id,user&gt;([select id,UserType from user where      UserType = 'PowerPartner' and IsActive = True] );    List&lt;GroupMember&gt;GroupMemberList = new List&lt;GroupMember&gt;([select GroupId,UserOrGroupId   from GroupMember]);   System.debug('PartnerUsermap ===  '  +PartnerUsermap); System.debug('GroupMemberList    '+GroupMemberList );  List&lt;LeadShare&gt; leadShareList = new list&lt;LeadShare&gt;();    if(!PartnerUsermap.isEmpty()){ for(Lead ld: trigger.new){      for(GroupMember grpmem : GroupMemberList){         if(grpmem.UserOrGroupId == ld.CreatedById){               LeadShare ldShare = new LeadShare (LeadId = ld.id,UserOrGroupId = grpmem.GroupId,LeadAccessLevel = 'Edit');              leadShareList.add(ldShare );         }     } } } if(!leadShareList.isEmpty()){ Database.SaveResult[] lsr = Database.insert(leadShareList,false);            Integer i=0; for(Database.SaveResult sr : lsr){     if(!sr.isSuccess()){     Database.Error err = sr.getErrors()[0];              if(!(err.getStatusCode() == StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION                                              &amp;&amp;  err.getMessage().contains('AccessLevel'))){                  trigger.newMap.get(leadShareList[i].LeadId).                   addError(                    'Unable to grant sharing access due to following exception: '                    + err.getMessage());             }     }    i++; } }
113537
I am trying to create a validation rule to lock down our original utm fields on leads after they are first populated.  Essentially I would like to prevent everyone (including our marketo sync user) but a 'system admin' to be able to update the fields below.  I think I have the Rule down for the most part, but I keep getting a syntax error "Missing ')'", please see below. Any help would be appreciated.  AND(     $Profile.Name &lt;&gt; "System Administrator",     ISCHANGED( OG_Lead_Source__c ),     NOT(ISBLANK(PRIORVALUE( OG_Lead_Source__c )))     ISCHANGED( OG_Lead_Medium__c ),     NOT(ISBLANK(PRIORVALUE( OG_Lead_Medium__c )))     ISCHANGED( OG_Lead_Campaign__c ),     NOT(ISBLANK(PRIORVALUE( OG_Lead_Campaign__c )))     ISCHANGED( OG_Lead_Content__c ),     NOT(ISBLANK(PRIORVALUE( OG_Lead_Content__c )))     ISCHANGED( OG_Lead_Term__c ),     NOT(ISBLANK(PRIORVALUE( OG_Lead_Term__c ))) )
33745
I'm writing a trigger for new opportunity products to populate  a field Product_Category__c (on opportunity lineitem) getting the value from Product_Category_new__c (on Product).  This is my trigger:  trigger SetProductCategory on OpportunityLineItem (after insert) {      for (OpportunityLineItem opplineitem: Trigger.new) {                    opplineitem.Product_Category__c =  opplineitem.PricebookEntry.Product2.Product_Category_new__c;     }      }   I get this error message:     execution of AfterInsert caused by: System.FinalException: Record is read-only   I have tried with before insert;in this case there aren't errors but the value Product category it's not saved on Opportunity Line item.  I have found that:  In a after insert trigger is not allowed change field using trigger.new  Please can you suggest a solution for this? i would like to copy the value Product category (Product) on Product Category (Opportunity Product)  after the insert of the new opportunity products.  Thanks in advantage for any advice.  Br
105554
I encountered a problem in Journey Builder, where decision splits that check for changes in Salesforce Service Cloud (filter expression is configured to retrieve Contact Data from synchronized data extension) don't lead to the path they should. The data is definitely synced correctly, as retrieving the changed data from the synchronized data extension via AMPscript in a mail sent by the journey leads to the correct result (retrieving the data using the salesforce-id of the object that is present in event/journey data).  This problem occurs every time a contact enters the journey more than once (which is legitimate as there can be more than one trigger object per contact (in my use case these objects represent offers for a customer)) and decision splits should act on changes in service cloud. However this shouldn't be a problem as the changed record can be uniquely identified by a salesforce id and even the journey is triggered by this very service cloud custom object (Salesforce Data Event).  Summary:   Salesforce Data event triggers the journey (update of custom object X) The contact has a 1-to-many relationship to custom object X Salesforce Contact-Id is used as subscriber key Waiting steps in journey are long enough for synchronization to definitely happen Data is synchronized correctly and can be retrieved via AMPscript Contact Data decision split doesn't evaluate correctly
120010
I want to create a workflow rule which should be triggered when I change the Lead Status value from 'Open: Not Contacted' to 'Open: Working'  Any help with this please?
41775
I'm trying to determine in a trigger, whether a lead belongs to a Queue or a User. What is the best way of going about this?  I tried the method mentioned in a dev. force discussion:  System.debug( lead.Owner.type )   ... but this consistently keeps fetching null.  Alternatively, I was trying to determine by first 3 characters of the OwnerId (005 for User, 00G for Queue). I tried using:  lead.OwnerId.substring( 3 ) == '005'    Trying the above gets me Method does not exist or incorrect signature.  Any bright ideas here?  Thank you.
7773
The official documentation from Salesforce is to use Salesforce Data Extensions if you want to push tracking information from Marketing Cloud to Salesforce ().  This is what we've done but I've noticed that after creating data extensions in the data extensions folder, emails sent are still being tracked and tracking is still being sent to Salesforce.   My question is can I create data extensions anywhere and tracking will always be sent to sales cloud? what do i need to look out for to insure that tracking is being sent?
86786
I have a problem with my trigger. In Sandbox, everything works fine. When I deploy it to production, I receive multiple exceptions - which is really strange, because I got angry and put the whole code in &quot;try&quot; block. When I put everything in &quot;try&quot; block, it shouldn't be possible not to catch an exception! This is how my code looks: trigger UpdateLeadField on Lead (before insert, before update) {      //debugging in progress     try{         if(Trigger.New[0].SomeField__c==NULL)         {             for(Lead obj: trigger.new)                 obj.SomeField__c = obj.OwnerId;             return;         }              if (Trigger.New[0].OwnerId != Trigger.Old[0].OwnerId)          {             for(Lead obj: trigger.new)             {                 if(Trigger.New[0].SomeField__c==NULL || [SELECT Name FROM UserRole Where Id = :[SELECT Id, UserRoleId FROM User WHERE Id = :obj.OwnerId][0].UserRoleId].Name == 'Some role')                 obj.SomeField__c = obj.OwnerId;             }         }     }     catch (Exception e)     {         System.debug(e);     } }  The main problem seems to be with Web-to-Lead - When deployed, it stops working. The exception:  Apex script unhandled trigger exception by user/organization: 005C00000XXXXXX/00XXXXX0000LXXQ UpdateLeadField: data changed by trigger for field Some field: id value of incorrect type: 00GC00000XXXXXqMAC  &quot;Some field&quot; is a lookup field.