function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
PbondalapatiPbondalapati 

assign the account if contact is created with out account if account name is abc

assign the account if contact is created with out account if account name is abc ,

i created the trigger , but i account abc is deleted , so how can i manage that .

i want to put a rule that , if contact is created without account , then the contacts aaccount is 'abc'.

if abc is deleted then no account is assigned to that contacts.  

Best Answer chosen by Admin (Salesforce Developers) 
PbondalapatiPbondalapati

 Account a = [Select Id from Account where Id='001M0000007VNAe' limit 1];       

        for(Contact c :trigger.new){ 

     if(a != null){       

    if(trigger.new[0].accountid == null){         

      system.debug('>>> Selected Id - '+a.Id);   

     Contact unAssignedCon = trigger.new[0];       

        unAssignedCon.AccountId = a.Id;   

       } 

}

}

This is i written , can you please update it for , if the account is that is deleted then contact is not assigne any account. 

All Answers

NzgonNzgon

Every record has flag (field) IsDeleted that you can use in your code (logic).

 

Nash

PbondalapatiPbondalapati

 Account a = [Select Id from Account where Id='001M0000007VNAe' limit 1];       

        for(Contact c :trigger.new){ 

     if(a != null){       

    if(trigger.new[0].accountid == null){         

      system.debug('>>> Selected Id - '+a.Id);   

     Contact unAssignedCon = trigger.new[0];       

        unAssignedCon.AccountId = a.Id;   

       } 

}

}

This is i written , can you please update it for , if the account is that is deleted then contact is not assigne any account. 

This was selected as the best answer