You need to sign in to do that
Don't have an account?
anillll
Update a field
public with sharing class AttachController { //private ApexPages.StandardController controller { get; set; } public List<Deal_License__c> dp{get;set;} public List<Contact> con{get;set;} public Deal__c D{get;set;} public AttachController(ApexPages.StandardController controller) { try { D = [Select Name,Id,VersionNo__c,Account__c,Account__r.Name,Account_Executive__r.Name,License_Value__c,Account__r.BillingStreet,Account__r.BillingCity,Account__r.Billingstate,Account__r.BillingPostalcode,Account__r.BillingCountry from Deal__c where id=:controller.getRecord().id]; system.debug('TestDeal'+D); Account acc=[Select Id,BillingStreet,BillingCity,Billingstate,BillingPostalcode,BillingCountry from Account where id=:D.Account__c]; system.debug('Account%%%%%%%%%%%%%%'+acc); dp=[select id,Name,Deal__c,Months__c,List_Price__c,Unit_Price__c,Quantity__c,Total_Value__c,Ingram_Transfer_Price__c,Ingram_Special_Price__c,Ingram_Purchase_Value__c,Start_Date__c,End_Date__c from Deal_License__c where Deal__c=:D.Id]; System.debug('DEALPRDODUCT&&&&&&&&&&'+dp); con=[select Id,Name,Email,Phone,MobilePhone from Contact where id=:D.Account_Executive__c]; } catch(Exception e) { system.debug('Exception'+e); } } public void attach() { try{ Deal__c D=new Deal__c(); Attachment myAttach = new Attachment(); myAttach.ParentId = ApexPages.currentPage().getParameters().get('id'); System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id')); List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId]; Integer c=at.size()+1; system.debug('Account%%%%%%%%%%%%%%'+c); myAttach.name =''+''+ c +''; PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id')); myAttach.body = psPdf.getContentAsPdf(); insert myAttach; D.VersionNo__c=myAttach.name; update D; System.debug('After attach'); System.debug(myAttach); /* ApexPages.addMessage(new ApexPages.Message (ApexPages.Severity.CONFIRM,'Quotation has been attached.')); */ } catch(Exception e) { ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,'There was an error while attaching')); System.debug('Exception'); } } public PageReference QA() { PageReference secondPage = new PageReference('/apex/EmailQuote?id=' + ApexPages.currentPage().getParameters().get('id')); Attachment myAttach = new Attachment(); myAttach.ParentId = ApexPages.currentPage().getParameters().get('id'); System.debug('Id: ' + ApexPages.currentPage().getParameters().get('id')); List<Attachment> at=[Select id from Attachment where parentId=:myAttach.ParentId]; Integer c=at.size()+1; myAttach.name = ''+''+ c +''; PageReference psPdf = new PageReference('/apex/Quotation?id=' + ApexPages.currentPage().getParameters().get('id')); try{ myAttach.body = psPdf.getContentAsPdf(); } catch(Exception e){} //insert myAttach; secondPage.setRedirect(true); return secondPage; } public PageReference back() { attach(); PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target'); pr.setRedirect(true); System.debug('Inside back'); return pr; } public PageReference cancel() { PageReference pr = new PageReference('/' + ApexPages.currentPage().getParameters().get('id') +'#'+ ApexPages.currentPage().getParameters().get('id') + '_RelatedNoteList_target'); pr.setRedirect(true); System.debug('Inside back'); return pr; } /*public String attachmentName{get; set;} public pagereference AttachQuote(){ Pagereference pdf = page.Quotation; blob b=pdf.getcontent(); attachment att = new attachment(); att.parentId = ApexPages.currentPage().getParameters().get('id') ; att.body = b; att.name = 'Quotation.pdf'; insert att; return null; }*/ /*test methods here*/ public static testMethod void testAttachController() { Profile p = [SELECT Id FROM Profile WHERE Name='Standard User']; User U = new User(Alias = 'TUser1', Email='testItemaster1@im.com',EmailEncodingKey='UTF-8', LastName='TestingAcc1', LanguageLocaleKey='en_US',LocaleSidKey='en_US', ProfileId =p.Id, TimeZoneSidKey='America/Los_Angeles', UserName='testacc1@test.com'); insert U; Account acc=new Account (Name='rose',BillingCity='bang',Billingstate='kat',BillingPostalcode='560000',BillingCountry='india'); insert acc; system.debug('########555'+ acc); Deal__c opp=new Deal__c(Name='test12',Account__c=acc.id); insert opp; system.debug('########7765'+ opp); Attachment myAttach1 = new Attachment(); myAttach1.ParentId =opp.id; myAttach1.name = 'Quotation.pdf'; myAttach1.body = blob.valueof('test'); insert myAttach1; system.debug('Attahment1'+ myAttach1); AttachController atc = new AttachController(new ApexPages.StandardController(opp)); system.debug('%%%%%'+atc); PageReference pageRef = Page.Quotation; pageRef.getParameters().put('id', String.valueOf(opp.Id)); Test.setCurrentPage(pageRef); Blob b; ApexPages.currentPage().getParameters().put('id', opp.id); AttachController atc1 = new AttachController(new ApexPages.StandardController(myAttach1)); //ApexPages.StandardController stc = new ApexPages.StandardController(opp); //AttachController qe = new AttachController(stc); // qe.QA(); atc.attach(); //atc.QA(); atc.back(); atc.cancel(); atc.QA(); return; /* public PageReference QA() { PageReference secondPage = new PageReference('/apex/EmailQuote?id=' + ApexPages.currentPage().getParameters().get('id')); insert myAttach1; secondPage.setRedirect(true); return secondPage; }*/ //Attachment atchoo = [Select Id, From Attachment where Name like 'Quotation.pdf' /* if (Test.isRunningTest()) { b=Blob.valueOf('Test Blob String'); } else { b= pageRef.getContent(); }*/ } }
I want to get the myattach.name in VersionNo__c field of Deal__c object shoulb get updated
Ref Line no:42
This method