- Jayati Arora
- NEWBIE
- 10 Points
- Member since 2014
- Salesforce Developer
- Techmatrix Consulting Pte
-
ChatterFeed
-
0Best Answers
-
1Likes Received
-
0Likes Given
-
5Questions
-
12Replies
Hi When I insert same company name using data loader, trigger fails. Please help me with work around
map<String,Account> accmap = new map<String,Account>();
list<Account> acclist = new list<Account>();
list<Contact> conlist =new list<Contact>();
list<Opportunity> Opplist = new list<Opportunity>();
for(Lead l:Trigger.new){
Account acc = new Account ();
acc.name = l.company;
accmap.put(acc.name,acc);
}
insert accmap.values();
for(Lead l:Trigger.new){
Contact con = new Contact();
con.lastname =l.lastname ;
con.AccountId= accmap.get(l.company).Id;
conlist.add(con);
Opportunity Opp=new Opportunity();
Opp.AccountId = accmap.get(l.company).Id;
Opp.Name = 'Opp' + l.lastname;
Opp.StageName='Closed Won';
Opp.CloseDate = System.Today();
Opplist.add(Opp);
}
insert conlist;
insert Opplist;
}
- Jayati Arora
- September 10, 2014
- Like
- 1
System.DmlException: Update failed.first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: [] Trigger.addAttachmentNameInReport: line 115, column 1
Hi Guys,
Please help me out with above error which I am facing during bulk update. Below is the code mentioned:-
trigger addAttachmentNameInReport on Attachment (after delete, after insert, after undelete, after update){
Set<ID> oppIdSet =new Set<id>();
Set<ID> jobrefIdSet =new Set<id>();
Set<ID> artworkIdSet =new Set<id>();
Map<Id,Opportunity> oppMap ;
Map<Id,Job_Reference__c> jobrefMap ;
Map<Id,artApp__Artwork__c> artworkMap ;
if(trigger.isInsert || trigger.isUpdate){
for(Attachment a: Trigger.new){
String objName = a.parentId.getSObjectType().getDescribe().getName();
if(objName == 'Opportunity'){
oppIdSet.add(a.parentid);
}
else if(objName== 'job_reference__c'){
jobrefIdSet.add(a.parentid);
}
else if(objName== 'artApp__Artwork__c'){
artworkIdSet.add(a.parentid);
}
}
}
if(trigger.isdelete){
for(Attachment a: Trigger.old){
String objName = a.parentId.getSObjectType().getDescribe().getName();
if(objName == 'Opportunity'){
oppIdSet.add(a.parentid);
}
else if(objName== 'job_reference__c'){
jobrefIdSet.add(a.parentid);
}
else if(objName== 'artApp__Artwork__c'){
artworkIdSet.add(a.parentid);
}
}
}
if(trigger.isInsert || trigger.isUpdate){
if(oppIdSet.size() > 0 ){
oppMap = new Map<Id,Opportunity>([select Id,Attachment__c from Opportunity where Id IN: oppIdSet]);
if(oppMap.size() > 0 ){
for(Attachment att : Trigger.new){
if(oppMap.get(att.parentId) != null){
if(oppMap.get(att.parentId).Attachment__c != null && oppMap.get(att.parentId).Attachment__c != ''){
if(Trigger.isInsert){
oppMap.get(att.parentId).Attachment__c += +'\n' +att.Name;
}
else if(Trigger.isUpdate){
system.debug('Updateeeee === ');
system.debug('$$$$$$'+ Trigger.oldMap.get(att.Id).Name);
system.debug('value of new name'+ att.Name);
if(Trigger.oldMap.get(att.Id).Name != att.Name && oppMap.get(att.parentId).Attachment__c.contains(Trigger.oldMap.get(att.Id).Name)){
oppMap.get(att.parentId).Attachment__c = oppMap.get(att.parentId).Attachment__c.replaceFirst(Trigger.oldMap.get(att.Id).Name,att.Name);
system.debug('Old Name=== '+Trigger.oldMap.get(att.Id).Name);
system.debug('Assingd Name === '+oppMap.get(att.parentId).Attachment__c);
}
}
}
else{
oppMap.get(att.parentId).Attachment__c = att.Name;
}
}
}
update oppMap.values();
}
}
if(jobrefIdSet.size()>0){
jobrefMap = new Map<Id,job_reference__c>([select Id,Attachment__c from job_reference__c where Id IN: jobrefIdSet]);
if(jobrefMap.size() > 0 ){
for(Attachment att : Trigger.new){
if(jobrefMap.get(att.parentId) != null){
if(jobrefMap.get(att.parentId).Attachment__c != null && jobrefMap.get(att.parentId).Attachment__c != ''){
if(Trigger.isInsert){
jobrefMap.get(att.parentId).Attachment__c += +'\n' +att.Name;
}
else if(Trigger.isUpdate){
system.debug('Updateeeee === ');
if(Trigger.oldMap.get(att.Id).Name != att.Name && jobrefMap.get(att.parentId).Attachment__c.contains(Trigger.oldMap.get(att.Id).Name)){
jobrefMap.get(att.parentId).Attachment__c = jobrefMap.get(att.parentId).Attachment__c.replaceFirst(Trigger.oldMap.get(att.Id).Name,att.Name);
system.debug('Old Name=== '+Trigger.oldMap.get(att.Id).Name);
system.debug('Assingd Name === '+jobrefMap.get(att.parentId).Attachment__c);
}
}
}
else{
jobrefMap.get(att.parentId).Attachment__c = att.Name;
}
}
}
update jobrefMap.values();
}
}
if(artworkIdSet.size()>0){
artworkMap = new Map<Id,artApp__Artwork__c>([select Id,Attachment__c from artApp__Artwork__c where Id IN: artworkIdSet]);
if(artworkMap.size() > 0 ){
for(Attachment att : Trigger.new){
if(artworkMap.get(att.parentId) != null){
if(artworkMap.get(att.parentId).Attachment__c != null && artworkMap.get(att.parentId).Attachment__c != ''){
if(Trigger.isInsert){
artworkMap.get(att.parentId).Attachment__c += +'\n' +att.Name;
}
else if(Trigger.isUpdate){
system.debug('Updateeeee === ');
if(Trigger.oldMap.get(att.Id).Name != att.Name && artworkMap.get(att.parentId).Attachment__c.contains(Trigger.oldMap.get(att.Id).Name)){
artworkMap.get(att.parentId).Attachment__c = artworkMap.get(att.parentId).Attachment__c.replaceFirst(Trigger.oldMap.get(att.Id).Name,att.Name);
system.debug('Old Name=== '+Trigger.oldMap.get(att.Id).Name);
system.debug('Assingd Name === '+artworkMap.get(att.parentId).Attachment__c);
}
}
}
else{
artworkMap.get(att.parentId).Attachment__c = att.Name;
}
}
}
update artworkMap.values();
}
}
}
else if(Trigger.isDelete){
if(oppIdSet.size() > 0 ){
system.debug('Opp Size'+oppIdSet.size());
oppMap = new Map<Id,Opportunity>([select Id,Attachment__c from Opportunity where Id IN: oppIdSet]);
if(oppMap.size() > 0 ){
for(Attachment att : Trigger.old){
if(oppMap.get(att.parentId).attachment__c != null && oppMap.get(att.parentId).attachment__c != '' && oppMap.get(att.parentId).Attachment__c.contains(Trigger.oldMap.get(att.Id).Name)){
oppMap.get(att.parentId).attachment__c = oppMap.get(att.parentId).attachment__c.replaceFirst(Trigger.oldMap.get(att.Id).Name,'');
}
}
Update oppMap.values();
}
}
if(jobrefIdSet.size()>0){
jobrefMap = new Map<Id,job_reference__c>([select Id,Attachment__c from job_reference__c where Id IN: jobrefIdSet]);
if(jobrefMap.size() > 0 ){
for(Attachment att : Trigger.old){
if(jobrefMap.get(att.parentId).attachment__c != null && jobrefMap.get(att.parentId).attachment__c != '' && jobrefMap.get(att.parentId).Attachment__c.contains(Trigger.oldMap.get(att.Id).Name)){
jobrefMap.get(att.parentId).attachment__c = jobrefMap.get(att.parentId).attachment__c.replaceFirst(Trigger.oldMap.get(att.Id).Name,'');
}
}
update jobrefMap.values();
}
}
if(artworkIdSet.size()>0){
artworkMap = new Map<Id,artApp__Artwork__c>([select Id,Attachment__c from artApp__Artwork__c where Id IN: artworkIdSet]);
if(artworkMap.size() > 0 ){
for(Attachment att : Trigger.old){
if(artworkMap.get(att.parentId).attachment__c != null && artworkMap.get(att.parentId).attachment__c != '' && artworkMap.get(att.parentId).Attachment__c.contains(Trigger.oldMap.get(att.Id).Name)){
artworkMap.get(att.parentId).attachment__c = artworkMap.get(att.parentId).attachment__c.replaceFirst(Trigger.oldMap.get(att.Id).Name,'');
}
}
update artworkMap.values();
}
}
}
}
- Jayati Arora
- August 20, 2014
- Like
- 0
I am getting input values as null. Please help and expalin the reason?
<apex:page controller="ContactSearchController" >
<apex:form >
<apex:pageMessages />
<apex:pageBlock title="Enter Inputs">
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!Searchresult}" value="Search"/>
</apex:pageBlockButtons>
<apex:pageblockSection >
<apex:inputField value="{!c.Lastname}"/>
<apex:inputField value="{!c.Phone}"/>
<apex:inputField value="{!c.Email}"/>
<apex:inputField value="{!c.AccountId}"/>
</apex:pageblockSection>
</apex:pageBlock>
<apex:pageblock title="Search Results" rendered="{!showsearchresults}">
<apex:pageblockTable value="{!conList}" var="c">
<apex:column value="{!c.lastname}"/>
<apex:column value="{!c.phone}"/>
<apex:column value="{!c.email}"/>
<apex:column value="{!c.accountId}"/>
</apex:pageblockTable>
</apex:pageblock>
</apex:form>
</apex:page>
public class ContactSearchController{
public Contact C {get;set;}
public list<contact> conList{get;set;}
public boolean showsearchresults{get;set;}
public ContactSearchController(){
//C = new Contact();
showsearchresults=false;
}
public pagereference Searchresult(){
C = new Contact();
conList=new list<contact>();
if(c.Lastname== null || c.Lastname=='' && c.Email==null || c.Email=='' && c.Phone==null || c.Phone =='' && c.AccountId==null || c.AccountId ==''){
System.debug('Value of lastname'+ c.Lastname);
System.debug('Value of Email'+ c.Email);
System.debug('Value of Phone'+ c.Phone);
System.debug('Value of AccountId'+ c.AccountId);
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please enter values for all input fields'));
showSearchResults=false;
return null;
}
System.debug('Size of list of contacts before SOQL'+conList.size());
conList = [Select lastname,email,phone,accountId from Contact where (lastname=:c.Lastname and email=:c.Email and phone=:c.Phone and accountId=:c.AccountId)and (lastname !=null and email!=null and phone!=null and accountId!=null)];
System.debug('Size of list of contacts after SOQL'+conList.size());
System.debug('values of list of contacts after SOQL'+conList);
if(conList.size()==0){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No matching Contact record found');
ApexPages.addMessage(myMsg);
showSearchResults=false;
return null;
}
else if(conList.size()>0){
showSearchResults=true;
return null;
}
return null;
}
}
- Jayati Arora
- August 07, 2014
- Like
- 0
Hi All, I want pageblock to be refreshed if after one search I leave my input fields as blank then only error message must be shown but currently my page is showing error along with old matched result.
<apex:form Id="FRM">
<apex:pagemessages />
<apex:pageblock title="Account Search" >
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Search" action="{!searchaccount}" reRender="op"/>
</apex:pageBlockButtons>
<apex:pageblocksection columns="2">
<apex:inputText label="Enter Account Name" value="{!acctname}"/><br/>
<apex:inputText label="Enter Account Phone" value="{!accntphone}"/><br/>
</apex:pageblocksection>
</apex:pageblock>
<apex:outputPanel id="op">
<apex:pageblock title="Account Search Results" rendered="{!showSearchResults}" id="pb">
<apex:pageBlockTable value="{!acntList}" var="c">
<apex:column value="{!c.Name}"/>
<apex:column value="{!c.Phone}" />
</apex:pageBlockTable>
</apex:pageblock>
</apex:outputPanel>
</apex:form>
</apex:page>
public class AccountSearchController{
public String acctname{get;set;}
public String accntphone{get;set;}
public list<account> acntList{get;set;}
public boolean showSearchResults{get;set;}
//String myMsg{get;set;}
public AccountSearchController(){
system.debug('====== constr ');
}
public AccountSearchController(ApexPages.StandardController controller){
showSearchResults=false;
acntList= new list<account>();
system.debug('====== constr with param ');
}
public pagereference searchaccount(){
system.debug('=== acctname '+acctname );
system.debug('=== accntphone'+accntphone);
if((acctname==null || acctname == '') && (accntphone==null || accntphone == '')){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please enter either account name or account phone'));
return null;
}
else if((acctname != null && acctname != '') || (accntphone != null && accntphone != '')){
acntList=[Select name,id,phone from account where (name=:acctname or phone=:accntphone) and (phone != null and name != null)];
System.debug('List of account values'+acntList);
System.debug('Size of account list'+acntList.size());
if(acntList.size()==0){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No matching account record found');
ApexPages.addMessage(myMsg);
showSearchResults=false;
return null;
}else if(acntList.size() > 0){
showSearchResults=true;
}
}
return null;
}
}
- Jayati Arora
- August 06, 2014
- Like
- 0
Hi All, I want pageblock to be refreshed if after one search I leave my input fields as blank then only error message must be shown but currently my page is showing error along with old matched result.
<apex:page standardController="Account" extensions="AccountSearchController">
<apex:form Id="FRM">
<apex:pagemessages />
<apex:pageblock title="Account Search" >
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Search" action="{!searchaccount}" reRender="op"/>
</apex:pageBlockButtons>
<apex:pageblocksection columns="2">
<apex:inputText label="Enter Account Name" value="{!acctname}"/><br/>
<apex:inputText label="Enter Account Phone" value="{!accntphone}"/><br/>
</apex:pageblocksection>
</apex:pageblock>
<apex:outputPanel id="op">
<apex:pageblock title="Account Search Results" rendered="{!showSearchResults}" id="pb">
<apex:pageBlockTable value="{!acntList}" var="c">
<apex:column value="{!c.Name}"/>
<apex:column value="{!c.Phone}" />
</apex:pageBlockTable>
</apex:pageblock>
</apex:outputPanel>
</apex:form>
</apex:page>
public class AccountSearchController{
public String acctname{get;set;}
public String accntphone{get;set;}
public list<account> acntList{get;set;}
public boolean showSearchResults{get;set;}
//String myMsg{get;set;}
public AccountSearchController(){
system.debug('====== constr ');
}
public AccountSearchController(ApexPages.StandardController controller){
showSearchResults=false;
acntList= new list<account>();
system.debug('====== constr with param ');
}
public pagereference searchaccount(){
system.debug('=== acctname '+acctname );
system.debug('=== accntphone'+accntphone);
if((acctname==null || acctname == '') && (accntphone==null || accntphone == '')){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please enter either account name or account phone'));
return null;
}
else if((acctname != null && acctname != '') || (accntphone != null && accntphone != '')){
acntList=[Select name,id,phone from account where (name=:acctname or phone=:accntphone) and (phone != null and name != null)];
System.debug('List of account values'+acntList);
System.debug('Size of account list'+acntList.size());
if(acntList.size()==0){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No matching account record found');
ApexPages.addMessage(myMsg);
showSearchResults=false;
return null;
}else if(acntList.size() > 0){
showSearchResults=true;
}
}
return null;
}
}
Tried rerendering with ID of form as well, but no search results are getting displayed.
- Jayati Arora
- August 06, 2014
- Like
- 0
Hi When I insert same company name using data loader, trigger fails. Please help me with work around
map<String,Account> accmap = new map<String,Account>();
list<Account> acclist = new list<Account>();
list<Contact> conlist =new list<Contact>();
list<Opportunity> Opplist = new list<Opportunity>();
for(Lead l:Trigger.new){
Account acc = new Account ();
acc.name = l.company;
accmap.put(acc.name,acc);
}
insert accmap.values();
for(Lead l:Trigger.new){
Contact con = new Contact();
con.lastname =l.lastname ;
con.AccountId= accmap.get(l.company).Id;
conlist.add(con);
Opportunity Opp=new Opportunity();
Opp.AccountId = accmap.get(l.company).Id;
Opp.Name = 'Opp' + l.lastname;
Opp.StageName='Closed Won';
Opp.CloseDate = System.Today();
Opplist.add(Opp);
}
insert conlist;
insert Opplist;
}
- Jayati Arora
- September 10, 2014
- Like
- 1
Hi When I insert same company name using data loader, trigger fails. Please help me with work around
map<String,Account> accmap = new map<String,Account>();
list<Account> acclist = new list<Account>();
list<Contact> conlist =new list<Contact>();
list<Opportunity> Opplist = new list<Opportunity>();
for(Lead l:Trigger.new){
Account acc = new Account ();
acc.name = l.company;
accmap.put(acc.name,acc);
}
insert accmap.values();
for(Lead l:Trigger.new){
Contact con = new Contact();
con.lastname =l.lastname ;
con.AccountId= accmap.get(l.company).Id;
conlist.add(con);
Opportunity Opp=new Opportunity();
Opp.AccountId = accmap.get(l.company).Id;
Opp.Name = 'Opp' + l.lastname;
Opp.StageName='Closed Won';
Opp.CloseDate = System.Today();
Opplist.add(Opp);
}
insert conlist;
insert Opplist;
}
- Jayati Arora
- September 10, 2014
- Like
- 1
System.DmlException: Update failed.first error: UNABLE_TO_LOCK_ROW, unable to obtain exclusive access to this record: [] Trigger.addAttachmentNameInReport: line 115, column 1
Hi Guys,
Please help me out with above error which I am facing during bulk update. Below is the code mentioned:-
trigger addAttachmentNameInReport on Attachment (after delete, after insert, after undelete, after update){
Set<ID> oppIdSet =new Set<id>();
Set<ID> jobrefIdSet =new Set<id>();
Set<ID> artworkIdSet =new Set<id>();
Map<Id,Opportunity> oppMap ;
Map<Id,Job_Reference__c> jobrefMap ;
Map<Id,artApp__Artwork__c> artworkMap ;
if(trigger.isInsert || trigger.isUpdate){
for(Attachment a: Trigger.new){
String objName = a.parentId.getSObjectType().getDescribe().getName();
if(objName == 'Opportunity'){
oppIdSet.add(a.parentid);
}
else if(objName== 'job_reference__c'){
jobrefIdSet.add(a.parentid);
}
else if(objName== 'artApp__Artwork__c'){
artworkIdSet.add(a.parentid);
}
}
}
if(trigger.isdelete){
for(Attachment a: Trigger.old){
String objName = a.parentId.getSObjectType().getDescribe().getName();
if(objName == 'Opportunity'){
oppIdSet.add(a.parentid);
}
else if(objName== 'job_reference__c'){
jobrefIdSet.add(a.parentid);
}
else if(objName== 'artApp__Artwork__c'){
artworkIdSet.add(a.parentid);
}
}
}
if(trigger.isInsert || trigger.isUpdate){
if(oppIdSet.size() > 0 ){
oppMap = new Map<Id,Opportunity>([select Id,Attachment__c from Opportunity where Id IN: oppIdSet]);
if(oppMap.size() > 0 ){
for(Attachment att : Trigger.new){
if(oppMap.get(att.parentId) != null){
if(oppMap.get(att.parentId).Attachment__c != null && oppMap.get(att.parentId).Attachment__c != ''){
if(Trigger.isInsert){
oppMap.get(att.parentId).Attachment__c += +'\n' +att.Name;
}
else if(Trigger.isUpdate){
system.debug('Updateeeee === ');
system.debug('$$$$$$'+ Trigger.oldMap.get(att.Id).Name);
system.debug('value of new name'+ att.Name);
if(Trigger.oldMap.get(att.Id).Name != att.Name && oppMap.get(att.parentId).Attachment__c.contains(Trigger.oldMap.get(att.Id).Name)){
oppMap.get(att.parentId).Attachment__c = oppMap.get(att.parentId).Attachment__c.replaceFirst(Trigger.oldMap.get(att.Id).Name,att.Name);
system.debug('Old Name=== '+Trigger.oldMap.get(att.Id).Name);
system.debug('Assingd Name === '+oppMap.get(att.parentId).Attachment__c);
}
}
}
else{
oppMap.get(att.parentId).Attachment__c = att.Name;
}
}
}
update oppMap.values();
}
}
if(jobrefIdSet.size()>0){
jobrefMap = new Map<Id,job_reference__c>([select Id,Attachment__c from job_reference__c where Id IN: jobrefIdSet]);
if(jobrefMap.size() > 0 ){
for(Attachment att : Trigger.new){
if(jobrefMap.get(att.parentId) != null){
if(jobrefMap.get(att.parentId).Attachment__c != null && jobrefMap.get(att.parentId).Attachment__c != ''){
if(Trigger.isInsert){
jobrefMap.get(att.parentId).Attachment__c += +'\n' +att.Name;
}
else if(Trigger.isUpdate){
system.debug('Updateeeee === ');
if(Trigger.oldMap.get(att.Id).Name != att.Name && jobrefMap.get(att.parentId).Attachment__c.contains(Trigger.oldMap.get(att.Id).Name)){
jobrefMap.get(att.parentId).Attachment__c = jobrefMap.get(att.parentId).Attachment__c.replaceFirst(Trigger.oldMap.get(att.Id).Name,att.Name);
system.debug('Old Name=== '+Trigger.oldMap.get(att.Id).Name);
system.debug('Assingd Name === '+jobrefMap.get(att.parentId).Attachment__c);
}
}
}
else{
jobrefMap.get(att.parentId).Attachment__c = att.Name;
}
}
}
update jobrefMap.values();
}
}
if(artworkIdSet.size()>0){
artworkMap = new Map<Id,artApp__Artwork__c>([select Id,Attachment__c from artApp__Artwork__c where Id IN: artworkIdSet]);
if(artworkMap.size() > 0 ){
for(Attachment att : Trigger.new){
if(artworkMap.get(att.parentId) != null){
if(artworkMap.get(att.parentId).Attachment__c != null && artworkMap.get(att.parentId).Attachment__c != ''){
if(Trigger.isInsert){
artworkMap.get(att.parentId).Attachment__c += +'\n' +att.Name;
}
else if(Trigger.isUpdate){
system.debug('Updateeeee === ');
if(Trigger.oldMap.get(att.Id).Name != att.Name && artworkMap.get(att.parentId).Attachment__c.contains(Trigger.oldMap.get(att.Id).Name)){
artworkMap.get(att.parentId).Attachment__c = artworkMap.get(att.parentId).Attachment__c.replaceFirst(Trigger.oldMap.get(att.Id).Name,att.Name);
system.debug('Old Name=== '+Trigger.oldMap.get(att.Id).Name);
system.debug('Assingd Name === '+artworkMap.get(att.parentId).Attachment__c);
}
}
}
else{
artworkMap.get(att.parentId).Attachment__c = att.Name;
}
}
}
update artworkMap.values();
}
}
}
else if(Trigger.isDelete){
if(oppIdSet.size() > 0 ){
system.debug('Opp Size'+oppIdSet.size());
oppMap = new Map<Id,Opportunity>([select Id,Attachment__c from Opportunity where Id IN: oppIdSet]);
if(oppMap.size() > 0 ){
for(Attachment att : Trigger.old){
if(oppMap.get(att.parentId).attachment__c != null && oppMap.get(att.parentId).attachment__c != '' && oppMap.get(att.parentId).Attachment__c.contains(Trigger.oldMap.get(att.Id).Name)){
oppMap.get(att.parentId).attachment__c = oppMap.get(att.parentId).attachment__c.replaceFirst(Trigger.oldMap.get(att.Id).Name,'');
}
}
Update oppMap.values();
}
}
if(jobrefIdSet.size()>0){
jobrefMap = new Map<Id,job_reference__c>([select Id,Attachment__c from job_reference__c where Id IN: jobrefIdSet]);
if(jobrefMap.size() > 0 ){
for(Attachment att : Trigger.old){
if(jobrefMap.get(att.parentId).attachment__c != null && jobrefMap.get(att.parentId).attachment__c != '' && jobrefMap.get(att.parentId).Attachment__c.contains(Trigger.oldMap.get(att.Id).Name)){
jobrefMap.get(att.parentId).attachment__c = jobrefMap.get(att.parentId).attachment__c.replaceFirst(Trigger.oldMap.get(att.Id).Name,'');
}
}
update jobrefMap.values();
}
}
if(artworkIdSet.size()>0){
artworkMap = new Map<Id,artApp__Artwork__c>([select Id,Attachment__c from artApp__Artwork__c where Id IN: artworkIdSet]);
if(artworkMap.size() > 0 ){
for(Attachment att : Trigger.old){
if(artworkMap.get(att.parentId).attachment__c != null && artworkMap.get(att.parentId).attachment__c != '' && artworkMap.get(att.parentId).Attachment__c.contains(Trigger.oldMap.get(att.Id).Name)){
artworkMap.get(att.parentId).attachment__c = artworkMap.get(att.parentId).attachment__c.replaceFirst(Trigger.oldMap.get(att.Id).Name,'');
}
}
update artworkMap.values();
}
}
}
}
- Jayati Arora
- August 20, 2014
- Like
- 0
I am getting input values as null. Please help and expalin the reason?
<apex:page controller="ContactSearchController" >
<apex:form >
<apex:pageMessages />
<apex:pageBlock title="Enter Inputs">
<apex:pageBlockButtons location="bottom">
<apex:commandButton action="{!Searchresult}" value="Search"/>
</apex:pageBlockButtons>
<apex:pageblockSection >
<apex:inputField value="{!c.Lastname}"/>
<apex:inputField value="{!c.Phone}"/>
<apex:inputField value="{!c.Email}"/>
<apex:inputField value="{!c.AccountId}"/>
</apex:pageblockSection>
</apex:pageBlock>
<apex:pageblock title="Search Results" rendered="{!showsearchresults}">
<apex:pageblockTable value="{!conList}" var="c">
<apex:column value="{!c.lastname}"/>
<apex:column value="{!c.phone}"/>
<apex:column value="{!c.email}"/>
<apex:column value="{!c.accountId}"/>
</apex:pageblockTable>
</apex:pageblock>
</apex:form>
</apex:page>
public class ContactSearchController{
public Contact C {get;set;}
public list<contact> conList{get;set;}
public boolean showsearchresults{get;set;}
public ContactSearchController(){
//C = new Contact();
showsearchresults=false;
}
public pagereference Searchresult(){
C = new Contact();
conList=new list<contact>();
if(c.Lastname== null || c.Lastname=='' && c.Email==null || c.Email=='' && c.Phone==null || c.Phone =='' && c.AccountId==null || c.AccountId ==''){
System.debug('Value of lastname'+ c.Lastname);
System.debug('Value of Email'+ c.Email);
System.debug('Value of Phone'+ c.Phone);
System.debug('Value of AccountId'+ c.AccountId);
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please enter values for all input fields'));
showSearchResults=false;
return null;
}
System.debug('Size of list of contacts before SOQL'+conList.size());
conList = [Select lastname,email,phone,accountId from Contact where (lastname=:c.Lastname and email=:c.Email and phone=:c.Phone and accountId=:c.AccountId)and (lastname !=null and email!=null and phone!=null and accountId!=null)];
System.debug('Size of list of contacts after SOQL'+conList.size());
System.debug('values of list of contacts after SOQL'+conList);
if(conList.size()==0){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No matching Contact record found');
ApexPages.addMessage(myMsg);
showSearchResults=false;
return null;
}
else if(conList.size()>0){
showSearchResults=true;
return null;
}
return null;
}
}
- Jayati Arora
- August 07, 2014
- Like
- 0
Hi All, I want pageblock to be refreshed if after one search I leave my input fields as blank then only error message must be shown but currently my page is showing error along with old matched result.
<apex:form Id="FRM">
<apex:pagemessages />
<apex:pageblock title="Account Search" >
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Search" action="{!searchaccount}" reRender="op"/>
</apex:pageBlockButtons>
<apex:pageblocksection columns="2">
<apex:inputText label="Enter Account Name" value="{!acctname}"/><br/>
<apex:inputText label="Enter Account Phone" value="{!accntphone}"/><br/>
</apex:pageblocksection>
</apex:pageblock>
<apex:outputPanel id="op">
<apex:pageblock title="Account Search Results" rendered="{!showSearchResults}" id="pb">
<apex:pageBlockTable value="{!acntList}" var="c">
<apex:column value="{!c.Name}"/>
<apex:column value="{!c.Phone}" />
</apex:pageBlockTable>
</apex:pageblock>
</apex:outputPanel>
</apex:form>
</apex:page>
public class AccountSearchController{
public String acctname{get;set;}
public String accntphone{get;set;}
public list<account> acntList{get;set;}
public boolean showSearchResults{get;set;}
//String myMsg{get;set;}
public AccountSearchController(){
system.debug('====== constr ');
}
public AccountSearchController(ApexPages.StandardController controller){
showSearchResults=false;
acntList= new list<account>();
system.debug('====== constr with param ');
}
public pagereference searchaccount(){
system.debug('=== acctname '+acctname );
system.debug('=== accntphone'+accntphone);
if((acctname==null || acctname == '') && (accntphone==null || accntphone == '')){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please enter either account name or account phone'));
return null;
}
else if((acctname != null && acctname != '') || (accntphone != null && accntphone != '')){
acntList=[Select name,id,phone from account where (name=:acctname or phone=:accntphone) and (phone != null and name != null)];
System.debug('List of account values'+acntList);
System.debug('Size of account list'+acntList.size());
if(acntList.size()==0){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No matching account record found');
ApexPages.addMessage(myMsg);
showSearchResults=false;
return null;
}else if(acntList.size() > 0){
showSearchResults=true;
}
}
return null;
}
}
- Jayati Arora
- August 06, 2014
- Like
- 0
Hi All, I want pageblock to be refreshed if after one search I leave my input fields as blank then only error message must be shown but currently my page is showing error along with old matched result.
<apex:page standardController="Account" extensions="AccountSearchController">
<apex:form Id="FRM">
<apex:pagemessages />
<apex:pageblock title="Account Search" >
<apex:pageBlockButtons location="bottom">
<apex:commandButton value="Search" action="{!searchaccount}" reRender="op"/>
</apex:pageBlockButtons>
<apex:pageblocksection columns="2">
<apex:inputText label="Enter Account Name" value="{!acctname}"/><br/>
<apex:inputText label="Enter Account Phone" value="{!accntphone}"/><br/>
</apex:pageblocksection>
</apex:pageblock>
<apex:outputPanel id="op">
<apex:pageblock title="Account Search Results" rendered="{!showSearchResults}" id="pb">
<apex:pageBlockTable value="{!acntList}" var="c">
<apex:column value="{!c.Name}"/>
<apex:column value="{!c.Phone}" />
</apex:pageBlockTable>
</apex:pageblock>
</apex:outputPanel>
</apex:form>
</apex:page>
public class AccountSearchController{
public String acctname{get;set;}
public String accntphone{get;set;}
public list<account> acntList{get;set;}
public boolean showSearchResults{get;set;}
//String myMsg{get;set;}
public AccountSearchController(){
system.debug('====== constr ');
}
public AccountSearchController(ApexPages.StandardController controller){
showSearchResults=false;
acntList= new list<account>();
system.debug('====== constr with param ');
}
public pagereference searchaccount(){
system.debug('=== acctname '+acctname );
system.debug('=== accntphone'+accntphone);
if((acctname==null || acctname == '') && (accntphone==null || accntphone == '')){
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please enter either account name or account phone'));
return null;
}
else if((acctname != null && acctname != '') || (accntphone != null && accntphone != '')){
acntList=[Select name,id,phone from account where (name=:acctname or phone=:accntphone) and (phone != null and name != null)];
System.debug('List of account values'+acntList);
System.debug('Size of account list'+acntList.size());
if(acntList.size()==0){
ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.ERROR,'No matching account record found');
ApexPages.addMessage(myMsg);
showSearchResults=false;
return null;
}else if(acntList.size() > 0){
showSearchResults=true;
}
}
return null;
}
}
Tried rerendering with ID of form as well, but no search results are getting displayed.
- Jayati Arora
- August 06, 2014
- Like
- 0