• Sree_Nani
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 8
    Replies

Hi Developers,

 

System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): EmailTemplate, original object: Account: []

 

Not allowing any insertion statement, now code coverage is 55% with only emailtemplate insertion. 

 

If I am doing any mistake please help me out with modified code.

 

public class TestClass{
public Static TestMethod void taskemail(){

/* Blob b1 = Blob.valueOf('Test Data');
Attachment attachment = new Attachment();
attachment.ParentId = '02sE00000005KTDIA2';
attachment.Name = 'Test Attachment for Parent';
attachment.Body = b1;

insert(attachment); */

//public blob body{set;get;}
Account a = new Account(name='abc');
insert a;
//Account a1 = [select id,name from account limit 1];
//contact c1 = [select id,name from contact limit 1];
//opportunity o1 = [select id, name from opportunity limit 1];
Contact c = new Contact(lastname='test',email='test@advanz.com');
insert c;
//BrandTemplate b = new BrandTemplate(name='sampletemplate');
//insert b;
BrandTemplate b=[select id,name from BrandTemplate limit 1];
emailtemplate etemplate=new emailtemplate(BrandTemplateId=b.id,body='body',name='sample',TemplateStyle='formalLetter',DeveloperName='taeqst123w',folderid='00DE0000000IzueMAC',TemplateType='HTML');

//attachment a=new attachment(body=b1,name='attachfilename');
//insert a;
document doc = new document(name='sample',folderid='005E0000000HyVQ');
insert doc;
taskemail t = new taskemail();
Test.startTest();
insert etemplate;
Test.stopTest();

t.send();
t.getett();
//t.testsend();
t.cancel();
t.cancel1();
t.selectedtemplate();
t.selecttemplate();
t.viewfile();
t.done();
t.del();
t.getdoclist();
t.files();
t.getet();
t.getetlist();
t.go();
t.getattachlist();
t.getattlist();
t.fileattach();
t.getItems();

}
}

 

 

 

class code:

public class taskemail
{

public taskemail()
{
//ett=[select Body,HtmlValue,Markup,TemplateType,Description,Name from emailtemplate where DeveloperName=:'ActeionContact'];
//body=ett.body;
oid=apexpages.currentpage().getparameters().get('oid');
system.debug('+++++++++++++++++++++');
for(OpportunityContactRole ocr:[select id,contactid from OpportunityContactRole where opportunityid=:oid])
{
setid.add(ocr.contactid);
contactids.add(ocr.contactid);
}
for(contact c:[select id,name,email from contact where id in:setid])
{
mapval.put(c.id,c.name);

if(c.email!=null)
{
s=s+c.Name+',';

}
}
email=s;

}


public boolean plaintextbody{set;get;}
public boolean htmlbody{set;get;}
public boolean displayPopUp{set;get;}
public boolean attachpopup{set;get;}
public string email{set;get;}
public string subject{set;get;}
public string body{set;get;}
public string additionalemail{set;get;}
public string bcc{set;get;}
public string cc{set;get;}
set<id> setid=new set<id>();
map<id,string> mapval=new map<id,string>();
public List<Id> contactids=new List<Id>();
map<id,OpportunityContactRole> mapopp;

string s='';
public id oid;


public string errmessage{set;get;}
emailtemplate ett=new emailtemplate();
public void testsend()
{

BrandTemplate b=[select id,name from BrandTemplate limit 1];
emailtemplate etemplate=new emailtemplate();
etemplate.name='sample2';
etemplate.DeveloperName='test123w';
etemplate.folderid='00DE0000000IzueMAC';
etemplate.TemplateType='HTML';
etemplate.BrandTemplateId=b.id;
etemplate.TemplateStyle='formalLetter';
//etemplate.HtmlValue=body;

etemplate.body=body;
insert etemplate;
//send();

}
public emailtemplate getett()
{
return ett;
}

public pagereference send()
{
if(body==''||subject==''||body==null||subject==null)
{
errmessage='Required fields Subject or Body missing ';
return null;
}
else
{
set<string> strset=new set<string>();
if(email!='')
{
string[] emailaddress=email.split(',');
for(string s:emailaddress)
{
strset.add(s);
}
}
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
for (Attachment a :attlist)
{ // Add to attachment file list
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(a.Name);
efa.setBody(a.Body);
fileAttachments.add(efa);
}


for(id i:mapval.keyset())
{
if(strset.contains(mapval.get(i)))
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {mapval.get(i)};
//String[] toAddresses=s.split(',');
//system.debug('********'+toAddresses);
mail.setTargetobjectid(i);
if(additionalemail!='')
{
string[] addaddresses=additionalemail.split(',');
mail.setToAddresses(addaddresses);
}
if(cc!='')
{
string[] ccAddresses=cc.split(',');
mail.setCcAddresses(ccAddresses);
}
if(bcc!='')
{
string[] bccAddresses=bcc.split(',');
mail.setbccAddresses(bccAddresses);
}
mail.setSenderDisplayName('Daisy Cake Sales Team');
system.debug('*****'+et.id);

/*if(et.id!=null)
{
mail.setTemplateId(et.id);
//mail.setHtmlBody(body);
}
else
{*/
mail.setSubject(subject);
mail.setPlainTextBody(body);
mail.setHtmlBody(body);
//}
mail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
pagereference page=new pagereference('/'+oid);
return page;
}
return null;
}
public pagereference cancel()
{
system.debug('****************');
pagereference page=new pagereference('/'+oid);

return page;
}
list<EmailTemplate> etlist=new list<EmailTemplate>();
public void selecttemplate()
{
displayPopUp=true;
etlist=[select Body,HtmlValue,Markup,TemplateType,Description,Name from emailtemplate];

}
public list<emailtemplate> getetlist()
{
return etlist;
}
public void cancel1()
{
displayPopUp=false;
attachpopup=false;

}
emailtemplate et=new emailtemplate();
public void selectedtemplate()
{
string name=apexpages.currentpage().getparameters().get('ename');
if(name!=null)
{
et=[select id,Subject,Markup,HtmlValue,name,body from emailtemplate where name=:name];
body=et.body;
subject=et.subject;
}
displayPopUp=false;
}
public emailtemplate getet()
{
return et;
}
list<document> doclist=new list<document>();
public void files()
{
system.debug('HHHHffffffffffffffHHHHHHHHHHHHHHHHHHH');
if(attachlist.size()>0)
attachlist.clear();
attachpopup=true;
doclist=[select id,ContentType,description,name from document];
val='My Personal Documents';
if(val=='My Personal Documents')
{
documents=true;
mycomputer=false;
}
if(val=='My Computer')
{
documents=false;
mycomputer=true;
}
}
public list<document> getdoclist()
{
return doclist;
}
list<attachment> attlist=new list<attachment>();
public void fileattach()
{
string a=apexpages.currentpage().getparameters().get('dname');
if(a!=null){
document doc=[select id,name,BodyLength,body,ContentType,description from document where name=:a];
attachment att=new attachment();
att.name=doc.name;
att.contenttype=doc.contenttype;
att.description=doc.description;

att.body=doc.body;
attlist.add(att);
attachpopup=false;
}}
public list<attachment> getattlist()
{
return attlist;
}
public void del()
{
string aa=apexpages.currentpage().getparameters().get('delname');

integer i=0;
for(attachment a:attlist)
{
if(a.name==aa)
{

attlist.remove(i);
break;
}
i++;
}


}
public string val{set;get;}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('My Personal Documents','My Personal Documents'));
options.add(new SelectOption('My Computer','My Computer'));

return options;
}
public pagereference viewfile()
{
string a=apexpages.currentpage().getparameters().get('fname');
pagereference page;
document doc;
if(a!=null){
doc=[select id,name,BodyLength,body,ContentType,description from document where name=:a];
page=new pagereference('/servlet/servlet.FileDownload?file='+doc.id);}
return page;
}
public boolean documents{set;get;}
public boolean mycomputer{set;get;}
public blob attfile{set;get;}
public void go()
{
if(val=='My Personal Documents')
{
documents=true;
mycomputer=false;

}
if(val=='My Computer')
{
documents=false;
mycomputer=true;
}

}
public string attachfilename{set;get;}
public integer attachfileSize{set;get;}
List<attachment> attachlist=new list<attachment>();
public void attach()
{
attachment a=new attachment();
a.body=attfile;
//a.BodyLength=attachfileSize;
a.name=attachfilename;
attachlist.add(a);

}
public void done()
{
if(attachlist.size()>0)
attlist=attachlist;
attachpopup=false;

}
public list<attachment> getattachlist()
{
return attachlist;
}
public void testval()
{
system.debug('**************');

}
}


Hi developers,

 

                     I am asking small doubt which i have a problem. I want to pass an Id to URL. 

Your question is Which Id you need to pass?

 

I want to create a new record from vf page of any object as a standard controller & I want to get that newly created record Id. That Id i want to pass to URL. 

 

 

How can I do this ?

Hi,

 

           I am facing an issue with my salesforce account. The issue is, "Your company's Single Sign-On configuration is invalid. Please contact the administrator at your company for more information.

 

I am trying to enable single sign-on process in my dev account. In administrator profile, I checked one checkbox called "Is single sign on enabled". after that my account is locked. from one week i am facing this issue & I sent a mail to support team. No one giving reply.

 

For support team people:: sreenath.jpnce@gmail.com this is my username of my salesforce account, which is locked.

 

can any one know how to login into my account???

Hi Developers,

 

System.DmlException: Insert failed. First exception on row 0; first error: MIXED_DML_OPERATION, DML operation on setup object is not permitted after you have updated a non-setup object (or vice versa): EmailTemplate, original object: Account: []

 

Not allowing any insertion statement, now code coverage is 55% with only emailtemplate insertion. 

 

If I am doing any mistake please help me out with modified code.

 

public class TestClass{
public Static TestMethod void taskemail(){

/* Blob b1 = Blob.valueOf('Test Data');
Attachment attachment = new Attachment();
attachment.ParentId = '02sE00000005KTDIA2';
attachment.Name = 'Test Attachment for Parent';
attachment.Body = b1;

insert(attachment); */

//public blob body{set;get;}
Account a = new Account(name='abc');
insert a;
//Account a1 = [select id,name from account limit 1];
//contact c1 = [select id,name from contact limit 1];
//opportunity o1 = [select id, name from opportunity limit 1];
Contact c = new Contact(lastname='test',email='test@advanz.com');
insert c;
//BrandTemplate b = new BrandTemplate(name='sampletemplate');
//insert b;
BrandTemplate b=[select id,name from BrandTemplate limit 1];
emailtemplate etemplate=new emailtemplate(BrandTemplateId=b.id,body='body',name='sample',TemplateStyle='formalLetter',DeveloperName='taeqst123w',folderid='00DE0000000IzueMAC',TemplateType='HTML');

//attachment a=new attachment(body=b1,name='attachfilename');
//insert a;
document doc = new document(name='sample',folderid='005E0000000HyVQ');
insert doc;
taskemail t = new taskemail();
Test.startTest();
insert etemplate;
Test.stopTest();

t.send();
t.getett();
//t.testsend();
t.cancel();
t.cancel1();
t.selectedtemplate();
t.selecttemplate();
t.viewfile();
t.done();
t.del();
t.getdoclist();
t.files();
t.getet();
t.getetlist();
t.go();
t.getattachlist();
t.getattlist();
t.fileattach();
t.getItems();

}
}

 

 

 

class code:

public class taskemail
{

public taskemail()
{
//ett=[select Body,HtmlValue,Markup,TemplateType,Description,Name from emailtemplate where DeveloperName=:'ActeionContact'];
//body=ett.body;
oid=apexpages.currentpage().getparameters().get('oid');
system.debug('+++++++++++++++++++++');
for(OpportunityContactRole ocr:[select id,contactid from OpportunityContactRole where opportunityid=:oid])
{
setid.add(ocr.contactid);
contactids.add(ocr.contactid);
}
for(contact c:[select id,name,email from contact where id in:setid])
{
mapval.put(c.id,c.name);

if(c.email!=null)
{
s=s+c.Name+',';

}
}
email=s;

}


public boolean plaintextbody{set;get;}
public boolean htmlbody{set;get;}
public boolean displayPopUp{set;get;}
public boolean attachpopup{set;get;}
public string email{set;get;}
public string subject{set;get;}
public string body{set;get;}
public string additionalemail{set;get;}
public string bcc{set;get;}
public string cc{set;get;}
set<id> setid=new set<id>();
map<id,string> mapval=new map<id,string>();
public List<Id> contactids=new List<Id>();
map<id,OpportunityContactRole> mapopp;

string s='';
public id oid;


public string errmessage{set;get;}
emailtemplate ett=new emailtemplate();
public void testsend()
{

BrandTemplate b=[select id,name from BrandTemplate limit 1];
emailtemplate etemplate=new emailtemplate();
etemplate.name='sample2';
etemplate.DeveloperName='test123w';
etemplate.folderid='00DE0000000IzueMAC';
etemplate.TemplateType='HTML';
etemplate.BrandTemplateId=b.id;
etemplate.TemplateStyle='formalLetter';
//etemplate.HtmlValue=body;

etemplate.body=body;
insert etemplate;
//send();

}
public emailtemplate getett()
{
return ett;
}

public pagereference send()
{
if(body==''||subject==''||body==null||subject==null)
{
errmessage='Required fields Subject or Body missing ';
return null;
}
else
{
set<string> strset=new set<string>();
if(email!='')
{
string[] emailaddress=email.split(',');
for(string s:emailaddress)
{
strset.add(s);
}
}
List<Messaging.Emailfileattachment> fileAttachments = new List<Messaging.Emailfileattachment>();
for (Attachment a :attlist)
{ // Add to attachment file list
Messaging.Emailfileattachment efa = new Messaging.Emailfileattachment();
efa.setFileName(a.Name);
efa.setBody(a.Body);
fileAttachments.add(efa);
}


for(id i:mapval.keyset())
{
if(strset.contains(mapval.get(i)))
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
String[] toAddresses = new String[] {mapval.get(i)};
//String[] toAddresses=s.split(',');
//system.debug('********'+toAddresses);
mail.setTargetobjectid(i);
if(additionalemail!='')
{
string[] addaddresses=additionalemail.split(',');
mail.setToAddresses(addaddresses);
}
if(cc!='')
{
string[] ccAddresses=cc.split(',');
mail.setCcAddresses(ccAddresses);
}
if(bcc!='')
{
string[] bccAddresses=bcc.split(',');
mail.setbccAddresses(bccAddresses);
}
mail.setSenderDisplayName('Daisy Cake Sales Team');
system.debug('*****'+et.id);

/*if(et.id!=null)
{
mail.setTemplateId(et.id);
//mail.setHtmlBody(body);
}
else
{*/
mail.setSubject(subject);
mail.setPlainTextBody(body);
mail.setHtmlBody(body);
//}
mail.setFileAttachments(fileAttachments);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
}
}
pagereference page=new pagereference('/'+oid);
return page;
}
return null;
}
public pagereference cancel()
{
system.debug('****************');
pagereference page=new pagereference('/'+oid);

return page;
}
list<EmailTemplate> etlist=new list<EmailTemplate>();
public void selecttemplate()
{
displayPopUp=true;
etlist=[select Body,HtmlValue,Markup,TemplateType,Description,Name from emailtemplate];

}
public list<emailtemplate> getetlist()
{
return etlist;
}
public void cancel1()
{
displayPopUp=false;
attachpopup=false;

}
emailtemplate et=new emailtemplate();
public void selectedtemplate()
{
string name=apexpages.currentpage().getparameters().get('ename');
if(name!=null)
{
et=[select id,Subject,Markup,HtmlValue,name,body from emailtemplate where name=:name];
body=et.body;
subject=et.subject;
}
displayPopUp=false;
}
public emailtemplate getet()
{
return et;
}
list<document> doclist=new list<document>();
public void files()
{
system.debug('HHHHffffffffffffffHHHHHHHHHHHHHHHHHHH');
if(attachlist.size()>0)
attachlist.clear();
attachpopup=true;
doclist=[select id,ContentType,description,name from document];
val='My Personal Documents';
if(val=='My Personal Documents')
{
documents=true;
mycomputer=false;
}
if(val=='My Computer')
{
documents=false;
mycomputer=true;
}
}
public list<document> getdoclist()
{
return doclist;
}
list<attachment> attlist=new list<attachment>();
public void fileattach()
{
string a=apexpages.currentpage().getparameters().get('dname');
if(a!=null){
document doc=[select id,name,BodyLength,body,ContentType,description from document where name=:a];
attachment att=new attachment();
att.name=doc.name;
att.contenttype=doc.contenttype;
att.description=doc.description;

att.body=doc.body;
attlist.add(att);
attachpopup=false;
}}
public list<attachment> getattlist()
{
return attlist;
}
public void del()
{
string aa=apexpages.currentpage().getparameters().get('delname');

integer i=0;
for(attachment a:attlist)
{
if(a.name==aa)
{

attlist.remove(i);
break;
}
i++;
}


}
public string val{set;get;}
public List<SelectOption> getItems() {
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('My Personal Documents','My Personal Documents'));
options.add(new SelectOption('My Computer','My Computer'));

return options;
}
public pagereference viewfile()
{
string a=apexpages.currentpage().getparameters().get('fname');
pagereference page;
document doc;
if(a!=null){
doc=[select id,name,BodyLength,body,ContentType,description from document where name=:a];
page=new pagereference('/servlet/servlet.FileDownload?file='+doc.id);}
return page;
}
public boolean documents{set;get;}
public boolean mycomputer{set;get;}
public blob attfile{set;get;}
public void go()
{
if(val=='My Personal Documents')
{
documents=true;
mycomputer=false;

}
if(val=='My Computer')
{
documents=false;
mycomputer=true;
}

}
public string attachfilename{set;get;}
public integer attachfileSize{set;get;}
List<attachment> attachlist=new list<attachment>();
public void attach()
{
attachment a=new attachment();
a.body=attfile;
//a.BodyLength=attachfileSize;
a.name=attachfilename;
attachlist.add(a);

}
public void done()
{
if(attachlist.size()>0)
attlist=attachlist;
attachpopup=false;

}
public list<attachment> getattachlist()
{
return attachlist;
}
public void testval()
{
system.debug('**************');

}
}


Hi developers,

 

                     I am asking small doubt which i have a problem. I want to pass an Id to URL. 

Your question is Which Id you need to pass?

 

I want to create a new record from vf page of any object as a standard controller & I want to get that newly created record Id. That Id i want to pass to URL. 

 

 

How can I do this ?

Hi,

 

           I am facing an issue with my salesforce account. The issue is, "Your company's Single Sign-On configuration is invalid. Please contact the administrator at your company for more information.

 

I am trying to enable single sign-on process in my dev account. In administrator profile, I checked one checkbox called "Is single sign on enabled". after that my account is locked. from one week i am facing this issue & I sent a mail to support team. No one giving reply.

 

For support team people:: sreenath.jpnce@gmail.com this is my username of my salesforce account, which is locked.

 

can any one know how to login into my account???

Hello,

 

I am desperate!  Is there a validation to set it so if "Integration__c" picklist has "PCI" selected, than "CPM__c" will be locked and unable to be edited?  I'd like it to be greyed out, or locked.  Please let me know if this is possible with validations, or if there is another way to do this.  Alternatively, if there is some other clever workaround, please let me know.

 

Thanks.

I'm trying to re-create the "Attach File" page using visualforce, but with big files, it is throwing the following error:

 

Maximum view state size limit (128K) exceeded. Actual viewstate size for this page was 142.438K

 

I've already been through the forums and the following post --

http://community.salesforce.com/sforce/board/message?board.id=Visualforce&message.id=10488#M10488

 

I tried commenting out lines to see if it would help, but the error doesn't go away.

 

 Here's the code --

 

 

public class OpportunityAttachFile {
public Opportunity oppty {get;set;}
public String fileName {get;set;}
public List<String> uploadedList {get;set;}
public Blob fileBody {get;set;}

public OpportunityAttachFile (ApexPages.StandardController controller) {
oppty = (Opportunity)controller.getRecord();
uploadedList = new List<String>();
}

public void attachFileAction() {
Attachment a = new Attachment();
a.ParentId = oppty.Id;
a.Name = fileName;
//NOTE: Here, I am commenting out segments of the code just to see if the error would go away, but it does not help.
//a.Body = fileBody;
//insert a;

//Clearing out the contents to avoid hitting viewstate limits
a = null;
}

public PageReference doneAction() {
return new PageReference('/' + oppty.Id);
}
}

 

 Help?
  • July 17, 2009
  • Like
  • 0