You need to sign in to do that
Don't have an account?
Vignesh Ramshetty
Changees are not relecting
Hi able to save the class but changes are not reflectiong in the account
trigger Checking on Customer_Policy_details__c (Before Insert , Before Update , After Insert , After update) {
if(trigger.isbefore == true &&(trigger.isinsert == true || trigger.isupdate == true)) {
CPDclass.beforemethod(trigger.new);
}
if(trigger.isafter == true &&(trigger.isinsert == true || trigger.isupdate == true)) {
CPDclass.Aftermethod(trigger.new);
}
Public Class CPDclass{
Public Static void beforemethod(List<Customer_Policy_details__c> CPDlist){
for(Customer_Policy_details__c varc : CPDlist){
varc.Text_for_before__c = 'before exec';
}
}
Public Static void Aftermethod(List<Customer_Policy_details__c> CPDlist1){
set<string> varset = new set<string>();
for(Customer_Policy_details__c varc : CPDlist1){
varset.add(varc.Account__r.id);
}
system.debug(varset.size());
List<Account> varacc = [SELECT id,Name,(SELECT id FROM Customer_Policy_details__r) From Account Where id in: varset];
if(varacc.size() > 0) {
for(Account a :varacc){
a.Name = 'after exec';
}
update varacc;
}
}
}
trigger Checking on Customer_Policy_details__c (Before Insert , Before Update , After Insert , After update) {
if(trigger.isbefore == true &&(trigger.isinsert == true || trigger.isupdate == true)) {
CPDclass.beforemethod(trigger.new);
}
if(trigger.isafter == true &&(trigger.isinsert == true || trigger.isupdate == true)) {
CPDclass.Aftermethod(trigger.new);
}
Public Class CPDclass{
Public Static void beforemethod(List<Customer_Policy_details__c> CPDlist){
for(Customer_Policy_details__c varc : CPDlist){
varc.Text_for_before__c = 'before exec';
}
}
Public Static void Aftermethod(List<Customer_Policy_details__c> CPDlist1){
set<string> varset = new set<string>();
for(Customer_Policy_details__c varc : CPDlist1){
varset.add(varc.Account__r.id);
}
system.debug(varset.size());
List<Account> varacc = [SELECT id,Name,(SELECT id FROM Customer_Policy_details__r) From Account Where id in: varset];
if(varacc.size() > 0) {
for(Account a :varacc){
a.Name = 'after exec';
}
update varacc;
}
}
}
Please try and execute the below:
trigger Checking on Customer_Policy_details__c(Before Insert, Before Update, After Insert, After update) {
if (trigger.isbefore && (trigger.isinsert || trigger.isupdate)) {
CPDclass.beforemethod(trigger.new);
}
if (trigger.isafter && (trigger.isinsert || trigger.isupdate)) {
CPDclass.Aftermethod(trigger.new);
}
}
public Class CPDclass {
public static void beforemethod(List < Customer_Policy_details__c > CPDlist) {
for (Customer_Policy_details__c varc: CPDlist) {
varc.Text_for_before__c = 'before exec';
}
}
public static void Aftermethod(List < Customer_Policy_details__c > CPDlist1) {
Set < Id > setOfAccountIds = new Set < Id > ();
for (Customer_Policy_details__c varc: CPDlist1) {
setOfAccountIds.add(varc.Account__c);
}
List < Account > lstOfAccount = new List < Account > ();
for (Account accountRec: [SELECT id, Name, (SELECT id FROM Customer_Policy_details__r) From Account Where id in: setOfAccountIds]) {
accountRec.Name = 'after exec';
lstOfAccount.add(accountRec);
}
if (!lstOfAccount.isEmpty())
update lstOfAccount;
}
}
All Answers
What is the issue?
Thanks!!
when the record is saved
Please try and execute the below:
trigger Checking on Customer_Policy_details__c(Before Insert, Before Update, After Insert, After update) {
if (trigger.isbefore && (trigger.isinsert || trigger.isupdate)) {
CPDclass.beforemethod(trigger.new);
}
if (trigger.isafter && (trigger.isinsert || trigger.isupdate)) {
CPDclass.Aftermethod(trigger.new);
}
}
public Class CPDclass {
public static void beforemethod(List < Customer_Policy_details__c > CPDlist) {
for (Customer_Policy_details__c varc: CPDlist) {
varc.Text_for_before__c = 'before exec';
}
}
public static void Aftermethod(List < Customer_Policy_details__c > CPDlist1) {
Set < Id > setOfAccountIds = new Set < Id > ();
for (Customer_Policy_details__c varc: CPDlist1) {
setOfAccountIds.add(varc.Account__c);
}
List < Account > lstOfAccount = new List < Account > ();
for (Account accountRec: [SELECT id, Name, (SELECT id FROM Customer_Policy_details__r) From Account Where id in: setOfAccountIds]) {
accountRec.Name = 'after exec';
lstOfAccount.add(accountRec);
}
if (!lstOfAccount.isEmpty())
update lstOfAccount;
}
}