You need to sign in to do that
Don't have an account?
Samir Meshram
oppo auto closed won after attaching a file
Hello evryone,
I have requirement like, in opportunity you cant not close a oppo to closed won untill you attach a file in attachment, after that there is a one field Signed__c you have to check that field, as soon as your file is attached and your Signed__c is checked, the opportunity should attomatically moved to closed won, i have written this trigger, but it is not working,
trigger AttachmentValidate on Opportunity (before update,before Insert, after insert, after update) {
public boolean noAttachment = false;
for(Opportunity o:Trigger.New)
{
//ContentDocument a = new ContentDocument();
if(o.StageName == 'Closed won')
{
try{
ContentDocumentLink CDL = [SELECT ContentDocumentId,Id,IsDeleted,LinkedEntityId FROM ContentDocumentLink where LinkedEntityId =: o.Id];
system.debug('cdl :'+CDL);
// system.debug('count :'+CDL);
}
catch(exception e)
{
noAttachment = true;
}
if (noAttachment == true){
o.addError('Add a MSA/SOW file in Notes and Attachment before you close the Opportunity as Closed Won');
system.debug('noAttachment :'+noAttachment);
}
else if(o.Signed__c == false){
o.addError('Please Check the Signed MSA/SOW attached checkbox');
system.debug('o.Signed__c :'+o.Signed__c);
}
else{
system.debug('hi');
}
}
}
}
Please help me out on this, thanks
I have requirement like, in opportunity you cant not close a oppo to closed won untill you attach a file in attachment, after that there is a one field Signed__c you have to check that field, as soon as your file is attached and your Signed__c is checked, the opportunity should attomatically moved to closed won, i have written this trigger, but it is not working,
trigger AttachmentValidate on Opportunity (before update,before Insert, after insert, after update) {
public boolean noAttachment = false;
for(Opportunity o:Trigger.New)
{
//ContentDocument a = new ContentDocument();
if(o.StageName == 'Closed won')
{
try{
ContentDocumentLink CDL = [SELECT ContentDocumentId,Id,IsDeleted,LinkedEntityId FROM ContentDocumentLink where LinkedEntityId =: o.Id];
system.debug('cdl :'+CDL);
// system.debug('count :'+CDL);
}
catch(exception e)
{
noAttachment = true;
}
if (noAttachment == true){
o.addError('Add a MSA/SOW file in Notes and Attachment before you close the Opportunity as Closed Won');
system.debug('noAttachment :'+noAttachment);
}
else if(o.Signed__c == false){
o.addError('Please Check the Signed MSA/SOW attached checkbox');
system.debug('o.Signed__c :'+o.Signed__c);
}
else{
system.debug('hi');
}
}
}
}
Please help me out on this, thanks
Do you have any trigger to update the Signed Checkbox as true when you are uploading the file if yes in the same trigger you can add the stage update also like below code.
Otherwise check is there any automation existing for Stage Update. If there is no update logic for stage update simpy you can create Workflow based on the Signed Checkbox field. Sample workflow is below link.
https://trailblazers.salesforce.com/answers?id=9063A000000iXq6QAE
Thanks,
Maharajan.C
All Answers
Please try the below code:
Thanks,
Maharajan.C
Thank you for the response, unfortunatelly it is not working.
Do you have any trigger to update the Signed Checkbox as true when you are uploading the file if yes in the same trigger you can add the stage update also like below code.
Otherwise check is there any automation existing for Stage Update. If there is no update logic for stage update simpy you can create Workflow based on the Signed Checkbox field. Sample workflow is below link.
https://trailblazers.salesforce.com/answers?id=9063A000000iXq6QAE
Thanks,
Maharajan.C