• sandip bijlwan
  • NEWBIE
  • 45 Points
  • Member since 2016
  • Software Engineer
  • SaaSFocus

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 13
    Replies
This is the controller class:

public class MYAPEX_Acc
{
    public static void createcon(List<Account> lstaccforcon)
    {
        List<Contact> lstcon = new List<Contact>();
        for(Account acc : lstaccforcon)
        {
        Contact newcon = new Contact();
        newcon.AccountId = acc.Id;
        newcon.FirstName = acc.Name;
        newcon.Description = acc.Description;
        newcon.Phone = acc.Phone;
        newcon.Email = acc.Email__c;
        lstcon.add(newcon);        
        }
        try{
        INSERT lstcon;
        }
        catch(exception e)
        {
        }
    }
}


This is the trigger :

trigger AishuAccount on Account (before insert,before update,after insert,after update) 
{
    List<Account> lstacc = new List<Account>();
    List<Account> lstaccforcon = new List<Account>();
    List<Contact> lstcon = new List<Contact>();

    If(Trigger.isAfter)
        {
        If(Trigger.isInsert)
        {
      
        for(Account acc : Trigger.new)
        {
        If(acc.Phone != NULL && acc.Name != NULL)
        lstaccforcon.add(acc);
        }
        }
       
        If(lstaccforcon.size() > 0)
        {
        MYAPEX_Acc.createcon(lstaccforcon);
        }
    }
    
}


I'm unable to create a contact with this code. please help
This is the controller class:

public class MYAPEX_Acc
{
    public static void createcon(List<Account> lstaccforcon)
    {
        List<Contact> lstcon = new List<Contact>();
        for(Account acc : lstaccforcon)
        {
        Contact newcon = new Contact();
        newcon.AccountId = acc.Id;
        newcon.FirstName = acc.Name;
        newcon.Description = acc.Description;
        newcon.Phone = acc.Phone;
        newcon.Email = acc.Email__c;
        lstcon.add(newcon);        
        }
        try{
        INSERT lstcon;
        }
        catch(exception e)
        {
        }
    }
}


This is the trigger :

trigger AishuAccount on Account (before insert,before update,after insert,after update) 
{
    List<Account> lstacc = new List<Account>();
    List<Account> lstaccforcon = new List<Account>();
    List<Contact> lstcon = new List<Contact>();

    If(Trigger.isAfter)
        {
        If(Trigger.isInsert)
        {
      
        for(Account acc : Trigger.new)
        {
        If(acc.Phone != NULL && acc.Name != NULL)
        lstaccforcon.add(acc);
        }
        }
       
        If(lstaccforcon.size() > 0)
        {
        MYAPEX_Acc.createcon(lstaccforcon);
        }
    }
    
}


I'm unable to create a contact with this code. please help
Hello can someone help me on below trigger.
I have a scenario that If account is updating for phone number then all associated contacts phone number should update with same number. 
I wrote the trigger as below.It doesnt throw any errors but the phone number doesnt gets updated.

trigger phupdate on account (after update) 
{
List<contact> ctlist =new list<contact>();
List<Id> ids = new List<Id>();
for(account ac: trigger.new)
{
ids.add(ac.Id);
}
Map<Id, contact> contactMap = new Map<Id, contact>([Select Id, Phone From contact Where Id In :ids]);
for(account ac: trigger.new)
{
contact c = contactMap.get(ac.Id);
if(c != null)
{
ac.Phone= c.Phone;
ctlist.add(c);
}
}
update ctlist;
}
 
  • October 02, 2016
  • Like
  • 0
Hi All,
I would like to copy one list to another without the changes done in one list impacting the other.
Basically I will have 2 lists. One holds the initial values and the other list which will be changed on visualforce page.
At the end I want to compare the changes between the lists.

I tried the following ways to copy the list (addAll,Clone,and assignment,for loop). In all cases the if I change one list the other list is also changing its values.
Refer the below code snippet. When the accountList changes the initialAccountList also changes.

Visualforce Page:
<apex:page controller="ListCopyController">
  <apex:form >
  <apex:pageblock title="Accounts List Copy" id="pgblkId">
  <apex:pageBlockTable value="{!accountList}" var="acc">
  <apex:column headerValue="Name">
  <apex:inputField value="{!acc.name}"/>
  </apex:column>
  <apex:column headerValue="Rating">
  <apex:inputField value="{!acc.rating}"/>
  </apex:column>  
  </apex:pageBlockTable>
  <apex:pageblockButtons >
   <apex:commandButton value="FetchAccounts" action="{!fetchAccounts}" reRender="pgblkId"/>
  <apex:commandButton value="Save" action="{!save}" reRender=""/>
  </apex:pageblockButtons>
  </apex:pageblock>
  </apex:form>
</apex:page>


Apex Controller:
public class ListCopyController {

    public list<account> accountList{get;set;}
    public list<account> initialAccountList{get;set;}
    
    public ListCopyController(){
        accountList = new list<account>();
        initialAccountList = new list<account>();        
        
    }
    public void fetchAccounts(){
        accountList = [select id,name,rating from account limit 5];

        for(account acc: accountList){
            initialAccountList.add(acc);
        }
       // initialAccountList = accountList;
       // initialAccountList.addAll(accountList);
        //initialAccountList = accountList.clone();    
    }
    public void save(){
        system.debug('@@ initialAccountList'+ initialAccountList);
        system.debug('@@ accountList'+ accountList);
        update accountList;
    }

}

Looks simple but couldn't find anything relevant while searching.
Any pointers/suggestions are highly appreciated.
Many Thanks!
How to automatically create a public group when an account is created?
Dear Expert.

I need to change Idea status base on number of Vote. I'm new to Apex, could you please advise why my code is not working?

trigger updateStatusbyVote on Idea (before update,before insert) {
for (Idea updatedIdea : Trigger.new) {
       if (updatedIdea.VoteTotal > 10) {
        updatedIdea.Status = 'Voted';
       }
}
}

A candidate may apply to multiple jobs at the company Universal Containers by submitting a single application per job posting, that application cannot be modified to be resubmitted to a different job posting.
What can the administrator do to associate an application with each job posting in the schema for the organization?
A. Create a lookup relationship on both objects to a junction object called Job Posting Applications.
B. Create a master -detail relationship in the Job Postings custom object to the Applications custom object.
C. Create a master -detail relationship in the Application custom object to the Job Postings custom object.
D. Create a lookup relationship in the Applications custom object to the Job Postings custom object.
I'm trying to deploy to the survey force app to production, but continue to get the 2 error messages below. Any guidance would be appreciated.

error 1:
GettingStartedController
testGettingStarted
System.QueryException: List has no rows for assignment to SObject
Stack Trace: Class.ReportFinderUtil.findReportId: line 7, column 1 Class.GettingStartedController.viewResults: line 56, column 1 Class.GettingStartedController.testGettingStarted: line 153, column 1

viewSurveyResultsComponentController
testResultController
 System.QueryException: List has no rows for assignment to SObject
Stack Trace: Class.ReportFinderUtil.findReportId: line 7, column 1 Class.viewSurveyResultsComponentController.<init>: line 12, column 1 Class.viewSurveyResultsComponentController.testResultController: line 29, column 1
 

Hi,
I have a Standard Lead Field in SFDC Rating.  
Rating is a picklist field.

When converting a Lead, I would like this field to auto mapped to a Contact "Custom Field (Rating)"  - Also a picklist with same value on the Lead page.

I couldn't find "Mapping Fields" on the leads page when clicking on the button.

Can someone help?
Hi All,

We are overriding Opportunity tab with custom tab..so need to override "Create New View" functionality as well. Now when the user click on "Add Filter Logic " link to provide custom filter logic in the text box I am saving this text into custom field on custom object. By default if 5 rows are there then in the text box I am showing  "1 AND 2 AND 3 AND 4 AND 5"

Now user can modify this filter logic like below 
Possible combination could be:

1 AND 2 OR (3 AND 4 AND 5) -     correct 
(1 OR 2) AND (3 OR 4 OR 5)   -     correct
(1 OR 2)(3 4) -                                Incorrect
(1 OR (2 OR 3 AND 4 AND 5)  -     Incorrect

Any help on validating this custom logic before saving it to custom field would be appriciated?

Thanks !
  • June 30, 2016
  • Like
  • 0