If you have afib and you have your heart shocked to get it back on beat but fails. Then they do it again if that fails what do if that fails what do they do next.

Options. Options will include antiarrhythmic medications ( medications to help the heart stay in regular rhythm) or catheter/surgical ablation. This will usually depend on the age of the individual, presence of structural heart disease, cardiac risk factors, concern about antiarrhythmic medications, presence of other surgical indications, ..Etc.
If . If your physician still wants to pursue getting the heart back to a normal rhythm there are both catheter based methods and surgical methods to do a maze type procedure, which can be successful about 80% of the time. The surgical procedures are generally more reliable, but do require general anesthesia and a surgical incision. Another option is to decide that allowing the heart to remain in atrial fibrillation and use medications to control the heart rate. Generally with this approach a blood thinner is recommended to reduce the risk of having a stroke, but this is very dependent on individual circumstances.