• Smadav AV
  • NEWBIE
  • -1 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 4
    Replies
For instance, we have "Custom Object A" and "Custom Object B" (Master-detail relationship). And Custom Object A has Record Type 'A' & 'B', Custom Object B has Record Types 'A1' & 'B1'. So, whenever I create a custom object 'A' record with record type 'A' and try to create a child object (Cus. Object B) through related list of Cus. Object A, it should automatically select record type 'A1' of Cus. object 'B' and same with record type 'B1' of cus. object B.

If (Custom Object A's record RT is A ---> Then Custom Object B's record RT should 'A1')
If (Custom Object A's record RT is B ---> Then Custom Object B's record RT should 'B1')

I've tried PB, WF, VR... but doesn't meet my requirement cuz i need the logic to be applied while creating the records of Cus. Object B, not after creating the record (needed to be in ligtning). There's coding solution for this requirement (below is the link) but it doesn't work if we click "Cancel" or "Save & New" button. I really appreciate if anyone could help.
https://force201.wordpress.com/2011/05/21/automatically-setting-the-record-type-of-a-detail-object-based-on-the-record-type-of-its-master-object/ 
 

 
Hi all,

We need to implement the following pattern at my org:
  • callout to external data source
  • if that callout takes too long (according to some configurable threshold), log an error (ie do some DML)
  • if that callout timed out on the remote server, try it again
Recognizing the potential for the dreaded "You have uncommitted work pending. Please commit or rollback before calling out." error, I put the error logging code in a future method, thus isolating the DML from the callouts. However, the error is still being thrown. I reduced the issue down to this pattern:
public static void foo() {
    Http http = new Http();
    HttpRequest req = new Httprequest();
    req.setEndpoint('https://test.salesforce.com'); //whatever endpoint
    req.setMethod('GET');
    http.send(req); //works fine
    bar();
    http.send(req); //throws calloutexception
}

@future public static void bar() {

}
Am I correct to assume that calling a future method counts as a DML operation? Is there any documentation I'm missing somewhere?

 

I'm trying to copy a new user as contact by using a trigger but I'm getting the following error

 

MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): Contact, original object: User

 

trigger Acceleration_User_Copyto_Contact on User (after insert, after update) {
    
   // Map<String,User> newLead = new Map <String, User>();
    
    system.debug('Acceleration_User_Copyto_Contact Trigger....');
 
    for ( User user : System.Trigger.new)
    {
        if  (user.Email.contains('acceleration'))
        {
            system.debug('Acceleration_User_Copyto_Contact Trigger..2.');
            Integer RecordCount = [select count() from Contact c where c.Email = : user.Email];
            
            system.debug('Acceleration_User_Copyto_Contact Trigger..2a .' + RecordCount);
            
            if (RecordCount == 0)
            {
                String AccountId = '';
                for ( Account a : [Select a.Id From Account a where Name = 'Acceleration']) 
                {
                    system.debug('Acceleration_User_Copyto_Contact Trigger..3.');
                     
                    AccountId = a.Id;
                
                    Contact con = New Contact();
                    con.AccountId = AccountId ;
                    con.Email = user.Email;
                    con.Firstname = User.Firstname;
                    con.Lastname = User.Lastname ;
                    con.User__c = User.Id;
                    insert con;
                }          
            }                   
        }
        
     }
    
    
}