You need to sign in to do that
Don't have an account?
sfdc dev 2264
DATE OVERLAPPING TRIGGER HELP NEEDED
Hi,
I need help on the following requirement below as follows,
1) I have a account object where contract is another object related to account
2) Contract object is having contract start date and end date which populates to account
My scenario is
3)If there are 2 active contract associcated to account and the dates contain
1st Active contracts dates are
start date :1.feb 2017
end date : 31st march 2017
2nd active contract dates are
start date : 1st march 2017
end date : 17th sep 2017
then in this scenatio the first active contract end date should be automatically backdated to the previous month below as follows to avoid overlapping between 2 contracts
1st active contract end date should automatically be changed to
end date :28th feb 2017
start date should remain the same as 1 feb 2017.
basically both contracts end dates and start dates shouldnt fall in same range to avoid overlapping
I tried the below apex class
I am gettingthe below error
Error: Compile Error: unexpected token: '}' at line 18 column 17
12 =>31, };
Help me pls
I need help on the following requirement below as follows,
1) I have a account object where contract is another object related to account
2) Contract object is having contract start date and end date which populates to account
My scenario is
3)If there are 2 active contract associcated to account and the dates contain
1st Active contracts dates are
start date :1.feb 2017
end date : 31st march 2017
2nd active contract dates are
start date : 1st march 2017
end date : 17th sep 2017
then in this scenatio the first active contract end date should be automatically backdated to the previous month below as follows to avoid overlapping between 2 contracts
1st active contract end date should automatically be changed to
end date :28th feb 2017
start date should remain the same as 1 feb 2017.
basically both contracts end dates and start dates shouldnt fall in same range to avoid overlapping
I tried the below apex class
public class overlapDateHandler{ public void overlapDateMethod(list<Contract__c> contractList){ set<Id> accountIdSet = new set<Id>(); list<Account> accList = new List<Account>(); map<integer, integer> dateMap = new map<integer, integer>{ 1 => 31, 3 => 31, 4 =>30, 5 =>31, 6 => 30, 7 => 31, 8 => 31, 9 =>30, 10 =>31, 11 =>30, 12 =>31, }; map<id, list<Contract__c>> idVsContractmap = new map<id, list<Contract__c>>(); list<Contract__c> updateContractList = new list<Contract__c>(); for(Contract__c conObj : contractList){ if(conObj.AccountId != null){ accountIdSet.add(conObj.AccountId); } } accList = [Select Id, (Select Contract_Start_Date__c, Contract_End_Date__c, AccountId From Contract__c) From Account Where Id IN :accountIdSet] for(Account accObj : accList){ idVsContractmap.put(accObj.id, accObj.Contract__c); } for(Contract__c conObj : contractList){ if(conObj.AccountId != null){ if(idVsContractmap.containsKey(conObj.AccountId)){ for(Contract contractObj : idVsContractmap.get(conObj.AccountId)){ if(contractObj.Contract_End_Date__c.month() == conObj.startdate__c.month()){ if(contractObj.Contract_End_Date__c.month() - 1 == 2){ if(MOD( contractObj.Contract_End_Date__c.year()) + 1, 4) = 0){ string newDate = 29 +'//'+contractObj.Contract_End_Date__c.month() - 1+'//'+contractObj.Contract_End_Date__c.year(); contractObj.Contract_End_Date__c = date.parse(newDate); } else{ string newDate = 28 +'//'+contractObj.Contract_End_Date__c.month() - 1+'//'+contractObj.Contract_End_Date__c.year(); contractObj.Contract_End_Date__c = date.parse(newDate); } } else if(contractObj.Contract_End_Date__c.month() - 1 == 0){ string newDate = 31 +'//'+12+'//'+contractObj.Contract_End_Date__c.year() -1; contractObj.Contract_End_Date__c = date.parse(newDate); } else{ string newDate = 31 +'//'+dateMap.get(contractObj.Contract_End_Date__c.month() - 1)+'//'+contractObj.Contract_End_Date__c.year() -1; contractObj.Contract_End_Date__c = date.parse(newDate); } } updateContractList.add(contractObj); } } } } update updateContractList; } }
I am gettingthe below error
Error: Compile Error: unexpected token: '}' at line 18 column 17
12 =>31, };
Help me pls
thanks
All Answers
thanks
Your line number 18 syntax is wrong. Please use this syntax . extra ',' is there in your code
i changed it
but getting the below error
Error: Compile Error: Didn't understand relationship 'Contract__c' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 28 column 19
accList = [Select Id, (Select Contract_Start_Date__c, Contract_End_Date__c, Account__c,Status__c From Contract__c where Status__c='Signed by Customer') From Account Where Id IN :accountIdSet]
contracts is a custom object child of account.
You need to give relationship name.
If above qury does nit works use below thanks
Error: Compile Error: expecting a semi-colon, found 'for' at line 29 column 8
accList = [Select Id, (Select Contract_Start_Date__c, Contract_End_Date__c, Account__c,Status__c From Contracts__r where Status__c='Signed by Customer') From Account Where Id IN :accountIdSet]
for(Account accObj : accList){
idVsContractmap.put(accObj.id, accObj.Contract__c);
}
if i had semicolon in the query
accList = [Select Id, (Select Contract_Start_Date__c, Contract_End_Date__c, Account__c,Status__c From Contracts__r where Status__c='Signed by Customer') From Account Where Id IN :accountIdSet];
it gives
Error: Compile Error: expecting a right parentheses, found ',' at line 45 column 84
if(MOD( contractObj.Contract_End_Date__c.year()) + 1, 4) = 0){
Please help me
accList = [Select Id, (Select Contract_Start_Date__c, Contract_End_Date__c, Account__c,Status__c From Contracts__r where Status__c='Signed by Customer') From Account Where Id IN :accountIdSet]
for(Account accObj : accList){
idVsContractmap.put(accObj.id, accObj.Contract__c);
}
if i had semicolon in the query
accList = [Select Id, (Select Contract_Start_Date__c, Contract_End_Date__c, Account__c,Status__c From Contracts__r where Status__c='Signed by Customer') From Account Where Id IN :accountIdSet];
it gives
Error: Compile Error: expecting a right parentheses, found ',' at line 45 column 84
if(contractObj.Contract_End_Date__c.month()- 1 == 2){
if(MOD( contractObj.Contract_End_Date__c.year()) + 1, 4) = 0){
Please help me
if(contractObj.Contract_End_Date__c.month()- 1 == 2){
if(MOD(contractObj.Contract_End_Date__c.year()+ 1, 4)) = 0){
getting the below error now
Error: Compile Error: unexpected token: '=' at line 44 column 79
if(contractObj.Contract_End_Date__c.month()- 1 == 2){
I removed it already
getting the following error now
Error: Compile Error: unexpected token: '=' at line 44 column 79
if(contractObj.Contract_End_Date__c.month()- 1 == 2){
Please help me bro
Thanks
//
if(firstcontract.Contract_Start_Date__c<contractObj.Contract_Start_Date__c && firstcontract.Contract_End_Date__c<contractObj.Contract_End_Date__c ){
if(firstcontract.Contract_End_Date__c>=contractObj.Contract_Start_Date__c){
firstcontract.Contract_End_Date__c=contractObj.Contract_Start_Date__c.addDays(-1);
update firstcontract;//put the list and update
}
}
else{
system.debug('elsesection');
if(contractObj.Contract_End_Date__c>=firstcontract.Contract_Start_Date__c){
contractObj.Contract_End_Date__c=firstcontract.Contract_Start_Date__c.addDays(-1);
update contractObj;// put the list and update
}
//
if(idVsContractmap.containsKey(controbj.Account__r.Id)) {
List<Contract__c> contrAccList = idVsContractmap.get(controbj.Account__r.Id);
contrAccList.add(controbj);
idVsContractmap.put(controbj.Account__c, contrAccList);
} else {
idVsContractmap.put(controbj.Account__c, new List<Contract__c> { controbj });
}
//
Kindly help me pls
Thanks in advance