-
ChatterFeed
-
0Best Answers
-
0Likes Received
-
0Likes Given
-
13Questions
-
3Replies
opportunity Line item have 2 fields one is quantity and another is discount .but my question is can we autopopulate discount field based on quatity
suppose quantity is more than 10
discount wil be 20%
quantity is more than 20
discount will be 30%
discount wil be 20%
quantity is more than 20
discount will be 30%
- DIVAKAR BABU 15
- December 02, 2020
- Like
- 0
- Continue reading or reply
i need test class for this trigger
trigger Sumoftotalamount on Opportunity (after insert,after update) {
set<id>accid = new set<id>();
List<opportunity> oppList = new List<opportunity>();
for(Opportunity op:Trigger.new){
accid.add(op.Accountid);
}
list<Account> acc =[select Id,name,Rollup_Amount_Y__c,Rollup_Amount_X__c,Rollup_Amount__c from Account where Id=:accid];
Map<id,Account> accmap = new Map<id,Account>();
for(Account ac: acc){
accmap.put(ac.Id,ac);
}
if(trigger.isinsert){
for(Opportunity op :Trigger.new){
if(accmap.containskey(op.Accountid)){
Decimal sum=0;
Account a = accmap.get(op.Accountid);
if(op.type__c== 'positive'){
if(op.Amount_X__c!=null){
If(a.Rollup_Amount_X__c==null){
a.Rollup_Amount_X__c=op.Amount_X__c;
accmap.put(op.Accountid,a );
}
else {
a.Rollup_Amount_X__c=a.Rollup_Amount_X__c + op.Amount_X__c;
accmap.put(op.Accountid,a );
}
}
}
if(op.type__c== 'negative'){
if(op.Amount_Y__c!=null){
If(a.Rollup_Amount_Y__c==null){
a.Rollup_Amount_Y__c=op.Amount_Y__c;
accmap.put(op.Accountid,a );
}
else {
a.Rollup_Amount_Y__c=a.Rollup_Amount_Y__c + op.Amount_Y__c;
accmap.put(op.Accountid,a );
}
}
}
if(a.Rollup_Amount__c==null) {
a.Rollup_Amount__c=a.Rollup_Amount_Y__c+a.Rollup_Amount_X__c;
accmap.put(op.Accountid,a );
}
else{
a.Rollup_Amount__c=a.Rollup_Amount__c+(a.Rollup_Amount_X__c+a.Rollup_Amount_Y__c);
accmap.put(op.Accountid,a );
}
}
}
update accmap.values();
}
if(trigger.isupdate){
for(Opportunity op:Trigger.new){
if(op.AccountId!=trigger.oldmap.get(op.Id).Accountid){
if(op.type__c==trigger.oldmap.get(op.Id).type__c && op.type__c== 'positive'){
//new opportunity 'account id' is not equal to old oppertunity Account id {change Account id}//
if(accmap.containskey(op.Accountid)){
Account a = accmap.get(op.Accountid);
if(a.Rollup_Amount_X__c==null){
a.Rollup_Amount_X__c=op.Amount_X__c;
}
else{
a.Rollup_Amount_X__c = a.Rollup_Amount_X__c+op.Amount_X__c;
accmap.put(op.Accountid,a );
}
if(accmap.containskey(trigger.oldmap.get(op.Id).Accountid)){
Account a1 = accmap.get(trigger.oldmap.get(op.Id).Accountid);
a1.Rollup_Amount_X__c = a1.Rollup_Amount_X__c - op.Amount_X__c;
accmap.put(trigger.oldmap.get(op.Id).Accountid,a1 );
}
}
}
else if(op.type__c!=trigger.oldmap.get(op.Id).type__c && op.type__c== 'positive'){//it changed from negative to positive & account is also changed
if(accmap.containskey(op.Accountid)){
Account a = accmap.get(op.Accountid);
if(a.Rollup_Amount_X__c==null){
a.Rollup_Amount_X__c=op.Amount_X__c;
accmap.put(op.Accountid,a );
}
else
{
a.Rollup_Amount_X__c= a.Rollup_Amount_X__c + op.Amount_X__c;
accmap.put(op.Accountid,a );
}
if(a.Rollup_Amount__c!=null||op.Amount_Y__c==null||op.Amount_X__c==null){
a.Rollup_Amount__c=a.Rollup_Amount__c+(op.Amount_X__c+op.Amount_Y__c);
accmap.put(op.Accountid,a );
}
else{
a.Rollup_Amount__c= (a.Rollup_Amount_X__c+a.Rollup_Amount_Y__c);
accmap.put(op.Accountid,a );
}
if(accmap.containskey(trigger.oldmap.get(op.Id).Accountid)){
Account a1 = accmap.get(trigger.oldmap.get(op.Id).Accountid);
If(a1.Rollup_Amount_Y__c!=null){
a1.Rollup_Amount_Y__c=a1.Rollup_Amount_Y__c-op.Amount_Y__c;
accmap.put(op.Accountid,a1 );
}
a1.Rollup_Amount__c = a1.Rollup_Amount__c - (trigger.oldmap.get(op.Id).Amount_Y__c+trigger.oldmap.get(op.Id).Amount_X__c);
accmap.put(op.Accountid,a1 );
}
}
}
if(op.type__c==trigger.oldmap.get(op.Id).type__c && op.type__c== 'negative'){
if(accmap.containskey(op.Accountid)){
Account a = accmap.get(op.Accountid);
if(a.Rollup_Amount_Y__c==null){
a.Rollup_Amount_Y__c=op.Amount_Y__c;
}
else{
a.Rollup_Amount_Y__c = a.Rollup_Amount_Y__c+op.Amount_Y__c;
accmap.put(op.Accountid,a );
}
}
if(accmap.containskey(trigger.oldmap.get(op.Id).Accountid)){
Account a1 = accmap.get(trigger.oldmap.get(op.Id).Accountid);
a1.Rollup_Amount_Y__c = a1.Rollup_Amount_Y__c -op.Amount_Y__c;
accmap.put(op.Accountid,a1);
}
}
else if(op.type__c!=trigger.oldmap.get(op.Id).type__c && op.type__c== 'negative'){//changed from positive to negative
if(accmap.containskey(op.Accountid)){
Account a = accmap.get(op.Accountid);
if(a.Rollup_Amount_Y__c==null){
a.Rollup_Amount_Y__c=op.Amount_Y__c;
accmap.put(op.Accountid,a );
}
else
{
a.Rollup_Amount_Y__c= a.Rollup_Amount_Y__c + op.Amount_Y__c;
accmap.put(op.Accountid,a );
}
if(a.Rollup_Amount__c!=null){
a.Rollup_Amount__c=a.Rollup_Amount__c+(a.Rollup_Amount_X__c+a.Rollup_Amount_Y__c);
accmap.put(op.Accountid,a);
}
else{
a.Rollup_Amount__c= (a.Rollup_Amount_X__c+a.Rollup_Amount_Y__c);
accmap.put(op.Accountid,a);
}
if(accmap.containskey(trigger.oldmap.get(op.Id).Accountid)){
Account a1 = accmap.get(trigger.oldmap.get(op.Id).Accountid);
If(a1.Rollup_Amount_X__c!=null){
a1.Rollup_Amount_X__c= a1.Rollup_Amount_X__c-op.Amount_X__c;
accmap.put(op.Accountid,a1 );
}
a1.Rollup_Amount__c = a1.Rollup_Amount__c - (trigger.oldmap.get(op.Id).Amount_X__c+trigger.oldmap.get(op.Id).Amount_Y__c);
accmap.put(op.Accountid,a1 );
}
}
}
}
else if(op.AccountId==trigger.oldmap.get(op.Id).Accountid){ //same account but change type
Account a = accmap.get(op.Accountid);
if(op.type__c!=trigger.oldmap.get(op.Id).type__c && op.type__c== 'positive'){
if(a.Rollup_Amount_X__c==null){
a.Rollup_Amount_X__c= op.Amount_X__c;
accmap.put(op.Accountid,a);
}else{
Decimal sum = op.Amount_X__c - trigger.oldmap.get(op.Id).Amount_X__c;
a.Rollup_Amount_X__c=a.Rollup_Amount_X__c+sum;
accmap.put(op.Accountid,a);
}
}
else if(op.type__c!=trigger.oldmap.get(op.Id).type__c && op.type__c== 'negative'){
if(a.Rollup_Amount_Y__c==null ){
a.Rollup_Amount_Y__c= op.Amount_Y__c;
accmap.put(op.Accountid,a);
}
else{
Decimal sum = op.Amount_Y__c - trigger.oldmap.get(op.Id).Amount_Y__c;
a.Rollup_Amount_Y__c=a.Rollup_Amount_Y__c+a.Rollup_Amount_Y__c+sum;
accmap.put(op.Accountid,a);
}
}
else if(op.type__c==trigger.oldmap.get(op.Id).type__c && op.type__c== 'positive'){
if(op.Amount_X__c!=trigger.oldmap.get(op.Id).Amount_X__c){
if(a.Rollup_Amount_X__c==null && op.Amount_X__c!=null){
a.Rollup_Amount_X__c=op.Amount_X__c;
accmap.put(op.Accountid,a);
}
else{
if(a.Rollup_Amount_X__c!=null && op.Amount_X__c!=null){
a.Rollup_Amount_X__c=a.Rollup_Amount_X__c-trigger.oldmap.get(op.Id).Amount_X__c;
a.Rollup_Amount_X__c=a.Rollup_Amount_X__c+op.Amount_X__c;
accmap.put(op.Accountid,a);
}
}
}
}
else if(op.type__c==trigger.oldmap.get(op.Id).type__c && op.type__c== 'negative'){
if(op.Amount_Y__c!=trigger.oldmap.get(op.Id).Amount_Y__c){
if(a.Rollup_Amount_Y__c==null && op.Amount_Y__c!=null){
a.Rollup_Amount_Y__c=op.Amount_Y__c;
accmap.put(op.Accountid,a);
}
else{
if(a.Rollup_Amount_Y__c!=null && op.Amount_Y__c!=null){
a.Rollup_Amount_Y__c=a.Rollup_Amount_Y__c-trigger.oldmap.get(op.Id).Amount_Y__c;
a.Rollup_Amount_Y__c=a.Rollup_Amount_Y__c+op.Amount_Y__c;
accmap.put(op.Accountid,a);
}
}
}
}
}
update accmap.values();
}
}
}
set<id>accid = new set<id>();
List<opportunity> oppList = new List<opportunity>();
for(Opportunity op:Trigger.new){
accid.add(op.Accountid);
}
list<Account> acc =[select Id,name,Rollup_Amount_Y__c,Rollup_Amount_X__c,Rollup_Amount__c from Account where Id=:accid];
Map<id,Account> accmap = new Map<id,Account>();
for(Account ac: acc){
accmap.put(ac.Id,ac);
}
if(trigger.isinsert){
for(Opportunity op :Trigger.new){
if(accmap.containskey(op.Accountid)){
Decimal sum=0;
Account a = accmap.get(op.Accountid);
if(op.type__c== 'positive'){
if(op.Amount_X__c!=null){
If(a.Rollup_Amount_X__c==null){
a.Rollup_Amount_X__c=op.Amount_X__c;
accmap.put(op.Accountid,a );
}
else {
a.Rollup_Amount_X__c=a.Rollup_Amount_X__c + op.Amount_X__c;
accmap.put(op.Accountid,a );
}
}
}
if(op.type__c== 'negative'){
if(op.Amount_Y__c!=null){
If(a.Rollup_Amount_Y__c==null){
a.Rollup_Amount_Y__c=op.Amount_Y__c;
accmap.put(op.Accountid,a );
}
else {
a.Rollup_Amount_Y__c=a.Rollup_Amount_Y__c + op.Amount_Y__c;
accmap.put(op.Accountid,a );
}
}
}
if(a.Rollup_Amount__c==null) {
a.Rollup_Amount__c=a.Rollup_Amount_Y__c+a.Rollup_Amount_X__c;
accmap.put(op.Accountid,a );
}
else{
a.Rollup_Amount__c=a.Rollup_Amount__c+(a.Rollup_Amount_X__c+a.Rollup_Amount_Y__c);
accmap.put(op.Accountid,a );
}
}
}
update accmap.values();
}
if(trigger.isupdate){
for(Opportunity op:Trigger.new){
if(op.AccountId!=trigger.oldmap.get(op.Id).Accountid){
if(op.type__c==trigger.oldmap.get(op.Id).type__c && op.type__c== 'positive'){
//new opportunity 'account id' is not equal to old oppertunity Account id {change Account id}//
if(accmap.containskey(op.Accountid)){
Account a = accmap.get(op.Accountid);
if(a.Rollup_Amount_X__c==null){
a.Rollup_Amount_X__c=op.Amount_X__c;
}
else{
a.Rollup_Amount_X__c = a.Rollup_Amount_X__c+op.Amount_X__c;
accmap.put(op.Accountid,a );
}
if(accmap.containskey(trigger.oldmap.get(op.Id).Accountid)){
Account a1 = accmap.get(trigger.oldmap.get(op.Id).Accountid);
a1.Rollup_Amount_X__c = a1.Rollup_Amount_X__c - op.Amount_X__c;
accmap.put(trigger.oldmap.get(op.Id).Accountid,a1 );
}
}
}
else if(op.type__c!=trigger.oldmap.get(op.Id).type__c && op.type__c== 'positive'){//it changed from negative to positive & account is also changed
if(accmap.containskey(op.Accountid)){
Account a = accmap.get(op.Accountid);
if(a.Rollup_Amount_X__c==null){
a.Rollup_Amount_X__c=op.Amount_X__c;
accmap.put(op.Accountid,a );
}
else
{
a.Rollup_Amount_X__c= a.Rollup_Amount_X__c + op.Amount_X__c;
accmap.put(op.Accountid,a );
}
if(a.Rollup_Amount__c!=null||op.Amount_Y__c==null||op.Amount_X__c==null){
a.Rollup_Amount__c=a.Rollup_Amount__c+(op.Amount_X__c+op.Amount_Y__c);
accmap.put(op.Accountid,a );
}
else{
a.Rollup_Amount__c= (a.Rollup_Amount_X__c+a.Rollup_Amount_Y__c);
accmap.put(op.Accountid,a );
}
if(accmap.containskey(trigger.oldmap.get(op.Id).Accountid)){
Account a1 = accmap.get(trigger.oldmap.get(op.Id).Accountid);
If(a1.Rollup_Amount_Y__c!=null){
a1.Rollup_Amount_Y__c=a1.Rollup_Amount_Y__c-op.Amount_Y__c;
accmap.put(op.Accountid,a1 );
}
a1.Rollup_Amount__c = a1.Rollup_Amount__c - (trigger.oldmap.get(op.Id).Amount_Y__c+trigger.oldmap.get(op.Id).Amount_X__c);
accmap.put(op.Accountid,a1 );
}
}
}
if(op.type__c==trigger.oldmap.get(op.Id).type__c && op.type__c== 'negative'){
if(accmap.containskey(op.Accountid)){
Account a = accmap.get(op.Accountid);
if(a.Rollup_Amount_Y__c==null){
a.Rollup_Amount_Y__c=op.Amount_Y__c;
}
else{
a.Rollup_Amount_Y__c = a.Rollup_Amount_Y__c+op.Amount_Y__c;
accmap.put(op.Accountid,a );
}
}
if(accmap.containskey(trigger.oldmap.get(op.Id).Accountid)){
Account a1 = accmap.get(trigger.oldmap.get(op.Id).Accountid);
a1.Rollup_Amount_Y__c = a1.Rollup_Amount_Y__c -op.Amount_Y__c;
accmap.put(op.Accountid,a1);
}
}
else if(op.type__c!=trigger.oldmap.get(op.Id).type__c && op.type__c== 'negative'){//changed from positive to negative
if(accmap.containskey(op.Accountid)){
Account a = accmap.get(op.Accountid);
if(a.Rollup_Amount_Y__c==null){
a.Rollup_Amount_Y__c=op.Amount_Y__c;
accmap.put(op.Accountid,a );
}
else
{
a.Rollup_Amount_Y__c= a.Rollup_Amount_Y__c + op.Amount_Y__c;
accmap.put(op.Accountid,a );
}
if(a.Rollup_Amount__c!=null){
a.Rollup_Amount__c=a.Rollup_Amount__c+(a.Rollup_Amount_X__c+a.Rollup_Amount_Y__c);
accmap.put(op.Accountid,a);
}
else{
a.Rollup_Amount__c= (a.Rollup_Amount_X__c+a.Rollup_Amount_Y__c);
accmap.put(op.Accountid,a);
}
if(accmap.containskey(trigger.oldmap.get(op.Id).Accountid)){
Account a1 = accmap.get(trigger.oldmap.get(op.Id).Accountid);
If(a1.Rollup_Amount_X__c!=null){
a1.Rollup_Amount_X__c= a1.Rollup_Amount_X__c-op.Amount_X__c;
accmap.put(op.Accountid,a1 );
}
a1.Rollup_Amount__c = a1.Rollup_Amount__c - (trigger.oldmap.get(op.Id).Amount_X__c+trigger.oldmap.get(op.Id).Amount_Y__c);
accmap.put(op.Accountid,a1 );
}
}
}
}
else if(op.AccountId==trigger.oldmap.get(op.Id).Accountid){ //same account but change type
Account a = accmap.get(op.Accountid);
if(op.type__c!=trigger.oldmap.get(op.Id).type__c && op.type__c== 'positive'){
if(a.Rollup_Amount_X__c==null){
a.Rollup_Amount_X__c= op.Amount_X__c;
accmap.put(op.Accountid,a);
}else{
Decimal sum = op.Amount_X__c - trigger.oldmap.get(op.Id).Amount_X__c;
a.Rollup_Amount_X__c=a.Rollup_Amount_X__c+sum;
accmap.put(op.Accountid,a);
}
}
else if(op.type__c!=trigger.oldmap.get(op.Id).type__c && op.type__c== 'negative'){
if(a.Rollup_Amount_Y__c==null ){
a.Rollup_Amount_Y__c= op.Amount_Y__c;
accmap.put(op.Accountid,a);
}
else{
Decimal sum = op.Amount_Y__c - trigger.oldmap.get(op.Id).Amount_Y__c;
a.Rollup_Amount_Y__c=a.Rollup_Amount_Y__c+a.Rollup_Amount_Y__c+sum;
accmap.put(op.Accountid,a);
}
}
else if(op.type__c==trigger.oldmap.get(op.Id).type__c && op.type__c== 'positive'){
if(op.Amount_X__c!=trigger.oldmap.get(op.Id).Amount_X__c){
if(a.Rollup_Amount_X__c==null && op.Amount_X__c!=null){
a.Rollup_Amount_X__c=op.Amount_X__c;
accmap.put(op.Accountid,a);
}
else{
if(a.Rollup_Amount_X__c!=null && op.Amount_X__c!=null){
a.Rollup_Amount_X__c=a.Rollup_Amount_X__c-trigger.oldmap.get(op.Id).Amount_X__c;
a.Rollup_Amount_X__c=a.Rollup_Amount_X__c+op.Amount_X__c;
accmap.put(op.Accountid,a);
}
}
}
}
else if(op.type__c==trigger.oldmap.get(op.Id).type__c && op.type__c== 'negative'){
if(op.Amount_Y__c!=trigger.oldmap.get(op.Id).Amount_Y__c){
if(a.Rollup_Amount_Y__c==null && op.Amount_Y__c!=null){
a.Rollup_Amount_Y__c=op.Amount_Y__c;
accmap.put(op.Accountid,a);
}
else{
if(a.Rollup_Amount_Y__c!=null && op.Amount_Y__c!=null){
a.Rollup_Amount_Y__c=a.Rollup_Amount_Y__c-trigger.oldmap.get(op.Id).Amount_Y__c;
a.Rollup_Amount_Y__c=a.Rollup_Amount_Y__c+op.Amount_Y__c;
accmap.put(op.Accountid,a);
}
}
}
}
}
update accmap.values();
}
}
}
- DIVAKAR BABU 15
- January 22, 2019
- Like
- 0
- Continue reading or reply
WRITE LOGIC
SUM OF 1) Make two number fields on Opportunity object
Amount_X
Amount_Y
2) Make one picklist field "Type" , values ('Positive', 'Negative')
3) Make two number fields on account
Rollup_Amount_X
Rollup_Amount_Y
Rollup_Amount
4) Make one trigger on Opportunity object, which will do following:
--> Sum all child of Opportunity's field "Amount_X" and store in parent account's "Rollup_Amount_X" Where Type is "Positive"
--> Sum all child of Opportunity's field "Amount_Y" and store in parent account's "Rollup_Amount_Y" Where Type is "Negative"
--> Sum all child of Opportunity's field "Amount_X" + "Amount_Y" and store in parent account's "Rollup_Amount"
5) Make trigg
Amount_X
Amount_Y
2) Make one picklist field "Type" , values ('Positive', 'Negative')
3) Make two number fields on account
Rollup_Amount_X
Rollup_Amount_Y
Rollup_Amount
4) Make one trigger on Opportunity object, which will do following:
--> Sum all child of Opportunity's field "Amount_X" and store in parent account's "Rollup_Amount_X" Where Type is "Positive"
--> Sum all child of Opportunity's field "Amount_Y" and store in parent account's "Rollup_Amount_Y" Where Type is "Negative"
--> Sum all child of Opportunity's field "Amount_X" + "Amount_Y" and store in parent account's "Rollup_Amount"
5) Make trigg
- DIVAKAR BABU 15
- January 11, 2019
- Like
- 0
- Continue reading or reply
trigger on oppertunity
1) Make two number fields on Opportunity object
Amount_X
Amount_Y
2) Make one picklist field "Type" , values ('Positive', 'Negative')
3) Make two number fields on account
Rollup_Amount_X
Rollup_Amount_Y
Rollup_Amount
4) Make one trigger on Opportunity object, which will do following:
--> Sum all child of Opportunity's field "Amount_X" and store in parent account's "Rollup_Amount_X" Where Type is "Positive"
--> Sum all child of Opportunity's field "Amount_Y" and store in parent account's "Rollup_Amount_Y" Where Type is "Negative"
--> Sum all child of Opportunity's field "Amount_X" + "Amount_Y" and store in parent account's "Rollup_Amount"
5) Make trigger as bulk / Test class
Amount_X
Amount_Y
2) Make one picklist field "Type" , values ('Positive', 'Negative')
3) Make two number fields on account
Rollup_Amount_X
Rollup_Amount_Y
Rollup_Amount
4) Make one trigger on Opportunity object, which will do following:
--> Sum all child of Opportunity's field "Amount_X" and store in parent account's "Rollup_Amount_X" Where Type is "Positive"
--> Sum all child of Opportunity's field "Amount_Y" and store in parent account's "Rollup_Amount_Y" Where Type is "Negative"
--> Sum all child of Opportunity's field "Amount_X" + "Amount_Y" and store in parent account's "Rollup_Amount"
5) Make trigger as bulk / Test class
- DIVAKAR BABU 15
- January 04, 2019
- Like
- 0
- Continue reading or reply
i have 3 triggers after insert ,after update ,after delete but i have to write in only one trigger how
after insert
trigger rollup summary on Contact (after insert) {
set<id>accid = new set<id>();
for(Contact c:Trigger.new){
accid.add(c.Accountid);
}
list<Account> acc =[select Id,name from Account where Id=:accid];
Map<id,Account> accmap = new Map<id,Account>();
for(Account ac: acc){
accmap.put(ac.Id,ac);
}
for( contact c:Trigger.new){
if(accmap.containskey(c.Accountid)){
Account a = accmap.get(c.Accountid);
a.Number_of_Contacts__c = a.Number_of_Contacts__c +1 ;
accmap.put(c.Accountid,a);
}
}
update accmap.values();
}
after delete
trigger rollup summary on Contact (after delete) {
set<id>accid = new set<id>();
for(Contact c:Trigger.old){
accid.add(c.Accountid);
}
list<Account> acc =[select Id,name from Account where Id=:accid];
Map<id,Account> accmap = new Map<id,Account>();
for(Account ac: acc){
accmap.put(ac.Id,ac);
}
for( contact c:Trigger.old){
if(accmap.containskey(c.Accountid)){
Account a = accmap.get(c.Accountid);
a.Number_of_Contacts__c = a.Number_of_Contacts__c +1 ;
accmap.put(c.Accountid,a);
}
}
update accmap.values();
}
After update
trigger afterupdate on Contact (after update) {
set<id>accid = new set<id>();
for(Contact c:Trigger.new){
accid.add(c.Accountid);
}
list<Account> acc =[select Id,name from Account where Id=:accid];
Map<id,Account> accmap = new Map<id,Account>();
for(Account ac: acc){
accmap.put(ac.Id,ac);
}
for( contact c:Trigger.new){
if(c.AccountId!=trigger.oldmap.get(c.Id).Accountid){
if(accmap.containskey(c.Accountid)){
Account a = accmap.get(c.Accountid);
a.Number_of_Contacts__c = a.Number_of_Contacts__c +1 ;
accmap.put(c.Accountid,a);
}
if(accmap.containskey(trigger.oldmap.get(c.Id).Accountid)){
Account a = accmap.get(trigger.oldmap.get(c.Id).Accountid);
a.Number_of_Contacts__c = a.Number_of_Contacts__c -1 ;
accmap.put(c.Accountid,a);
}
}
}
update accmap.values();
}
trigger rollup summary on Contact (after insert) {
set<id>accid = new set<id>();
for(Contact c:Trigger.new){
accid.add(c.Accountid);
}
list<Account> acc =[select Id,name from Account where Id=:accid];
Map<id,Account> accmap = new Map<id,Account>();
for(Account ac: acc){
accmap.put(ac.Id,ac);
}
for( contact c:Trigger.new){
if(accmap.containskey(c.Accountid)){
Account a = accmap.get(c.Accountid);
a.Number_of_Contacts__c = a.Number_of_Contacts__c +1 ;
accmap.put(c.Accountid,a);
}
}
update accmap.values();
}
after delete
trigger rollup summary on Contact (after delete) {
set<id>accid = new set<id>();
for(Contact c:Trigger.old){
accid.add(c.Accountid);
}
list<Account> acc =[select Id,name from Account where Id=:accid];
Map<id,Account> accmap = new Map<id,Account>();
for(Account ac: acc){
accmap.put(ac.Id,ac);
}
for( contact c:Trigger.old){
if(accmap.containskey(c.Accountid)){
Account a = accmap.get(c.Accountid);
a.Number_of_Contacts__c = a.Number_of_Contacts__c +1 ;
accmap.put(c.Accountid,a);
}
}
update accmap.values();
}
After update
trigger afterupdate on Contact (after update) {
set<id>accid = new set<id>();
for(Contact c:Trigger.new){
accid.add(c.Accountid);
}
list<Account> acc =[select Id,name from Account where Id=:accid];
Map<id,Account> accmap = new Map<id,Account>();
for(Account ac: acc){
accmap.put(ac.Id,ac);
}
for( contact c:Trigger.new){
if(c.AccountId!=trigger.oldmap.get(c.Id).Accountid){
if(accmap.containskey(c.Accountid)){
Account a = accmap.get(c.Accountid);
a.Number_of_Contacts__c = a.Number_of_Contacts__c +1 ;
accmap.put(c.Accountid,a);
}
if(accmap.containskey(trigger.oldmap.get(c.Id).Accountid)){
Account a = accmap.get(trigger.oldmap.get(c.Id).Accountid);
a.Number_of_Contacts__c = a.Number_of_Contacts__c -1 ;
accmap.put(c.Accountid,a);
}
}
}
update accmap.values();
}
- DIVAKAR BABU 15
- January 01, 2019
- Like
- 0
- Continue reading or reply
write a test class for this below trigger
/**
trigger fired on:- before delete
purpose :- restrict users not to delete Casecomments except System admin profile Users
**/
trigger restrictUsersFromDel on Case_Comment__c (before delete) {
if(trigger.isBefore && trigger.isdelete){
Profile SystemAdminId=[select id from Profile where Name='System Administrator' limit 1];
if(UserInfo.getProfileId() != SystemAdminId.Id){
for(Case_Comment__c oldcase:Trigger.old){
oldcase.adderror('You are not authorized to delete the record , please contact your system administrator');
}
}
}
trigger fired on:- before delete
purpose :- restrict users not to delete Casecomments except System admin profile Users
**/
trigger restrictUsersFromDel on Case_Comment__c (before delete) {
if(trigger.isBefore && trigger.isdelete){
Profile SystemAdminId=[select id from Profile where Name='System Administrator' limit 1];
if(UserInfo.getProfileId() != SystemAdminId.Id){
for(Case_Comment__c oldcase:Trigger.old){
oldcase.adderror('You are not authorized to delete the record , please contact your system administrator');
}
}
}
- DIVAKAR BABU 15
- December 26, 2018
- Like
- 0
- Continue reading or reply
i am getting error variable doesnt exist .variable doesnt exist Contact_Area__c, contact_country__c
parent object: account
fields : contact country - Picklist values: India, Africa, America
child object : contact
field : Contact Area - Picklist values: Karataka, Andhra Pradesh, Kerala, South Africa, Nigeria, Kenya, California, San Fransisco, Texas
when contact is inserted / updated, based the contact's Contact Area field the parents contact Country should change with respected country. wirte a trigger for insert, Update. create required fields.
trigger ConnectA on Contact (after insert,after update) {
Map<Id,Contact> AccID = New Map<Id,Contact>();
Map<Id,Contact> oldCOn = trigger.oldMap ;
for(Contact con : Trigger.new){
if( (con.contact_country__c!=oldCOn.get(con.Id).contact_country__c) ||
(con.Contact_Area__c!=oldCOn.get(con.Id).Contact_Area__c) ){
AccID.add(con.AccountId);
}
}
List<Account> accList = [SELECT Name, BillingStreet FROM Account WHERE id in :AccID.keySet()];
for(Account a :accList){
Contact c = AccID.get(a.Id) ;
a.Contact_Area__c = c.Contact_Area__c ;
a.contact_country__c = c.contact_country__c ;
}
update accList;
}
fields : contact country - Picklist values: India, Africa, America
child object : contact
field : Contact Area - Picklist values: Karataka, Andhra Pradesh, Kerala, South Africa, Nigeria, Kenya, California, San Fransisco, Texas
when contact is inserted / updated, based the contact's Contact Area field the parents contact Country should change with respected country. wirte a trigger for insert, Update. create required fields.
trigger ConnectA on Contact (after insert,after update) {
Map<Id,Contact> AccID = New Map<Id,Contact>();
Map<Id,Contact> oldCOn = trigger.oldMap ;
for(Contact con : Trigger.new){
if( (con.contact_country__c!=oldCOn.get(con.Id).contact_country__c) ||
(con.Contact_Area__c!=oldCOn.get(con.Id).Contact_Area__c) ){
AccID.add(con.AccountId);
}
}
List<Account> accList = [SELECT Name, BillingStreet FROM Account WHERE id in :AccID.keySet()];
for(Account a :accList){
Contact c = AccID.get(a.Id) ;
a.Contact_Area__c = c.Contact_Area__c ;
a.contact_country__c = c.contact_country__c ;
}
update accList;
}
- DIVAKAR BABU 15
- December 16, 2018
- Like
- 0
- Continue reading or reply
why i am getting error
public class Abdevil {
public integer bvalue{get;set;}
public integer avalue{get;set;}
public integer result{get;set;}
public string operation{get;set;}
public pagereference subb()
{
result = avalue-bvalue;
operation = 'SUBTRACTION';
return null;
}
public pagereference subb()
{
result= avalue+bvalue;
operation= 'ADDITION';
return null;
}
}
method already decleared ? line 12
public integer bvalue{get;set;}
public integer avalue{get;set;}
public integer result{get;set;}
public string operation{get;set;}
public pagereference subb()
{
result = avalue-bvalue;
operation = 'SUBTRACTION';
return null;
}
public pagereference subb()
{
result= avalue+bvalue;
operation= 'ADDITION';
return null;
}
}
method already decleared ? line 12
- DIVAKAR BABU 15
- February 10, 2018
- Like
- 0
- Continue reading or reply
- DIVAKAR BABU 15
- January 30, 2018
- Like
- 0
- Continue reading or reply
opportunity Line item have 2 fields one is quantity and another is discount .but my question is can we autopopulate discount field based on quatity
suppose quantity is more than 10
discount wil be 20%
quantity is more than 20
discount will be 30%
discount wil be 20%
quantity is more than 20
discount will be 30%
- DIVAKAR BABU 15
- December 02, 2020
- Like
- 0
- Continue reading or reply
trigger on oppertunity
1) Make two number fields on Opportunity object
Amount_X
Amount_Y
2) Make one picklist field "Type" , values ('Positive', 'Negative')
3) Make two number fields on account
Rollup_Amount_X
Rollup_Amount_Y
Rollup_Amount
4) Make one trigger on Opportunity object, which will do following:
--> Sum all child of Opportunity's field "Amount_X" and store in parent account's "Rollup_Amount_X" Where Type is "Positive"
--> Sum all child of Opportunity's field "Amount_Y" and store in parent account's "Rollup_Amount_Y" Where Type is "Negative"
--> Sum all child of Opportunity's field "Amount_X" + "Amount_Y" and store in parent account's "Rollup_Amount"
5) Make trigger as bulk / Test class
Amount_X
Amount_Y
2) Make one picklist field "Type" , values ('Positive', 'Negative')
3) Make two number fields on account
Rollup_Amount_X
Rollup_Amount_Y
Rollup_Amount
4) Make one trigger on Opportunity object, which will do following:
--> Sum all child of Opportunity's field "Amount_X" and store in parent account's "Rollup_Amount_X" Where Type is "Positive"
--> Sum all child of Opportunity's field "Amount_Y" and store in parent account's "Rollup_Amount_Y" Where Type is "Negative"
--> Sum all child of Opportunity's field "Amount_X" + "Amount_Y" and store in parent account's "Rollup_Amount"
5) Make trigger as bulk / Test class
- DIVAKAR BABU 15
- January 04, 2019
- Like
- 0
- Continue reading or reply