function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
apexnewbieapexnewbie 

Tigger Help - Convert string to boolean

I am trying to map the Lead Type field (picklist) to the account when the lead is converted. If the Lead Type = Salesforce.com, I want a checkbox on the account to be True. I'm missing how to convert the string to boolean to make it work.

 

trigger LeadTypeToAccount on Lead (before update) {

 

Map<Id,String> LeadType = new Map<Id,String>();

 

for(Lead lead : Trigger.new) {
if (lead.IsConverted) {
LeadType.put(lead.ConvertedAccountId,lead.Lead_Type__c);
}
}
List<Account> AcctList = [select Id from Account WHERE Account.Id IN :LeadType.keySet()];
for ( Account a : AcctList) {
If (LeadType = 'Salesforce.com')
a.Salesforce_com__c = LeadType.get(a.Id);
}
update AcctList;
}

 

***Save Error: Illegal assignment from String to Boolean

Best Answer chosen by Admin (Salesforce Developers) 
AmitSahuAmitSahu
If (leadtype.get(a.id)=='salesforce.com')

All Answers

AmitSahuAmitSahu
First of all , change the line

If(leadtype='salesforce.com')

To

If(leadtype=='salesforce.com')

If salesforce_com__c is boolean ,you need to use:

A.salesforce_com__c = true;
apexnewbieapexnewbie

Lead Type is actually a picklist but the field I'm trying to update on the Account is boolean

apexnewbieapexnewbie

**Save Error: Comparison Arguments must be compatible types : MAP<ID,String>,String

 

trigger LeadTypeToAccount on Lead (before update) {

Map<Id,String> LeadType = new Map<Id,String>();
// Map of the converted Account ID and the Lead Type

for(Lead lead : Trigger.new) {
if (lead.IsConverted) {
LeadType.put(lead.ConvertedAccountId,lead.Lead_Type__c);
}
}
List<Account> AcctList = [select Id from Account WHERE Account.Id IN :LeadType.keySet()];
for ( Account a : AcctList) {
If (LeadType =='Salesforce.com')

a.Salesforce_com__c = true;

}
update AcctList;
}

AmitSahuAmitSahu
If (leadtype.get(a.id)=='salesforce.com')
This was selected as the best answer
apexnewbieapexnewbie

Thank you!