Advertisement
Guest User

Untitled

a guest
Sep 24th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.33 KB | None | 0 0
  1. `<script>
  2. function complete1() {
  3. RedirectAccount();
  4. }
  5. </script>
  6. <apex:commandButton value="Update all Contacts" action="{!updateContacts}" rendered="{!IF(accList.size!=null, true, false)}" oncomplete="complete1();" >
  7. <apex:actionfunction name="RedirectAccount" action="{!RedirectAccount}"/>
  8. </apex:commandButton>
  9. <apex:messages />`
  10.  
  11. `public void cloneRec()
  12. {
  13. List<Contact> lstContact = [SELECT Accountid FROM Contact WHERE Splits__c=true];
  14. if(lstContact.size()>0){
  15. ID AccSel=lstContact[0].Accountid;
  16. system.debug('AccSel '+AccSel);
  17. Account acc = [SELECT Id,Name FROM Account WHERE Id =:AccSel];
  18. accClone = acc.clone(false,true,false,false);
  19.  
  20. List<Account> CheckAcc =[SELECT id, (SELECT Splits__c FROM Contacts) FROM Account WHERE id IN (SELECT AccountId FROM Contact WHERE Splits__c=true)];
  21.  
  22. if(CheckAcc.size()>1){
  23. ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'No splitting'));
  24. system.debug('CheckAcc.size() '+ CheckAcc.size());
  25. }Else{
  26. insert accClone;
  27. IsMade = '1';
  28. accClone.Name = 'TESTCLONE' + accClone.Name;
  29. update accClone;
  30. idOfRecNew = accClone.id;
  31. List<Contact> cons = new List<Contact>();
  32. List<Contact> con = [SELECT Id,firstname, LastName, AccountId,Splits__c FROM Contact WHERE AccountId = : acc.Id AND Splits__c=true];
  33. for(Contact c : con)
  34. {
  35. Contact conClone = c.clone(false,true,false,false);
  36. conClone.AccountId = accClone.Id;
  37. conClone.Splits__c = false;
  38. cons.add(conClone);
  39. }
  40. insert cons;
  41. List<Contact> conOld =[SELECT id,Accountid FROM Contact WHERE Splits__c=true AND Accountid =:AccSel];
  42. system.debug('conOld '+conOld);
  43. delete conOld;
  44. }
  45. }
  46. }
  47.  
  48. public PageReference RedirectAccount(){
  49. List<Account> CheckAcc =[SELECT id, (SELECT Splits__c FROM Contacts) FROM Account WHERE id IN (SELECT AccountId
  50. FROM Contact WHERE Splits__c=true)];
  51. if(IsMade=='1'){
  52. system.debug('redirection has fired ');
  53. PageReference retURL = new PageReference('https://cs89.salesforce.com/'+idOfRecNew);
  54. retURL.setRedirect(true);
  55. return retURL;}
  56. return null;
  57. }`
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement